Skip to content

Commit

Permalink
Rename schema "map" -> "link".
Browse files Browse the repository at this point in the history
  • Loading branch information
zswang committed Nov 15, 2015
1 parent bc249cd commit 30d2f1f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jpacks",
"description": "Binary data packing and unpacking.",
"version": "0.5.7",
"version": "0.6.2",
"homepage": "https://github.com/zswang/jpacks",
"authors": {
"name": "zswang",
Expand Down
28 changes: 14 additions & 14 deletions jpacks.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Binary data packing and unpacking.
* @author
* zswang (http://weibo.com/zswang)
* @version 0.5.7
* @date 2015-11-13
* @version 0.6.2
* @date 2015-11-15
*/
function createSchema() {
/**
Expand Down Expand Up @@ -1483,17 +1483,17 @@
* @param {string|Schema} item 元素类型
* @return {Schema|Function} 返回数据结构
'''<example>'''
* @example mapCreator():base
* @example linkCreator():base
```js
var _ = jpacks;
var _schema = {
size1: 'uint16',
size2: 'uint16',
data1: _.map('size1', 'uint8'),
data2: _.map('size2', 'uint8')
data1: _.link('size1', 'uint8'),
data2: _.link('size2', 'uint8')
};
console.log(_.stringify(_schema));
// > {size1:'uint16',size2:'uint16',data1:map('size1','uint8'),data2:map('size2','uint8')}
// > {size1:'uint16',size2:'uint16',data1:link('size1','uint8'),data2:link('size2','uint8')}
var buffer = jpacks.pack(_schema, {
data1: [1, 2, 3, 4],
data2: [1, 2, 3, 4, 5, 6, 7, 8],
Expand All @@ -1505,7 +1505,7 @@
```
'''</example>'''
*/
function mapCreator(field, item) {
function linkCreator(field, item) {
/*<safe>*/
if (typeof field !== 'string') {
throw new Error('Parameter "field" must be a string.');
Expand Down Expand Up @@ -1547,19 +1547,19 @@
}
Schema.pack(Schema.array(itemSchema, null), value, options, buffer);
},
namespace: 'map',
namespace: 'link',
args: arguments
});
}
var map = Schema.together(mapCreator, function (fn, args) {
fn.namespace = 'map';
var link = Schema.together(linkCreator, function (fn, args) {
fn.namespace = 'link';
fn.args = args;
});
Schema.register('map', map);
function mapArray(field, itemSchema) {
return map(field, Schema.array(itemSchema));
Schema.register('link', link);
function linkArray(field, itemSchema) {
return link(field, Schema.array(itemSchema));
}
Schema.register('mapArray', mapArray);
Schema.register('linkArray', linkArray);
return Schema;
}
var root = create();
Expand Down
28 changes: 14 additions & 14 deletions jpacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Binary data packing and unpacking.
* @author
* zswang (http://weibo.com/zswang)
* @version 0.5.7
* @date 2015-11-13
* @version 0.6.2
* @date 2015-11-15
*/
function createSchema() {
/**
Expand Down Expand Up @@ -1389,17 +1389,17 @@
* @param {string|Schema} item 元素类型
* @return {Schema|Function} 返回数据结构
'''<example>'''
* @example mapCreator():base
* @example linkCreator():base
```js
var _ = jpacks;
var _schema = {
size1: 'uint16',
size2: 'uint16',
data1: _.map('size1', 'uint8'),
data2: _.map('size2', 'uint8')
data1: _.link('size1', 'uint8'),
data2: _.link('size2', 'uint8')
};
console.log(_.stringify(_schema));
// > {size1:'uint16',size2:'uint16',data1:map('size1','uint8'),data2:map('size2','uint8')}
// > {size1:'uint16',size2:'uint16',data1:link('size1','uint8'),data2:link('size2','uint8')}
var buffer = jpacks.pack(_schema, {
data1: [1, 2, 3, 4],
data2: [1, 2, 3, 4, 5, 6, 7, 8],
Expand All @@ -1411,7 +1411,7 @@
```
'''</example>'''
*/
function mapCreator(field, item) {
function linkCreator(field, item) {
return new Schema({
unpack: function _unpack(buffer, options, offsets) {
var fieldValue = options.$scope.target[field];
Expand All @@ -1428,19 +1428,19 @@
}
Schema.pack(Schema.array(itemSchema, null), value, options, buffer);
},
namespace: 'map',
namespace: 'link',
args: arguments
});
}
var map = Schema.together(mapCreator, function (fn, args) {
fn.namespace = 'map';
var link = Schema.together(linkCreator, function (fn, args) {
fn.namespace = 'link';
fn.args = args;
});
Schema.register('map', map);
function mapArray(field, itemSchema) {
return map(field, Schema.array(itemSchema));
Schema.register('link', link);
function linkArray(field, itemSchema) {
return link(field, Schema.array(itemSchema));
}
Schema.register('mapArray', mapArray);
Schema.register('linkArray', linkArray);
return Schema;
}
var root = create();
Expand Down
2 changes: 1 addition & 1 deletion jpacks.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jpacks",
"title": "c struct packer",
"description": "Binary data packing and unpacking.",
"version": "0.5.7",
"version": "0.6.2",
"homepage": "http://github.com/zswang/jpacks",
"main": "jpacks.js",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion src/jpacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
require('./schemas/parse')(Schema);

require('./schemas/virtual')(Schema);
require('./schemas/map')(Schema);
require('./schemas/link')(Schema);
/*</jdists>*/

return Schema;
Expand Down
24 changes: 12 additions & 12 deletions src/schemas/map.js → src/schemas/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ module.exports = function (Schema) {
* @param {string|Schema} item 元素类型
* @return {Schema|Function} 返回数据结构
'''<example>'''
* @example mapCreator():base
* @example linkCreator():base
```js
var _ = jpacks;
var _schema = {
size1: 'uint16',
size2: 'uint16',
data1: _.map('size1', 'uint8'),
data2: _.map('size2', 'uint8')
data1: _.link('size1', 'uint8'),
data2: _.link('size2', 'uint8')
};
console.log(_.stringify(_schema));
// > {size1:'uint16',size2:'uint16',data1:map('size1','uint8'),data2:map('size2','uint8')}
// > {size1:'uint16',size2:'uint16',data1:link('size1','uint8'),data2:link('size2','uint8')}
var buffer = jpacks.pack(_schema, {
data1: [1, 2, 3, 4],
Expand All @@ -30,7 +30,7 @@ module.exports = function (Schema) {
```
'''</example>'''
*/
function mapCreator(field, item) {
function linkCreator(field, item) {
/*<safe>*/
if (typeof field !== 'string') {
throw new Error('Parameter "field" must be a string.');
Expand Down Expand Up @@ -73,19 +73,19 @@ module.exports = function (Schema) {
}
Schema.pack(Schema.array(itemSchema, null), value, options, buffer);
},
namespace: 'map',
namespace: 'link',
args: arguments
});
}
var map = Schema.together(mapCreator, function (fn, args) {
fn.namespace = 'map';
var link = Schema.together(linkCreator, function (fn, args) {
fn.namespace = 'link';
fn.args = args;
});
Schema.register('map', map);
Schema.register('link', link);

function mapArray(field, itemSchema) {
return map(field, Schema.array(itemSchema));
function linkArray(field, itemSchema) {
return link(field, Schema.array(itemSchema));
}
Schema.register('mapArray', mapArray);
Schema.register('linkArray', linkArray);
/*</define>*/
};
10 changes: 5 additions & 5 deletions test/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,18 @@ describe("./src/schemas/enums.js", function () {
assert.equal(printValue, "2"); printValue = undefined;
});
});
describe("./src/schemas/map.js", function () {
describe("./src/schemas/link.js", function () {
printValue = undefined;
it("mapCreator():base", function () {
it("linkCreator():base", function () {
var _ = jpacks;
var _schema = {
size1: 'uint16',
size2: 'uint16',
data1: _.map('size1', 'uint8'),
data2: _.map('size2', 'uint8')
data1: _.link('size1', 'uint8'),
data2: _.link('size2', 'uint8')
};
print(_.stringify(_schema));
assert.equal(printValue, "{size1:'uint16',size2:'uint16',data1:map('size1','uint8'),data2:map('size2','uint8')}"); printValue = undefined;
assert.equal(printValue, "{size1:'uint16',size2:'uint16',data1:link('size1','uint8'),data2:link('size2','uint8')}"); printValue = undefined;
var buffer = jpacks.pack(_schema, {
data1: [1, 2, 3, 4],
data2: [1, 2, 3, 4, 5, 6, 7, 8],
Expand Down

0 comments on commit 30d2f1f

Please sign in to comment.