Skip to content

Instantly share code, notes, and snippets.

@ravikp7
Created June 4, 2017 05:32
Embed
What would you like to do?
Schemapack encoding doesn't work for array of more than 9 objects.
ravi@ravi-Lenovo-G50-45:~/beagle-js$ node serializer-test.js
undefined:3
var ref1=json;var ref2=ref1['a'];var ref3=ref2[0];var ref4=ref2[1];var ref5=ref2[10];var ref6=ref2[2];var ref7=ref2[3];var ref8=re
f2[4];var ref9=ref2[5];var ref10=ref2[6];var ref11=ref2[7];var ref12=ref2[8];var byteC=0;byteC+=1;byteC+=1;byteC+=bag.dynamicByteC
ounts['string'](ref5['pad']);byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=bag.getVarUIntByteLength(ref2.l
ength);for (var j2=10;j2<ref2.length;j2++) { var ref13xn=ref2[j2];byteC+=1;}var wBuffer=bag.allocUnsafe(byteC);bag.byteOffset=0;if
(typeof(ref3['a']) !== 'number'||ref3['a']<0||ref3['a']>255){bag.throwTypeError(ref3['a'],'number',0,255,'uint8');}bag.byteOffset
= wBuffer.writeUInt8(ref3['a'], bag.byteOffset, true);if (typeof(ref4['b']) !== 'number'||ref4['b']<0||ref4['b']>255){bag.throwTy
peError(ref4['b'],'number',0,255,'uint8');}bag.byteOffset = wBuffer.writeUInt8(ref4['b'], bag.byteOffset, true);if (typeof(ref5['p
ad']) !== 'string'){bag.throwTypeError(ref5['pad'],'string');}bag.writeString(ref5['pad'], wBuffer);
TypeError: Cannot read property 'pad' of undefined
at eval (eval at getCompiledSchema (/home/ravi/beagle-js/node_modules/schemapack/schemapack.js:375:24), <anonymous>:3:281)
at Object.encode (/home/ravi/beagle-js/node_modules/schemapack/schemapack.js:390:14)
at Object.<anonymous> (/home/ravi/beagle-js/serializer-test.js:33:23)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
// schemapack
var sp = require('schemapack');
var ethhdr_e = sp.build([ // Array of more than 9 objects doesn't work
{ a: 'uint8' },
{ b: 'uint8' },
{ c: 'uint8' },
{ d: 'uint8'},
{ e: 'uint8'},
{ f: 'uint8'},
{ g: 'uint8'},
{ h: 'uint8'},
{ i: 'uint8'},
{ j: 'uint8'},
//{ k: 'uint32'},
{ pad: 'string' }
]);
var eth = [
{ a: 10},
{ b: 3},
{ c: 5},
{ d: 4},
{ e: 7},
{ f: 9},
{ g: 6},
{ h: 12},
{ i: 16},
{ j: 20}
//{ k: 32}
];
// encode
var schbuf = ethhdr_e.encode(eth);
console.log(schbuf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment