How to use the protodef.types 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 deathcap / wsmc / wsmc.js View on Github external
'use strict';

var mcversion = require('./mcversion.js');
var minecraft_protocol = require('minecraft-protocol/src');
var autoVersionForge = require('minecraft-protocol-forge').autoVersionForge;
var minecraft_data = require('minecraft-data')(mcversion);
var protodef = require('protodef');
var readVarInt = protodef.types.varint[0];
var writeVarInt = protodef.types.varint[1];
var sizeOfVarInt = protodef.types.varint[2];
var hex = require('hex');
var WebSocketServer = (require('ws')).Server;
var websocket_stream = require('websocket-stream');
var argv = (require('optimist'))
  .default('wshost', '')
  .default('wsport', 24444)
  .default('mchost', 'localhost')
  .default('mcport', 25565)
  .default('prefix', 'webuser-')
  .argv;

var PACKET_DEBUG = process.env.NODE_DEBUG && /wsmc/.test(process.env.NODE_DEBUG);
var FIXED_MC_VERSION = false; // either a version string, or false to auto-detect

console.log('WS('+argv.wshost+':'+argv.wsport+') <--> MC('+argv.mchost+':'+argv.mcport+')');
github deathcap / wsmc / wsmc.js View on Github external
'use strict';

var mcversion = require('./mcversion.js');
var minecraft_protocol = require('minecraft-protocol/src');
var autoVersionForge = require('minecraft-protocol-forge').autoVersionForge;
var minecraft_data = require('minecraft-data')(mcversion);
var protodef = require('protodef');
var readVarInt = protodef.types.varint[0];
var writeVarInt = protodef.types.varint[1];
var sizeOfVarInt = protodef.types.varint[2];
var hex = require('hex');
var WebSocketServer = (require('ws')).Server;
var websocket_stream = require('websocket-stream');
var argv = (require('optimist'))
  .default('wshost', '')
  .default('wsport', 24444)
  .default('mchost', 'localhost')
  .default('mcport', 25565)
  .default('prefix', 'webuser-')
  .argv;

var PACKET_DEBUG = process.env.NODE_DEBUG && /wsmc/.test(process.env.NODE_DEBUG);
var FIXED_MC_VERSION = false; // either a version string, or false to auto-detect
github MephisTools / diablo2-protocol / lib / utils / splitter.js View on Github external
'use strict'

const [writeLu8] = require('protodef').types.lu8
const Transform = require('readable-stream').Transform
const { getPacketSize } = require('./compression')

module.exports.createSplitter = function () {
  return new Splitter()
}

module.exports.createFramer = function () {
  return new Framer()
}

class Framer extends Transform {
  _transform (chunk, enc, cb) {
    const buffer = Buffer.alloc(1 + chunk.length)
    writeLu8(chunk.length + 1, buffer, 0)
    chunk.copy(buffer, 1)
github PrismarineJS / node-minecraft-protocol / src / transforms / compression.js View on Github external
'use strict'

const [readVarInt, writeVarInt, sizeOfVarInt] = require('protodef').types.varint
const zlib = require('zlib')
const Transform = require('readable-stream').Transform

module.exports.createCompressor = function (threshold) {
  return new Compressor(threshold)
}

module.exports.createDecompressor = function (threshold, hideErrors) {
  return new Decompressor(threshold, hideErrors)
}

class Compressor extends Transform {
  constructor (compressionThreshold = -1) {
    super()
    this.compressionThreshold = compressionThreshold
  }
github PrismarineJS / node-minecraft-protocol / src / transforms / framing.js View on Github external
'use strict'

const [readVarInt, writeVarInt, sizeOfVarInt] = require('protodef').types.varint
const Transform = require('readable-stream').Transform

module.exports.createSplitter = function () {
  return new Splitter()
}

module.exports.createFramer = function () {
  return new Framer()
}

class Framer extends Transform {
  _transform (chunk, enc, cb) {
    const varIntSize = sizeOfVarInt(chunk.length)
    const buffer = Buffer.alloc(varIntSize + chunk.length)
    writeVarInt(chunk.length, buffer, 0)
    chunk.copy(buffer, varIntSize)

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