shortcode

shorthand for binary encodings

npm install shortcode
4 downloads in the last month

shortcode

shorthand for binary encodings

build status

example

var shortcode = require('shortcode');

[ 's16l', 'fb', 'u32l[]', 's8' ].forEach(function (code) {
    console.log(shortcode(code));
});

{ type: 'signed', size: 16, endian: 'little', array: false }
{ type: 'float', size: 32, endian: 'big', array: false }
{ type: 'unsigned', size: 32, endian: 'little', array: true }
{ type: 'signed', size: 8, endian: undefined, array: false }

encodings

shortcode encodings have 4 ordered parts:

  • type
  • size
  • endianness
  • array
{s,u}8{,[]}
{s,u}{16,32,64}{l,b}{,[]}
{f,d}{l,b}{,[]}

type

You can use the shorthand or type out the entire word.

s, signed

signed integer

u, unsigned

unsigned integer

f, float

32-bit floating point

d, double

64-bit floating point

size

For signed and unsigned integers, the number modifier refers to the number of bits to use.

endianness

l, little

b, big

undefined

For 's8' and 'u8' endianness is always undefined and shouldn't be specified.

array

By default the encoding is expected to be a Buffer. Put [] after the code to specify a binary array.

For example s32l would be a little-endian Int32Array.

methods

var shortcode = require('shortcode')

var long = shortcode(code)

For the shorthand string code, return an object with a more verbose representation of the type with properties 'type', 'size' in bits, 'endian' ('big' or 'little'), and array (true or false).

If the code specified is invalid, return undefined.

install

With npm do:

npm install shortcode

license

MIT

npm loves you