Comparing version 1.2.4 to 2.0.0
@@ -92,6 +92,6 @@ 'use strict'; | ||
var Vector = types.Vector, | ||
Optional = types.Optional; | ||
var vector = types.vector, | ||
optional = types.optional; | ||
// Create types from a string (ex Vector[Type]) | ||
// Create types from a string (ex vector[Type]) | ||
@@ -103,8 +103,7 @@ function getTypeOrStruct(Type, typeArgs) { | ||
annotation = typeatty.annotation, | ||
arrayType = typeatty.arrayType, | ||
optional = typeatty.optional; | ||
arrayType = typeatty.arrayType; | ||
var ret = void 0; | ||
if (annotation) { | ||
// AnyType<FieldName, TypeName> | ||
// any_type<field_name, type_name> | ||
var _type = types[name]; | ||
@@ -168,5 +167,5 @@ if (_type == null) { | ||
ret = Vector(nameType); | ||
ret = vector(nameType); | ||
} else if (arrayType.length > 0) { | ||
// Vector[Type] | ||
// vector[Type] | ||
var arrayTs = getTypeOrStruct(typeatty.arrayType); | ||
@@ -184,3 +183,3 @@ if (!arrayTs) { | ||
} | ||
return optional ? Optional(ret) : ret; | ||
return typeatty.optional ? optional(ret) : ret; | ||
} | ||
@@ -187,0 +186,0 @@ |
@@ -17,7 +17,7 @@ 'use strict'; | ||
describe('API', function () { | ||
it('Bytes', function () { | ||
it('bytes', function () { | ||
var _Types = Types(), | ||
Bytes = _Types.Bytes; | ||
bytes = _Types.bytes; | ||
var type = Bytes(); | ||
var type = bytes(); | ||
assertSerializer(type, '00aaeeff'); | ||
@@ -27,7 +27,7 @@ assertRequired(type); | ||
it('String', function () { | ||
it('string', function () { | ||
var _Types2 = Types(), | ||
String = _Types2.String; | ||
string = _Types2.string; | ||
var type = String(); | ||
var type = string(); | ||
assertSerializer(type, '爱'); | ||
@@ -37,11 +37,11 @@ assertRequired(type); | ||
it('Vector', function () { | ||
it('vector', function () { | ||
var _Types3 = Types(), | ||
Vector = _Types3.Vector, | ||
String = _Types3.String; | ||
vector = _Types3.vector, | ||
string = _Types3.string; | ||
throws(function () { | ||
return Vector('String'); | ||
}, /Vector type should be a serializer/); | ||
var unsortedVector = Vector(String()); | ||
return vector('string'); | ||
}, /vector type should be a serializer/); | ||
var unsortedVector = vector(string()); | ||
assertRequired(unsortedVector); | ||
@@ -53,3 +53,3 @@ | ||
var sortedVector = Vector(String(), true); | ||
var sortedVector = vector(string(), true); | ||
assert.deepEqual(sortedVector.fromObject(['z', 'a']), ['a', 'z']); //sorts | ||
@@ -61,9 +61,9 @@ assertSerializer(sortedVector, ['a', 'z']); | ||
var _Types4 = Types(), | ||
FixedBytes16 = _Types4.FixedBytes16; | ||
fixed_bytes16 = _Types4.fixed_bytes16; | ||
var type = FixedBytes16(); | ||
var type = fixed_bytes16(); | ||
assertSerializer(type, Array(16 + 1).join('ff')); // hex string | ||
throws(function () { | ||
return assertSerializer(type, Array(17 + 1).join('ff')); | ||
}, /FixedBytes16 length 17 does not equal 16/); | ||
}, /fixed_bytes16 length 17 does not equal 16/); | ||
assertRequired(type); | ||
@@ -74,5 +74,5 @@ }); | ||
var _Types5 = Types(), | ||
FixedString16 = _Types5.FixedString16; | ||
fixed_string16 = _Types5.fixed_string16; | ||
var type = FixedString16(); | ||
var type = fixed_string16(); | ||
assertSerializer(type, '1234567890123456'); | ||
@@ -96,6 +96,6 @@ throws(function () { | ||
var fn = types[typeName]; | ||
if (typeName === 'Map') { | ||
fn([types.String(), types.String()]); | ||
if (typeName === 'map') { | ||
fn([types.string(), types.string()]); | ||
} else if (typeof fn === 'function') { | ||
fn(types.String()); | ||
fn(types.string()); | ||
} | ||
@@ -119,7 +119,7 @@ } | ||
it('Time', function () { | ||
it('time', function () { | ||
var _Types6 = Types(), | ||
Time = _Types6.Time; | ||
time = _Types6.time; | ||
var type = Time(); | ||
var type = time(); | ||
@@ -144,11 +144,11 @@ throws(function () { | ||
it('Optional', function () { | ||
it('optional', function () { | ||
var _Types7 = Types(), | ||
Optional = _Types7.Optional, | ||
String = _Types7.String; | ||
optional = _Types7.optional, | ||
string = _Types7.string; | ||
var type = Optional(String()); | ||
var type = optional(string()); | ||
throws(function () { | ||
return Optional('String'); | ||
}, /Optional parameter should be a serializer/); | ||
return optional('string'); | ||
}, /optional parameter should be a serializer/); | ||
assertSerializer(type, 'str'); | ||
@@ -159,7 +159,7 @@ assertSerializer(type, null); | ||
it('UInt', function () { | ||
it('uint', function () { | ||
var _Types8 = Types(), | ||
UInt8 = _Types8.UInt8; | ||
uint8 = _Types8.uint8; | ||
var type = UInt8(); | ||
var type = uint8(); | ||
assertSerializer(type, 0); | ||
@@ -176,7 +176,7 @@ assertSerializer(type, 255); | ||
it('UInt64', function () { | ||
it('uint64', function () { | ||
var _Types9 = Types(), | ||
UInt64 = _Types9.UInt64; | ||
uint64 = _Types9.uint64; | ||
var type = UInt64(); | ||
var type = uint64(); | ||
@@ -194,7 +194,7 @@ assertSerializer(type, '18446744073709551615'); | ||
it('Int', function () { | ||
it('int', function () { | ||
var _Types10 = Types(), | ||
Int8 = _Types10.Int8; | ||
int8 = _Types10.int8; | ||
var type = Int8(); | ||
var type = int8(); | ||
assertSerializer(type, -128); | ||
@@ -211,7 +211,7 @@ assertSerializer(type, 127); | ||
it('Int64', function () { | ||
it('int64', function () { | ||
var _Types11 = Types(), | ||
Int64 = _Types11.Int64; | ||
int64 = _Types11.int64; | ||
var type = Int64(); | ||
var type = int64(); | ||
@@ -229,13 +229,13 @@ assertSerializer(type, '9223372036854775807'); | ||
it('Struct', function () { | ||
it('struct', function () { | ||
var _Types12 = Types(), | ||
Vector = _Types12.Vector, | ||
UInt16 = _Types12.UInt16, | ||
FixedBytes33 = _Types12.FixedBytes33; | ||
vector = _Types12.vector, | ||
uint16 = _Types12.uint16, | ||
fixed_bytes33 = _Types12.fixed_bytes33; | ||
var KeyPermissionWeight = Struct('KeyPermissionWeight'); | ||
KeyPermissionWeight.add('key', FixedBytes33()); | ||
KeyPermissionWeight.add('weight', UInt16()); | ||
KeyPermissionWeight.add('key', fixed_bytes33()); | ||
KeyPermissionWeight.add('weight', uint16()); | ||
var type = Vector(KeyPermissionWeight); | ||
var type = vector(KeyPermissionWeight); | ||
assertSerializer(type, [{ key: Array(33 + 1).join('00'), weight: 1 }, { key: Array(33 + 1).join('00'), weight: 1 }]); | ||
@@ -247,3 +247,3 @@ }); | ||
it('Structure', function () { | ||
assertCompile({ Struct: { fields: { checksum: 'FixedBytes32' } } }); | ||
assertCompile({ Struct: { fields: { checksum: 'fixed_bytes32' } } }); | ||
throws(function () { | ||
@@ -256,3 +256,3 @@ return assertCompile({ Struct: {} }); | ||
throws(function () { | ||
return assertCompile({ Struct: { fields: 'String' } }); | ||
return assertCompile({ Struct: { fields: 'string' } }); | ||
}, /Expecting object/); | ||
@@ -268,3 +268,3 @@ throws(function () { | ||
it('Debug', function () { | ||
assertCompile({ Name: 'String', Person: { fields: { name: 'Name' } } }, { defaults: true, debug: true }); | ||
assertCompile({ name: 'string', Person: { fields: { name: 'name' } } }, { defaults: true, debug: true }); | ||
}); | ||
@@ -276,8 +276,8 @@ | ||
}, /Unrecognized type/); | ||
assertCompile({ Name: 'String', Person: { fields: { name: 'Name' } } }); | ||
assertCompile({ Name: 'String', MyName: 'Name', Person: { fields: { name: 'MyName' } } }); | ||
assertCompile({ name: 'string', Person: { fields: { name: 'name' } } }); | ||
assertCompile({ name: 'string', MyName: 'name', Person: { fields: { name: 'MyName' } } }); | ||
}); | ||
it('typedef', function () { | ||
assertCompile({ Event: { fields: { time: 'Time' } } }); | ||
assertCompile({ Event: { fields: { time: 'time' } } }); | ||
}); | ||
@@ -287,10 +287,10 @@ | ||
throws(function () { | ||
return assertCompile({ Struct: { fields: { name: 'Name' } } }); | ||
}, /Missing Name/); | ||
return assertCompile({ Struct: { fields: { name: 'name' } } }); | ||
}, /Missing name/); | ||
throws(function () { | ||
return assertCompile({ Struct: { base: 'String' } }); | ||
}, /Missing String in Struct.base/); | ||
return assertCompile({ Struct: { base: 'string' } }); | ||
}, /Missing string in Struct.base/); | ||
throws(function () { | ||
return assertCompile({ | ||
Person: { base: 'Human', fields: { name: 'String' } } }); | ||
Person: { base: 'Human', fields: { name: 'string' } } }); | ||
}, /Missing Human/); | ||
@@ -300,15 +300,15 @@ | ||
return assertCompile({ | ||
Human: 'String', // Human needs to be struct not a type | ||
Person: { base: 'Human', fields: { name: 'String' } } }); | ||
Human: 'string', // Human needs to be struct not a type | ||
Person: { base: 'Human', fields: { name: 'string' } } }); | ||
}, /Missing Human/); | ||
assertCompile({ | ||
Boolean: 'UInt8', | ||
Boolean: 'uint8', | ||
Human: { fields: { Alive: 'Boolean' } }, | ||
Person: { base: 'Human', fields: { name: 'String' } } | ||
Person: { base: 'Human', fields: { name: 'string' } } | ||
}); | ||
}); | ||
it('Optional', function () { | ||
var _assertCompile = assertCompile({ Person: { fields: { name: 'String?' } } }, { defaults: false }), | ||
it('optional', function () { | ||
var _assertCompile = assertCompile({ Person: { fields: { name: 'string?' } } }, { defaults: false }), | ||
Person = _assertCompile.Person; | ||
@@ -324,3 +324,3 @@ | ||
throws(function () { | ||
return assertCompile({ Person: { fields: { name: 'Vector[TypeArg]' } } }); | ||
return assertCompile({ Person: { fields: { name: 'vector[TypeArg]' } } }); | ||
}, /Missing TypeArg/); | ||
@@ -331,8 +331,8 @@ throws(function () { | ||
throws(function () { | ||
return assertCompile({ Person: { fields: { name: 'BaseType[String]' } } }); | ||
return assertCompile({ Person: { fields: { name: 'BaseType[string]' } } }); | ||
}, /Missing BaseType/); | ||
assertCompile({ Person: { fields: { name: 'Vector[String]' } } }); | ||
assertCompile({ Person: { fields: { name: 'String' } }, Conference: { fields: { attendees: 'Person[]' } } }); | ||
assertCompile({ Person: { fields: { name: 'vector[string]' } } }); | ||
assertCompile({ Person: { fields: { name: 'string' } }, Conference: { fields: { attendees: 'Person[]' } } }); | ||
var _assertCompile2 = assertCompile({ Person: { fields: { friends: 'String[]' } } }), | ||
var _assertCompile2 = assertCompile({ Person: { fields: { friends: 'string[]' } } }), | ||
Person = _assertCompile2.Person; | ||
@@ -344,3 +344,3 @@ | ||
it('Errors', function () { | ||
var _create = create({ Struct: { fields: { age: 'String' } } }, Types({ defaults: true })), | ||
var _create = create({ Struct: { fields: { age: 'string' } } }, Types({ defaults: true })), | ||
structs = _create.structs; | ||
@@ -359,6 +359,6 @@ | ||
var definitions = { | ||
Asset: { | ||
asset: { | ||
fields: { | ||
amount: 'String', // another definition (like transfer) | ||
symbol: 'String' | ||
amount: 'string', // another definition (like transfer) | ||
symbol: 'string' | ||
} | ||
@@ -368,3 +368,3 @@ } | ||
var override = { | ||
'Asset.fromObject': function AssetFromObject(value) { | ||
'asset.fromObject': function assetFromObject(value) { | ||
var _value$split = value.split(' '), | ||
@@ -377,3 +377,3 @@ _value$split2 = _slicedToArray(_value$split, 2), | ||
}, | ||
'Asset.toObject': function AssetToObject(value) { | ||
'asset.toObject': function assetToObject(value) { | ||
var amount = value.amount, | ||
@@ -391,5 +391,5 @@ symbol = value.symbol; | ||
assert.equal(errors.length, 0); | ||
var asset = structs.Asset.fromObject('1 EOS'); | ||
var asset = structs.asset.fromObject('1 EOS'); | ||
assert.deepEqual(asset, { amount: 1, symbol: 'EOS' }); | ||
assert.deepEqual('1 EOS', structs.Asset.toObject(asset)); | ||
assert.deepEqual('1 EOS', structs.asset.toObject(asset)); | ||
}); | ||
@@ -399,6 +399,6 @@ | ||
var definitions = { | ||
Message: { | ||
message: { | ||
fields: { | ||
type: 'String', // another definition (like transfer) | ||
data: 'Bytes' | ||
type: 'string', // another definition (like transfer) | ||
data: 'bytes' | ||
} | ||
@@ -408,4 +408,4 @@ }, | ||
fields: { | ||
from: 'String', | ||
to: 'String' | ||
from: 'string', | ||
to: 'string' | ||
} | ||
@@ -415,3 +415,3 @@ } | ||
var override = { | ||
'Message.data.fromByteBuffer': function MessageDataFromByteBuffer(_ref) { | ||
'message.data.fromByteBuffer': function messageDataFromByteBuffer(_ref) { | ||
var fields = _ref.fields, | ||
@@ -426,3 +426,3 @@ object = _ref.object, | ||
}, | ||
'Message.data.appendByteBuffer': function MessageDataAppendByteBuffer(_ref2) { | ||
'message.data.appendByteBuffer': function messageDataAppendByteBuffer(_ref2) { | ||
var fields = _ref2.fields, | ||
@@ -438,3 +438,3 @@ object = _ref2.object, | ||
}, | ||
'Message.data.fromObject': function MessageDataFromObject(_ref3) { | ||
'message.data.fromObject': function messageDataFromObject(_ref3) { | ||
var fields = _ref3.fields, | ||
@@ -449,3 +449,3 @@ object = _ref3.object, | ||
}, | ||
'Message.data.toObject': function MessageDataToObject(_ref4) { | ||
'message.data.toObject': function messageDataToObject(_ref4) { | ||
var fields = _ref4.fields, | ||
@@ -470,7 +470,7 @@ object = _ref4.object, | ||
assert.equal(errors.length, 0); | ||
assertSerializer(structs.Message, { | ||
assertSerializer(structs.message, { | ||
type: 'transfer', | ||
data: { | ||
from: 'slim', | ||
to: 'charles' | ||
to: 'luke' | ||
} | ||
@@ -485,4 +485,4 @@ }); | ||
var customTypes = { | ||
ImpliedDecimal: function ImpliedDecimal() { | ||
return [_ImpliedDecimal, { decimals: 4 }]; | ||
implied_decimal: function implied_decimal() { | ||
return [ImpliedDecimal, { decimals: 4 }]; | ||
} | ||
@@ -492,6 +492,6 @@ }; | ||
var definitions = { | ||
Asset: { | ||
asset: { | ||
fields: { | ||
amount: 'ImpliedDecimal', | ||
symbol: 'String' | ||
amount: 'implied_decimal', | ||
symbol: 'string' | ||
} | ||
@@ -501,3 +501,3 @@ } | ||
var _ImpliedDecimal = function _ImpliedDecimal(_ref6) { | ||
var ImpliedDecimal = function ImpliedDecimal(_ref6) { | ||
var decimals = _ref6.decimals; | ||
@@ -537,3 +537,3 @@ | ||
assert.equal(errors.length, 0); | ||
var asset = structs.Asset.fromObject({ amount: '1', symbol: 'EOS' }); | ||
var asset = structs.asset.fromObject({ amount: '1', symbol: 'EOS' }); | ||
assert.deepEqual(asset, { amount: '1.0000', symbol: 'EOS' }); | ||
@@ -540,0 +540,0 @@ }); |
@@ -17,57 +17,57 @@ 'use strict'; | ||
var types = { | ||
Bytes: function Bytes() { | ||
bytes: function bytes() { | ||
return [bytebuf]; | ||
}, | ||
String: function String() { | ||
return [string]; | ||
string: function string() { | ||
return [_string]; | ||
}, | ||
Vector: function Vector(type, sorted) { | ||
return [vector, { type: type, sorted: sorted }]; | ||
vector: function vector(type, sorted) { | ||
return [_vector, { type: type, sorted: sorted }]; | ||
}, | ||
Optional: function Optional(type) { | ||
return [optional, { type: type }]; | ||
optional: function optional(type) { | ||
return [_optional, { type: type }]; | ||
}, | ||
Time: function Time() { | ||
return [time]; | ||
time: function time() { | ||
return [_time2]; | ||
}, | ||
Map: function Map(annotation) { | ||
return [map, { annotation: annotation }]; | ||
map: function map(annotation) { | ||
return [_map, { annotation: annotation }]; | ||
}, | ||
FixedString16: function FixedString16() { | ||
return [string, { maxLen: 16 }]; | ||
fixed_string16: function fixed_string16() { | ||
return [_string, { maxLen: 16 }]; | ||
}, | ||
FixedString32: function FixedString32() { | ||
return [string, { maxLen: 32 }]; | ||
fixed_string32: function fixed_string32() { | ||
return [_string, { maxLen: 32 }]; | ||
}, | ||
FixedBytes16: function FixedBytes16() { | ||
fixed_bytes16: function fixed_bytes16() { | ||
return [bytebuf, { len: 16 }]; | ||
}, | ||
FixedBytes28: function FixedBytes28() { | ||
fixed_bytes28: function fixed_bytes28() { | ||
return [bytebuf, { len: 28 }]; | ||
}, | ||
FixedBytes32: function FixedBytes32() { | ||
fixed_bytes32: function fixed_bytes32() { | ||
return [bytebuf, { len: 32 }]; | ||
}, | ||
FixedBytes33: function FixedBytes33() { | ||
fixed_bytes33: function fixed_bytes33() { | ||
return [bytebuf, { len: 33 }]; | ||
}, | ||
FixedBytes64: function FixedBytes64() { | ||
fixed_bytes64: function fixed_bytes64() { | ||
return [bytebuf, { len: 64 }]; | ||
}, | ||
FixedBytes65: function FixedBytes65() { | ||
fixed_bytes65: function fixed_bytes65() { | ||
return [bytebuf, { len: 65 }]; | ||
}, | ||
UInt8: function UInt8() { | ||
uint8: function uint8() { | ||
return [intbuf, { bits: 8 }]; | ||
}, | ||
UInt16: function UInt16() { | ||
uint16: function uint16() { | ||
return [intbuf, { bits: 16 }]; | ||
}, | ||
UInt32: function UInt32() { | ||
uint32: function uint32() { | ||
return [intbuf, { bits: 32 }]; | ||
}, | ||
UInt64: function UInt64() { | ||
uint64: function uint64() { | ||
return [intbuf, { bits: 64 }]; | ||
@@ -77,12 +77,12 @@ }, | ||
Int8: function Int8() { | ||
int8: function int8() { | ||
return [intbuf, { signed: true, bits: 8 }]; | ||
}, | ||
Int16: function Int16() { | ||
int16: function int16() { | ||
return [intbuf, { signed: true, bits: 16 }]; | ||
}, | ||
Int32: function Int32() { | ||
int32: function int32() { | ||
return [intbuf, { signed: true, bits: 32 }]; | ||
}, | ||
Int64: function Int64() { | ||
int64: function int64() { | ||
return [intbuf, { signed: true, bits: 64 }]; | ||
@@ -140,3 +140,3 @@ } | ||
validation.typeName = typeName; | ||
// if(typeName === 'Vector') console.log('typeName', validation) | ||
// if(typeName === 'vector') console.log('typeName', validation) | ||
var type = fn(validation, baseTypes, customTypes); | ||
@@ -146,3 +146,3 @@ return type; | ||
var map = function map(validation) { | ||
var _map = function _map(validation) { | ||
var _validation$annotatio = _slicedToArray(validation.annotation, 2), | ||
@@ -153,6 +153,6 @@ type1 = _validation$annotatio[0], | ||
if (!isSerializer(type1)) { | ||
throw new TypeError('Map<type1, > unknown'); | ||
throw new TypeError('map<type1, > unknown'); | ||
} | ||
if (!isSerializer(type2)) { | ||
throw new TypeError('Map<, type2> unknown'); | ||
throw new TypeError('map<, type2> unknown'); | ||
} | ||
@@ -168,3 +168,3 @@ | ||
if (validation.debug) { | ||
console.log('0x' + size.toString(16), '(Map.fromByteBuffer length)', result); | ||
console.log('0x' + size.toString(16), '(map.fromByteBuffer length)', result); | ||
} | ||
@@ -178,3 +178,3 @@ return result; | ||
if (validation.debug) { | ||
console.log('0x' + keys.length.toString(16), '(Map.appendByteBuffer length)', keys); | ||
console.log('0x' + keys.length.toString(16), '(map.appendByteBuffer length)', keys); | ||
} | ||
@@ -239,3 +239,3 @@ // if(sorted) { | ||
var vector = function vector(validation) { | ||
var _vector = function _vector(validation) { | ||
var type = validation.type, | ||
@@ -245,3 +245,3 @@ sorted = validation.sorted; | ||
if (!isSerializer(type)) { | ||
throw new TypeError('Vector type should be a serializer'); | ||
throw new TypeError('vector type should be a serializer'); | ||
} | ||
@@ -253,3 +253,3 @@ | ||
if (validation.debug) { | ||
console.log('0x' + size.toString(16), '(Vector.fromByteBuffer length)'); | ||
console.log('0x' + size.toString(16), '(vector.fromByteBuffer length)'); | ||
} | ||
@@ -269,3 +269,3 @@ var result = []; | ||
if (validation.debug) { | ||
console.log('0x' + value.length.toString(16), '(Vector.appendByteBuffer length)', value); | ||
console.log('0x' + value.length.toString(16), '(vector.appendByteBuffer length)', value); | ||
} | ||
@@ -369,7 +369,7 @@ var _iteratorNormalCompletion2 = true; | ||
var optional = function optional(validation) { | ||
var _optional = function _optional(validation) { | ||
var type = validation.type; | ||
if (!isSerializer(type)) { | ||
throw new TypeError('Optional parameter should be a serializer'); | ||
throw new TypeError('optional parameter should be a serializer'); | ||
} | ||
@@ -501,3 +501,3 @@ | ||
var string = function string(validation) { | ||
var _string = function _string(validation) { | ||
return { | ||
@@ -525,3 +525,3 @@ fromByteBuffer: function fromByteBuffer(b) { | ||
var time = function time(validation) { | ||
var _time2 = function _time2(validation) { | ||
var _time = { | ||
@@ -528,0 +528,0 @@ fromByteBuffer: function fromByteBuffer(b) { |
{ | ||
"name": "fcbuffer", | ||
"description": "Serialization library geared towards immutable data storage such as blockchains.", | ||
"version": "1.2.4", | ||
"version": "2.0.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -9,5 +9,5 @@ [![Build Status](https://travis-ci.org/EOSIO/eosjs-fcbuffer.svg?branch=master)](https://travis-ci.org/EOSIO/eosjs-fcbuffer) | ||
Project status: Beta. FC Buffer is a recent refactor from serialization code used in | ||
Bitshares and Steem. Some of the serialization code was reduced and the definitions | ||
language added. The definition format may change. | ||
FC Buffer is a recent refactor from serialization code used in Bitshares and | ||
Steem. Some of the serialization code was reduced and the definitions language | ||
added. The definition format may change. | ||
@@ -25,5 +25,5 @@ # Features | ||
- Consider Cap'n Proto or Protocol Buffers if your data structures need to be extended | ||
at the serialization layer. | ||
- No streams, usually smaller objects will work | ||
- Consider Cap'n Proto or Protocol Buffers if your data structures need to | ||
be extended at the serialization layer. | ||
- No streams, smaller blockchain sized objects are used | ||
@@ -37,12 +37,12 @@ # Example | ||
const definitions = { | ||
MessageType: 'FixedString16', // CustomType: built-in type | ||
AccountName: 'FixedString32', // CustomType: built-in type | ||
Message: { // struct | ||
definitions = { | ||
message_type: 'fixed_string16', // CustomType: built-in type | ||
account_name: 'fixed_string32', // CustomType: built-in type | ||
message: { // struct | ||
fields: { | ||
from: 'AccountName', | ||
to: 'AccountName', | ||
cc: 'AccountName[]', | ||
type: 'MessageType', | ||
data: 'Bytes' // built-in type | ||
from: 'account_name', | ||
to: 'account_name', | ||
cc: 'account_name[]', | ||
type: 'message_type', | ||
data: 'bytes' // built-in type | ||
} | ||
@@ -59,17 +59,17 @@ } | ||
// If there are no errors, you'll get your structs | ||
var {Message} = fcbuffer.structs | ||
var {message} = fcbuffer.structs | ||
// Create JSON serializable object | ||
// returns { from: '', to: '', cc: [ '' ], type: '', data: '' } | ||
Message.toObject() | ||
message.toObject() | ||
// Convert JSON into a more compact fcbuffer serializable object | ||
msg = { from: 'jc', to: 'charles', cc: [ 'abc' ], type: '', data: '0f0f0f' } | ||
msg = { from: 'jc', to: 'dan', cc: [ 'abc' ], type: '', data: '0f0f0f' } | ||
// Serialize fcbuffer object into a single binary buffer | ||
buf = Fcbuffer.toBuffer(Message, msg) | ||
buf = Fcbuffer.toBuffer(message, msg) | ||
// returns <Buffer 02 6a 63 07 63 68 61 72 6c 65 73 01 03 61 62 63 00 03 0f 0f 0f> | ||
// Convert binary back into a new (cloned) object | ||
obj = Fcbuffer.fromBuffer(Message, buf) | ||
obj = Fcbuffer.fromBuffer(message, buf) | ||
@@ -82,7 +82,7 @@ // Check that the new object matches the original | ||
fcbuffer2 = fcbuffer.extend({ | ||
PermissionName: 'FixedString16', | ||
AccountPermission: { | ||
permission_name: 'fixed_string16', | ||
account_permission: { | ||
fields: { | ||
account: 'AccountName', | ||
permission: 'PermissionName' | ||
account: 'account_name', | ||
permission: 'permission_name' | ||
} | ||
@@ -94,4 +94,4 @@ } | ||
var {AccountPermission} = fcbuffer2.structs | ||
AccountPermission.toObject() | ||
var {account_permission} = fcbuffer2.structs | ||
account_permission.toObject() | ||
// toObject returns: { account: '', permission: '' } | ||
@@ -98,0 +98,0 @@ |
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
61179
1572