Skip to content

Instantly share code, notes, and snippets.

@ravikp7
Created June 2, 2017 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ravikp7/1ded85a989cdf540a0cd6737ab88278b to your computer and use it in GitHub Desktop.
Save ravikp7/1ded85a989cdf540a0cd6737ab88278b to your computer and use it in GitHub Desktop.
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