Created
June 2, 2017 09:50
-
-
Save ravikp7/1ded85a989cdf540a0cd6737ab88278b to your computer and use it in GitHub Desktop.
parsing test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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