Socket
Socket
Sign inDemoInstall

binbone

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    binbone

A binary encoder/decoder aimed at achieving optimal space utilization.


Version published
Maintainers
1
Install size
109 kB
Created

Changelog

Source

v0.2.0

  • upd dep. Adapt for io.js 3.0

Readme

Source

node-binbone

Node.js(io.js) implemention of binbone, A binary encode specification aimed at achieving optimal space utilization.

NPM version Build Status Build status

Installation

npm i binbone -S

Usage

  • Use Block. Block can be use as both an encoder and a decoder.
Block = require("binbone");
block = new Block(1024); // args are the same as a QueueBuffer

block.writeArray([1, 2, 3]);
block.writeUInt("123456789012345"); // Big integer(use [jsbn](https://github.com/andyperlitch/jsbn))
block.readArray();
block.readUInt();
  • Use encoder/decoder.

Directly:

Encoder = require("binbone").Encoder;
encodeBlock = new Encoder();

encodeBlock.writeInt(123);

Specify a Buffer for data:

binbone = require('binbone');
buf = new binbone.QueueBuffer();
buf.writeUInt16BE(12);
decoder = new binbone.Decoder(buf);
decoder.readUInt({length: 2});

API

Encoder

  • constructor (outputBlock)

    constructor

    • param: outputBlock { FlexBuffer }

      An BinboneBlock Object

  • writeTo (outputBlock)

    Reset data block

    • param: outputBlock { FlexBuffer }

      An BinboneBlock Object

  • writeByte (value = 0)

    Write a byte.

    • param: value { number=0 }

      byte value

    • return: { number }

      length to write (always 1)

  • writeBoolean (value) (alias: writeBool)

    Write a boolean value.

    • param: value { boolean }

      boolean value

    • return: { number }

      length to write (always 1)

  • writeUInt (num = 0 | string, opts = {}) (alias: writeLength, writeSign)

    Write an unsigned integer, using variable-length coding.

    • param: num { number=0 | string }

      integer, use string for any big integer

    • param: opts { Object={} }

      options

    • option: length { number }

      byte length of integer (1, 2, 4, 8)

    • return: { number }

      length to write

  • writeInt (opts = {}) (alias: writeLong)

    Write an signed integer, using zig-zag variable-length coding.

    • param: opts { Object={} }

      options

    • option: length { number }

      byte length of integer (1, 2, 4, 8)

    • return: { number }

      length to write

  • writeFloat (value = 0)

    Write a float.

    • param: value { number=0 }

      float point number

    • return: { number }

      length to write (always 4)

  • writeDouble (value = 0)

    Write a double.

    • param: value { number=0 }

      float point number

    • return: { number }

      length to write (always 8)

  • writeBytes (values, opts = {})

    Write bytes.

    • param: values { Array | Buffer }

      bytes

    • param: opts { Object={} }

      options

    • option: length { number }

      number of bytes

    • return: { number }

      length to write

  • writeString (str, opts = {})

    Write a string.

    • param: str { string }

      string

    • param: opts { Object={} }

      options

    • option: length { number }

      byte length of string

    • return: { number }

      length to write

  • writeMap (map = {}, opts = {})

    Write a map.

    • param: map { Object | Map = {} }

      key-value map

    • param: opts { Object={} }

      options

    • option: length { number }

      size of map

    • option: keyType { string|Object }

      type of key [required]

    • option: valueType { string|Object }

      type of value [required]

    • return: { number }

      length to write

  • writeArray (arr = [], opts = {})

    Write an array of data.

    • param: arr { Array=[] }

      Array

    • param: opts { Object={} }

      options

    • option: length { number }

      length of array

    • option: valueType { string|Object }

      type of array item

    • return: { number }

      length to write

  • writeObject (obj = {}, opts = {})

    Write an object.

    • param: obj { Object={} }

      object

    • param: opts { Object={} }

      options

    • option: length { number }

      size of object

    • option: valueType { string|Object }

      type of object value

    • return: { number }

      length to write

Decoder

Test

npm test

TODO

  • Record type

License

MIT@Jingchen Zhao

FAQs

Last updated on 05 Aug 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc