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 protodef with all npm packages installed. Try it out:

const ProtoDef = require('protodef').ProtoDef const Serializer = require('protodef').Serializer const Parser = require('protodef').Parser // the protocol can be in a separate json file const exampleProtocol = { 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' } } ] } ] ] } const proto = new ProtoDef() proto.addTypes(exampleProtocol) 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 } }) 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.

protodef v1.15.0

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