Comparing version 1.0.9 to 1.1.0
@@ -77,3 +77,3 @@ /* eslint-env mocha */ | ||
assertSerializer(type, '2106-02-07T06:28:15') | ||
throws(() => assertSerializer(type, '1969-12-31T23:59:59Z'), /Overflow/) | ||
throws(() => assertSerializer(type, '1969-12-31T23:59:59Z'), /format/) // becomes -1 | ||
throws(() => assertSerializer(type, '2106-02-07T06:28:16Z'), /Overflow/) | ||
@@ -98,3 +98,3 @@ assertRequired(type) | ||
throws(() => assertSerializer(type, 256), /Overflow/) | ||
throws(() => assertSerializer(type, -1), /Overflow/) | ||
throws(() => assertSerializer(type, -1), /format/) | ||
assertRequired(type) | ||
@@ -110,3 +110,3 @@ }) | ||
throws(() => assertSerializer(type, '18446744073709551616'), /Overflow/) | ||
throws(() => assertSerializer(type, '-1'), /Overflow/) | ||
throws(() => assertSerializer(type, '-1'), /format/) | ||
assertRequired(type) | ||
@@ -274,9 +274,9 @@ }) | ||
}, | ||
'Message.data.fromObject': ({fields, serializedObject, result}) => { | ||
const {data, type} = serializedObject | ||
'Message.data.fromObject': ({fields, object, result}) => { | ||
const {data, type} = object | ||
const ser = (type || '') == '' ? fields.data : structs[type] | ||
result.data = ser.fromObject(data) | ||
}, | ||
'Message.data.toObject': ({fields, serializedObject, result, config}) => { | ||
const {data, type} = serializedObject || {} | ||
'Message.data.toObject': ({fields, object, result, config}) => { | ||
const {data, type} = object || {} | ||
const ser = (type || '') == '' ? fields.data : structs[type] | ||
@@ -328,3 +328,3 @@ result.data = ser.toObject(data, config) | ||
const {structs, errors} = create(definitions, Types({customTypes})) | ||
const {structs, errors} = Fcbuffer(definitions, {customTypes}) | ||
assert.equal(errors.length, 0) | ||
@@ -331,0 +331,0 @@ const asset = structs.Asset.fromObject({amount: '1', symbol: 'EOS'}) |
{ | ||
"name": "fcbuffer", | ||
"description": "Serialization library geared towards immutable data storage such as blockchains.", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -30,18 +30,3 @@ const ByteBuffer = require('bytebuffer') | ||
try { | ||
if (config.debug) { | ||
if (type.struct) { | ||
console.error(type.struct) | ||
} else { | ||
const o1 = b.offset | ||
type.fromByteBuffer(b, config) | ||
const o2 = b.offset | ||
b.offset = o1 | ||
// b.reset() | ||
const _b = b.copy(o1, o2) | ||
console.error( | ||
`${name}.${field}\t`, | ||
_b.toHex() | ||
) | ||
} | ||
} | ||
const o1 = b.offset | ||
if (field === '') { | ||
@@ -58,2 +43,14 @@ // structPtr | ||
} | ||
if (config.debug) { | ||
if (type.struct) { | ||
console.error(type.struct) | ||
} else { | ||
const _b = b.copy(o1, b.offset) | ||
console.error( | ||
`${name}.${field}\t`, | ||
_b.toHex(), | ||
'(fromByteBuffer)' | ||
) | ||
} | ||
} | ||
} catch (e) { | ||
@@ -113,5 +110,5 @@ e.message += ` (${name}.${field})` | ||
for (field in fields) { | ||
if(config.debug) { | ||
console.error(name, field) | ||
} | ||
// if(config.debug) { | ||
// console.error(name, field, '(fromObject)') | ||
// } | ||
const type = fields[field] | ||
@@ -125,3 +122,3 @@ if (field === '') { | ||
if(fromObject) { | ||
fromObject({fields, serializedObject, result}) | ||
fromObject({fields, object: serializedObject, result}) | ||
} else { | ||
@@ -153,3 +150,3 @@ const value = serializedObject[field] | ||
if(toObject) { | ||
toObject({fields, serializedObject, result, config}) | ||
toObject({fields, object: serializedObject, result, config}) | ||
} else { | ||
@@ -173,3 +170,3 @@ const object = type.toObject(serializedObject ? serializedObject[field] : null, config) | ||
if(toObject && appendByteBuffer) { | ||
appendByteBuffer({fields, serializedObject, b}) | ||
appendByteBuffer({fields, object: serializedObject, b}) | ||
} else { | ||
@@ -181,5 +178,6 @@ type.appendByteBuffer(b, value) | ||
b = b.copy(0, b.offset) | ||
console.error(name + '.' + field, b.toHex()) | ||
console.error(name + '.' + field, b.toHex(), '(toObject)') | ||
} catch(error) { // work-around to prevent debug time crash | ||
console.error('DEBUG', name + '.' + field, error.toString()) | ||
error.message = `${name}.${field} ${error.message}` | ||
console.error(error) | ||
} | ||
@@ -186,0 +184,0 @@ } |
@@ -84,5 +84,5 @@ const BN = require('bn.js') | ||
const size = b.readVarint32() | ||
// if (validation.debug) { | ||
// console.log("constint32 size = " + size.toString(16)) | ||
// } | ||
if (validation.debug) { | ||
console.log('0x' + size.toString(16), '(Vector.fromByteBuffer length)') | ||
} | ||
const result = [] | ||
@@ -97,2 +97,5 @@ for (let i = 0; i < size; i++) { | ||
b.writeVarint32(value.length) | ||
if (validation.debug) { | ||
console.log('0x' + value.length.toString(16), '(Vector.appendByteBuffer length)') | ||
} | ||
if(sorted) { | ||
@@ -181,3 +184,3 @@ value = sort(type, Object.assign([], value)) | ||
appendByteBuffer (b, value) { | ||
// noOverflow(value, validation) | ||
// validateInt(value, validation) | ||
// value = typeof value === 'string' ? Long.fromString(value) : value | ||
@@ -187,3 +190,3 @@ b[`write${intbufType(validation)}`](value) | ||
fromObject (value) { | ||
noOverflow(value, validation) | ||
validateInt(value, validation) | ||
// if(validation.bits > 53 && typeof value === 'number') | ||
@@ -199,3 +202,3 @@ // value = String(value) | ||
noOverflow(value, validation) | ||
validateInt(value, validation) | ||
// if(validation.bits > 53 && typeof value === 'number') | ||
@@ -312,3 +315,3 @@ // value = String(value) | ||
noOverflow(value, spread(validation, {bits: 32})) | ||
validateInt(value, spread(validation, {bits: 32})) | ||
const int = parseInt(value) | ||
@@ -344,3 +347,3 @@ return (new Date(int * 1000)).toISOString().split('.')[0] | ||
function noOverflow (value, validation) { | ||
function validateInt (value, validation) { | ||
if (isEmpty(value)) { | ||
@@ -351,5 +354,13 @@ throw new Error(`Required ${validation.typeName}`) | ||
value = String(value).trim() | ||
if( | ||
(signed && !/^-?[0-9]+$/.test(value)) || | ||
(!signed && !/^[0-9]+$/.test(value)) | ||
) { | ||
throw new Error(`Number format ${validation.typeName} ${value}`) | ||
} | ||
const max = signed ? maxSigned(bits) : maxUnsigned(bits) | ||
const min = signed ? minSigned(bits) : ZERO | ||
const i = new BN(String(value)) | ||
const i = new BN(value) | ||
@@ -356,0 +367,0 @@ // console.log('i.toString(), min.toString()', i.toString(), min.toString()) |
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
70620
1098