Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(){
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)
})
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)
{
'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))
})
function createSerializer ({ state = states.HANDSHAKING, isServer = false, version, customPackets } = {}) {
return new Serializer(createProtocol(state, !isServer ? 'toServer' : 'toClient', version, customPackets), 'packet')
}