Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parsing test
ravi@ravi-Lenovo-G50-45:~/beagle-js$ node serializer
<Buffer 06 ff ff ff ff ff ff 08 00 06 a0 f6 fd 8a e9 1a>
{ h_dest: [ 6, 255, 255, 255, 255, 255 ],
h_source: [ 255, 8, 0, 6, 160, 246 ],
h_proto: -630 }
var Parser = require('binary-parser').Parser;
// schemapack
var sp = require('schemapack');
var ethhdr_e = sp.build({
h_dest : ['uint8'],
h_source : ['uint8'],
h_proto : 'uint16'
});
var eth = {
h_dest : [ 255, 255, 255, 255, 255, 255 ],
h_source : [ 160, 246, 253, 138, 233, 26 ],
h_proto : 2048
};
// encode
var schbuf = ethhdr_e.encode(eth);
// Parsing
var ethhdr = new Parser()
.array('h_dest',{
type: 'uint8',
length: 6
})
.array('h_source',{
type: 'uint8',
length: 6
})
.int16be('h_proto');
console.log(schbuf);
console.log(ethhdr.parse(schbuf));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment