Primitive Values
There are a few primitives to choose from:
boolis an 8-bit value representing eithertrueorfalse.- Encoded as
1if true, and as0if false.
- Encoded as
byteis an 8-bit value representing an unsigned number between 0 and 255.- Encoded as-is
i32is a 32-bit signed integer number container.- Encoded as-is
f32is a 32-bit signed floating-point number container.- Encoded as-is
stringis a variable-length string of ASCII characters.- A string of characters followed by a
\0terminal character.
- A string of characters followed by a
import bin from 'typed-binary';
const buffer = Buffer.alloc(16);
// Writing four bytes into the bufferconst writer = new bin.BufferWriter(buffer);bin.byte.write(writer, 'W'.charCodeAt(0));bin.byte.write(writer, 'o'.charCodeAt(0));bin.byte.write(writer, 'w'.charCodeAt(0));bin.byte.write(writer, 0);
const reader = new bin.BufferReader(buffer);console.log(bin.string.read(reader)); // > Wow