Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @roblabla/protodef with all npm packages installed. Try it out:

var ProtoDef = require("protodef").ProtoDef; var Serializer = require("protodef").Serializer; var Parser = require("protodef").Parser; // the protocol can be in a separate json file var example_protocol={ "container": "native", "varint": "native", "byte": "native", "bool": "native", "switch": "native", "entity_look": [ "container", [ { "name": "entityId", "type": "varint" }, { "name": "yaw", "type": "i8" }, { "name": "pitch", "type": "i8" }, { "name": "onGround", "type": "bool" } ] ], "packet": [ "container", [ { "name": "name", "type": [ "mapper", { "type": "varint", "mappings": { "22": "entity_look" } } ] }, { "name": "params", "type": [ "switch", { "compareTo": "name", "fields": { "entity_look": "entity_look" } } ] } ] ] }; var proto = new ProtoDef(); proto.addTypes(example_protocol); var parser = new Parser(proto, "packet"); var serializer = new Serializer(proto, "packet"); serializer.write({ name: "entity_look", params: { "entityId": 1, "yaw": 1, "pitch": 1, "onGround": true } }); serializer.pipe(parser); parser.on('data', function (chunk) { console.log(JSON.stringify(chunk, null, 2)); });

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@roblabla/protodef v1.2.2

A simple yet powerful way to define binary protocols

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free