BitBuffer provides two objects,
BitStream is a wrapper for a
BitView used to help maintain your current buffer position, as well as to provide higher-level read / write operations such as for ASCII strings.
bb.buffer // Underlying ArrayBuffer.
BitView(buffer, optional byteOffset, optional byteLength)
Default constructor, takes in a single argument of an ArrayBuffer. Optional are the
byteLength arguments to offset and truncate the view's representation of the buffer.
getBits(offset, bits, signed)
bits number of bits starting at
getInt8, getUint8, getInt16, getUint16, getInt32, getUint32(offset)
Shortcuts for getBits, setting the correct
Gets 32 bits from
offset, and coerces and returns as a proper float32 value.
Gets 64 bits from
offset, and coerces and returns as a proper float64 value.
setBits(offset, value, bits)
bits number of bits at
setInt8, setUint8, setInt16, setUint16, setInt32, setUint32(offset)
Shortcuts for setBits, setting the correct
Coerces a float32 to uint32 and sets at
Coerces a float64 to two uint32s and sets at
bb.byteIndex // Get current index in bytes. bb.byteIndex = 0; // Set current index in bytes.
bb.view // Underlying BitView
Default constructor, takes in a single argument of a BitView.
BitSteam(buffer, optional byteOffset, optional byteLength)
Shortcut constructor that initializes a new
BitView(buffer, byteOffset, byteLength) for the stream to use.
bits numbers of bits from the view at the current index, updating the index.
bits numbers of bits from
value in the view at the current index, updating the index.
Reads bytes from the underlying view at the current index until either
bytes count is reached or a 0x00 terminator is reached.
writeASCIIString(string, optional bytes)
Writes a string followed by a NULL character to the underlying view starting at the current index. If the string is longer than
bytes it will be truncated, and if it is shorter 0x00 will be written in its place.