Comparing version 0.6.10 to 0.6.12
@@ -8,4 +8,4 @@ (function (exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.6.10 | ||
* @date 2016-03-16 | ||
* @version 0.6.12 | ||
* @date 2016-03-18 | ||
*/ | ||
@@ -12,0 +12,0 @@ function createSchema() { |
@@ -8,4 +8,4 @@ (function (exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.6.10 | ||
* @date 2016-03-16 | ||
* @version 0.6.12 | ||
* @date 2016-03-18 | ||
*/ | ||
@@ -12,0 +12,0 @@ function createSchema() { |
@@ -5,3 +5,3 @@ { | ||
"description": "Binary data packing and unpacking.", | ||
"version": "0.6.10", | ||
"version": "0.6.12", | ||
"homepage": "http://github.com/zswang/jpacks", | ||
@@ -8,0 +8,0 @@ "main": "jpacks.js", |
@@ -70,2 +70,3 @@ var protobufjs = require('protobufjs'); | ||
} | ||
function bytesprase(value, options) { | ||
@@ -275,11 +276,22 @@ if (options.protobuf_bytesAsString) { | ||
function protobufCreator(prototext, messagepath, size) { | ||
var builder; | ||
if (/\s.*[{};]/.test(prototext)) { | ||
builder = protobufjs.loadProto(prototext); | ||
} else { | ||
builder = protobufjs.loadProtoFile(prototext); | ||
var messager; | ||
/** | ||
* 采用动态加载的策略 | ||
*/ | ||
function initMessager() { | ||
if (messager) { | ||
return; | ||
} | ||
var builder; | ||
if (/\s.*[{};]/.test(prototext)) { | ||
builder = protobufjs.loadProto(prototext); | ||
} else { | ||
builder = protobufjs.loadProtoFile(prototext); | ||
} | ||
messager = builder.build(messagepath); | ||
} | ||
var messager = builder.build(messagepath); | ||
return new Schema({ | ||
unpack: function(buffer, options, offsets) { | ||
initMessager(); | ||
var bytes = Schema.unpack(Schema.bytes(size), buffer, options, offsets); | ||
@@ -294,2 +306,3 @@ var rs = messager.decode(bytes); | ||
pack: function _pack(value, options, buffer) { | ||
initMessager(); | ||
if (!value) { | ||
@@ -296,0 +309,0 @@ return; |
113207
3575