How to use the protodef.utils 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 PrismarineJS / node-minecraft-protocol / src / datatypes / minecraft.js View on Github external
'use strict'

const nbt = require('prismarine-nbt')
const UUID = require('uuid-1345')
const zlib = require('zlib')

module.exports = {
  UUID: [readUUID, writeUUID, 16],
  nbt: [readNbt, writeNbt, sizeOfNbt],
  optionalNbt: [readOptionalNbt, writeOptionalNbt, sizeOfOptionalNbt],
  compressedNbt: [readCompressedNbt, writeCompressedNbt, sizeOfCompressedNbt],
  restBuffer: [readRestBuffer, writeRestBuffer, sizeOfRestBuffer],
  entityMetadataLoop: [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata]
var PartialReadError = require('protodef').utils.PartialReadError

function readUUID (buffer, offset) {
  if (offset + 16 > buffer.length) { throw new PartialReadError() }
  return {
    value: UUID.stringify(buffer.slice(offset, 16 + offset)),
    size: 16

function writeUUID (value, buffer, offset) {
  const buf = UUID.parse(value)
  buf.copy(buffer, offset)
  return offset + 16

function readNbt (buffer, offset) {


A simple yet powerful way to define binary protocols

Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis