protodef
Version:
A simple yet powerful way to define binary protocols
34 lines (26 loc) • 761 B
JavaScript
const ProtoDef = require("protodef").ProtoDef;
const Serializer = require("protodef").Serializer;
const Parser = require("protodef").Parser;
const example_protocol=require("./example_protocol.json");
const proto = new ProtoDef();
proto.addTypes(example_protocol);
const parser = new Parser(proto, "packet");
const serializer = new Serializer(proto, "packet");
serializer.write({
name: "entity_look",
params: {
"entityId": 1,
"yaw": 1,
"pitch": 1,
"onGround": true
}
});
parser.on('error',function(err){
console.log(err.stack);
console.log(err.buffer);
});
parser.write(new Buffer([0x17,0x01,0x01,0x01,0x01]));
serializer.pipe(parser);
parser.on('data', function (chunk) {
console.log(JSON.stringify(chunk.data, null, 2));
});