shortcode

shorthand for binary encodings

shortcode

shorthand for binary encodings

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}{,[]}

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

signed integer

unsigned integer

32-bit floating point

64-bit floating point

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

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

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')

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