This module makes creating binary formats easy. It supports both fixed length structures (like classic c structs), and variable (usually length delemited) structures.
If you want Big Endian, append BE, for examlpe Int16BE or add LE for Little Endian.
64 bit ints are actually only 53 bit ints, but they will still be written to 8 bytes. (based on int53)
Array(lengthArray, itemCodec)
Create codec that encodes an array with fixed length.
VarArray(lengthCodec, itemCodec)
Create a variable length codec that encodes an array of items. itemCodec may be any varstruct compatible codec, including a VarArray. As long as it can encode very element in the array, lengthCodec must encode an integer.
Sequence([ itemType, itemType, ..., itemType ])
Create codec that encodes an array with fixed length and various types.
Buffer(length)
Create a fixed length buffer codec.
VarBuffer(lengthCodec)
Create a variable length buffer codec. This will first write out the length of the value buffer and then the value buffer itself. The lengthCodec may be variable length itself, but must encode an integer.
VarMap(lengthCodec, keyCodec, valueCodec)
Create a variable length object codec. This will first write out the number of entries in the object and then write each entry as a key-value pair.
The keyCodec must accept typeof === 'string' keys.
String(length [, encoding = 'utf-8'])
Create a fixed length (in bytes) string codec.
VarString(lengthCodec [, encoding = 'utf-8'])
Create a variable length string codec. This codec uses VarBuffer (buffer will be created from string with given encoding).
Bound(itemCodec, checkValueCallback)
Return a codec that will call checkValueCallback before encode and after decode. checkValueCallback should throw error if the given value is wrong.
Value(itemCodec, constantValue)
Return a codec that will encode constantValue every time (and will throw if given any value other than constantValue), and will decode constantValue if it exists (throwing otherwise).