How to use the protodef.Serializer function in protodef

To help you get started, we’ve selected a few protodef examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProtoDef-io / node-protodef / test / benchmark.js View on Github external
it("bench serializing",function(done){
    var start, i, j;
    console.log('Beginning write test');
    var serializer = new Serializer(proto, "packet");
    start = Date.now();
    for(i = 0; i < ITERATIONS; i++) {
      for(j = 0; j < testDataWrite.length; j++) {
        serializer.write(testDataWrite[j]);
      }
    }
    function wait(cb) {
      var i=0;
      serializer.on("data",function(data){
        inputData.push(data);
        i++;
        if(i==size)
          cb();
      });
    }
    wait(function(){
github ProtoDef-io / node-protodef / examples / error_handling.js View on Github external
const ProtoDef = require('protodef').ProtoDef
const Serializer = require('protodef').Serializer
const Parser = require('protodef').Parser

const exampleProtocol = require('./example_protocol.json')

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
  }
})

parser.on('error', function (err) {
  console.log(err.stack)
  console.log(err.buffer)
})
github ProtoDef-io / node-protodef / examples / full_protocol.js View on Github external
const ProtoDef = require('protodef').ProtoDef
const Serializer = require('protodef').Serializer
const Parser = require('protodef').Parser

const exampleProtocol = require('./full_protocol_example.json')

const proto = new ProtoDef()
proto.addProtocol(exampleProtocol, ['login', 'toClient'])
const parser = new Parser(proto, 'packet')
const serializer = new Serializer(proto, 'packet')

serializer.write({
  name: 'success',
  params: {
    'uuid': 'some uuid',
    'username': 'some name'
  }
})

parser.on('error', function (err) {
  console.log(err.stack)
  console.log(err.buffer)
})

serializer.pipe(parser)
github ProtoDef-io / node-protodef / example.js View on Github external
{
            '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))
})
github PrismarineJS / node-minecraft-protocol / src / transforms / serializer.js View on Github external
function createSerializer ({ state = states.HANDSHAKING, isServer = false, version, customPackets } = {}) {
  return new Serializer(createProtocol(state, !isServer ? 'toServer' : 'toClient', version, customPackets), 'packet')
}

protodef

A simple yet powerful way to define binary protocols

MIT
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis