Comparing version 0.3.17 to 0.3.25
@@ -8,4 +8,4 @@ (function (exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.3.17 | ||
* @date 2015-11-05 | ||
* @version 0.3.25 | ||
* @date 2015-11-06 | ||
*/ | ||
@@ -186,5 +186,7 @@ function createSchema() { | ||
var schema = Schema.from(packSchema); | ||
/*<safe>*/ | ||
if (!schema) { | ||
throw new Error('Parameter schema "' + packSchema + '" is unregister.'); | ||
} | ||
/*</safe>*/ | ||
buffer = arrayBufferFrom(buffer); // 确保是 ArrayBuffer 类型 | ||
@@ -214,5 +216,7 @@ options = options || {}; | ||
var schema = Schema.from(packSchema); | ||
/*<safe>*/ | ||
if (!schema) { | ||
throw new Error('Parameter schema "' + packSchema + '" is unregister.'); | ||
} | ||
/*</safe>*/ | ||
buffer = buffer || []; | ||
@@ -243,11 +247,11 @@ options = options || {}; | ||
t(1)()(2, 3); | ||
// -> [1,2,3] | ||
// > [1,2,3] | ||
t(4)(5)()(6); | ||
// -> [4,5,6] | ||
// > [4,5,6] | ||
t(7, 8, 9); | ||
// -> [7,8,9] | ||
// > [7,8,9] | ||
t('a', 'b')('c'); | ||
// -> ["a","b","c"] | ||
// > ["a","b","c"] | ||
t()('x')()()('y')()()('z'); | ||
// -> ["x","y","z"] | ||
// > ["x","y","z"] | ||
``` | ||
@@ -262,3 +266,9 @@ * @example together():hook | ||
console.log(t(1)(2).schema); | ||
// -> f(1,2) | ||
// > f(1,2) | ||
function go() { | ||
console.log(1); | ||
} | ||
var g = _.together(go); | ||
g(); | ||
// > 1 | ||
``` | ||
@@ -362,4 +372,4 @@ '''</example>''' | ||
* @field {Array of string} alias 别名 | ||
'''<example>''' | ||
* @example all number | ||
'''<example>''' | ||
```js | ||
@@ -820,2 +830,3 @@ var _ = jpacks; | ||
* @example enumsCreator():fault tolerant | ||
```js | ||
var _ = jpacks; | ||
@@ -837,2 +848,3 @@ var _schema = _.enums({ | ||
// > 2 | ||
``` | ||
'''</example>''' | ||
@@ -839,0 +851,0 @@ */ |
@@ -8,4 +8,4 @@ (function (exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.3.17 | ||
* @date 2015-11-05 | ||
* @version 0.3.25 | ||
* @date 2015-11-06 | ||
*/ | ||
@@ -168,5 +168,2 @@ function createSchema() { | ||
var schema = Schema.from(packSchema); | ||
if (!schema) { | ||
throw new Error('Parameter schema "' + packSchema + '" is unregister.'); | ||
} | ||
buffer = arrayBufferFrom(buffer); // 确保是 ArrayBuffer 类型 | ||
@@ -193,5 +190,2 @@ options = options || {}; | ||
var schema = Schema.from(packSchema); | ||
if (!schema) { | ||
throw new Error('Parameter schema "' + packSchema + '" is unregister.'); | ||
} | ||
buffer = buffer || []; | ||
@@ -222,11 +216,11 @@ options = options || {}; | ||
t(1)()(2, 3); | ||
// -> [1,2,3] | ||
// > [1,2,3] | ||
t(4)(5)()(6); | ||
// -> [4,5,6] | ||
// > [4,5,6] | ||
t(7, 8, 9); | ||
// -> [7,8,9] | ||
// > [7,8,9] | ||
t('a', 'b')('c'); | ||
// -> ["a","b","c"] | ||
// > ["a","b","c"] | ||
t()('x')()()('y')()()('z'); | ||
// -> ["x","y","z"] | ||
// > ["x","y","z"] | ||
``` | ||
@@ -241,3 +235,9 @@ * @example together():hook | ||
console.log(t(1)(2).schema); | ||
// -> f(1,2) | ||
// > f(1,2) | ||
function go() { | ||
console.log(1); | ||
} | ||
var g = _.together(go); | ||
g(); | ||
// > 1 | ||
``` | ||
@@ -341,4 +341,4 @@ '''</example>''' | ||
* @field {Array of string} alias 别名 | ||
'''<example>''' | ||
* @example all number | ||
'''<example>''' | ||
```js | ||
@@ -778,2 +778,3 @@ var _ = jpacks; | ||
* @example enumsCreator():fault tolerant | ||
```js | ||
var _ = jpacks; | ||
@@ -795,2 +796,3 @@ var _schema = _.enums({ | ||
// > 2 | ||
``` | ||
'''</example>''' | ||
@@ -797,0 +799,0 @@ */ |
@@ -5,3 +5,3 @@ { | ||
"description": "Binary data packing and unpacking.", | ||
"version": "0.3.17", | ||
"version": "0.3.25", | ||
"homepage": "http://github.com/zswang/jpacks", | ||
@@ -8,0 +8,0 @@ "main": "jpacks.js", |
@@ -106,2 +106,10 @@ var jints = require('jints'); | ||
// > "-2" | ||
var buffer = _.pack(_schema, "-0xff11233ff", { littleEndian: false }); | ||
console.log(buffer.join(' ')); | ||
// > 255 255 255 240 14 237 204 1 | ||
console.log(JSON.stringify(_.unpack(_schema, buffer, { littleEndian: false }))); | ||
// > "-68469011455" | ||
``` | ||
@@ -139,7 +147,9 @@ '''</example>''' | ||
var hex; | ||
if (/^0x/.test(value)) { | ||
hex = value.slice(2 + signed ? 1 : 0); | ||
if (/^[-+]?0x/.test(value)) { | ||
hex = value.replace(/^[-+]?0x/, ''); // 清除符号和前缀 | ||
} else { | ||
hex = jints.digit(value, 10, 16); | ||
} | ||
console.log('value: %j', hex); | ||
hex = jints.fullZero(hex, 16).replace(/^.+(.{16})$/, '$1'); // 避免位数过高 | ||
@@ -146,0 +156,0 @@ var bytes = hex2bytes(hex); |
@@ -13,3 +13,3 @@ var protobufjs = require('protobufjs'); | ||
if (!messager) { | ||
throw new Error('messager is undefined.'); | ||
return json; | ||
} | ||
@@ -66,3 +66,3 @@ var result = {}; | ||
if (!json || !messager) { | ||
return; | ||
return json; | ||
} | ||
@@ -200,6 +200,38 @@ var type = messager.$type; | ||
``` | ||
* @example protobufCreator():proto text | ||
```js | ||
var _ = jpacks; | ||
var _schema = _.array( | ||
_.protobuf('message Value { required string text = 1; }', 'Value', 'uint16'), | ||
'int8' | ||
); | ||
console.log(_.stringify(_schema)) | ||
// > array(protobuf('message Value { required string text = 1; }','Value','uint16'),'int8') | ||
_.setDefaultOptions({ | ||
protobuf_bytesAsString: true | ||
}); | ||
var buffer = _.pack(_schema, [{ | ||
text: "a" | ||
}, { | ||
text: "b" | ||
}]); | ||
console.log(buffer.join(' ')); | ||
// > 2 3 0 10 1 97 3 0 10 1 98 | ||
console.log(JSON.stringify(_.unpack(_schema, buffer))); | ||
// > [{"text":"a"},{"text":"b"}] | ||
``` | ||
'''</example>''' | ||
*/ | ||
function protobufCreator(filename, messagepath, size) { | ||
var builder = protobufjs.loadProtoFile(filename); | ||
function protobufCreator(prototext, messagepath, size) { | ||
var builder; | ||
if (/\s.*[{};]/.test(prototext)) { | ||
builder = protobufjs.loadProto(prototext); | ||
} else { | ||
builder = protobufjs.loadProtoFile(prototext); | ||
} | ||
var messager = builder.build(messagepath); | ||
@@ -206,0 +238,0 @@ return new Schema({ |
@@ -33,2 +33,5 @@ var zlib = require('zlib'); | ||
// > {"type":2,"data":"你好世界!Hello"} | ||
console.log(_.stringify(_.gzip(_.longString))); | ||
// > gzip(string('uint32')) | ||
``` | ||
@@ -81,2 +84,5 @@ '''</example>''' | ||
// > {"type":2,"data":"你好世界!Hello"} | ||
console.log(_.stringify(_.inflate(_.longString))); | ||
// > inflate(string('uint32')) | ||
``` | ||
@@ -83,0 +89,0 @@ '''</example>''' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103551
3292