BitStringWriter
Index
Constructors
constructor
Creates a new and empty
BitStringWriter.Returns BitStringWriter
Methods
flush
Converts the currently held data into a
stringand returns it. Resets the internal buffer.Returns string
flushBase64
Converts the currently held data into a
base64string and returns it. Resets the internal buffer.Returns string
reset
Resets the current writer, discarding any data written so far.
Returns BitStringWriter
toBase64
Converts the currently held data into a
base64string and returns it. Does not modify the internal buffer.Returns string
toBitString
Converts the currently held data into a
stringand returns it. Does not modify the internal buffer.Returns string
writeBit
A convenience function for writing a single bit expressed as an integer of value of either
0or1.With the correct arguments behaves exactly like
writeUnsigned(value, 1).Any other value passed to this function would result in an error.
Parameters
value: number
either
0or1.
Returns BitStringWriter
writeBool
A convenience function for writing a single boolean value.
Coerces value to a boolean, then writes
1if the result is truthy,0otherwise.Parameters
value: any
Returns BitStringWriter
writeSigned
Writes a signed integer with
bitswidth.Throws an
Invalid argumenterror when any of the following is true:bitsis outside [0; SAFE_INTEGER_BITS] range;bitsbits is not enough to storevalue.
Parameters
value: number
a signed integer to be encoded.
bits: number
a non-negative integer. The amount of bits the value should take.
Returns BitStringWriter
writeUnsigned
Writes an unsigned integer with
bitswidth.Throws an
Invalid argumenterror when any of the following is true:valueis negative;bitsis outside [0; SAFE_INTEGER_BITS] range;bitsbits is not enough to storevalue.
Parameters
value: number
a non-negative integer to be encoded.
bits: number
a non-negative integer. The amount of bits the value should take.
Returns BitStringWriter
The writer class. It is responsible for creating a BitString from a sequence of variable-sized integers.