zserio.bitwriter module

The module implements abstraction for writing data to the bit stream.

class zserio.bitwriter.BitStreamWriter[source]

Bases: object

Bit stream writer using bytearray.

Constructor.

alignto(alignment: int) None[source]

Aligns the bit position according to the aligning value.

Parameters:

alignment – An aligning value to use.

property bitposition: int

Gets current bit position.

Returns:

Current bit position.

property byte_array: bytes

Gets internal bytearray.

Returns:

Underlying bytearray object.

to_file(filename: str) None[source]

Writes underlying bytearray to binary file.

Parameters:

filename – File to write.

write_bitbuffer(bitbuffer: BitBuffer) None[source]

Writes a bit buffer to the underlying storage. Length of the bit buffer is written as varsize at the beginning.

Parameters:

bitbuffer – Bit buffer to write.

write_bits(value: int, numbits: int) None[source]

Writes the given value with the given number of bits to the underlying storage.

Parameters:
  • value – Value to write.

  • numbits – Number of bits to write.

Raises:

PythonRuntimeException – If the value is out of the range or if the number of bits is invalid.

write_bits_unchecked(value: int, numbits: int) None[source]

Writes the given value with the given number of bits to the underlying storage.

This method does not check that numbits > 0 and assumes that it’s ensured by the caller.

Parameters:
  • value – Value to write.

  • numbits – Number of bits to write.

Raises:

PythonRuntimeException – If the value is out of the range or if the number of bits is invalid.

write_bool(value: bool) None[source]

Writes bool in a single bit.

Parameters:

value – Bool value to write.

write_bytes(value: bytearray)[source]

Writes the given bytes to the underlying storage. Length of the bytes is written as varsize at the beginning.

Parameters:

value – Bytes to write.

write_float16(value: float) None[source]

Writes a 16-bit float value to the underlying storage according to IEEE 754 binary16.

Parameters:

value – Float value to write.

write_float32(value: float) None[source]

Writes a 32-bit float value to the underlying storage according to IEEE 754 binary32.

Parameters:

value – Float value to write.

write_float64(value: float) None[source]

Writes a 64-bit float value to the underlying storage according to IEEE 754 binary64.

Parameters:

value – Float value to write.

write_signed_bits(value: int, numbits: int) None[source]

Writes the given signed value with the given number of bits to the underlying storage. Provided for convenience.

Parameters:
  • value – Signed value to write.

  • numbits – Number of bits to write.

Raises:

PythonRuntimeException – If the value is out of the range or if the number of bits is invalid.

write_signed_bits_unchecked(value: int, numbits: int) None[source]

Writes the given signed value with the given number of bits to the underlying storage. Provided for convenience.

This method does not check that numbits > 0 and assumes that it’s ensured by the caller.

Parameters:
  • value – Signed value to write.

  • numbits – Number of bits to write.

Raises:

PythonRuntimeException – If the value is out of the range or if the number of bits is invalid.

write_string(string: str) None[source]

Writes the given string to the underlying storage in UTF-8 encoding. Length of the string is written as varsize at the beginning.

Parameters:

string – String to write.

write_varint(value: int) None[source]

Writes a variable signed integer value (up to 9 bytes) to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varint16(value: int) None[source]

Writes a variable 16-bit signed integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varint32(value: int) None[source]

Writes a variable 32-bit signed integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varint64(value: int) None[source]

Writes a variable 16-bit signed integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varsize(value: int) None[source]

Writes a variable size integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varuint(value: int) None[source]

Writes a variable unsigned integer value (up to 9 bytes) to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varuint16(value: int) None[source]

Writes a variable 16-bit unsigned integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varuint32(value: int) None[source]

Writes a variable 32-bit unsigned integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.

write_varuint64(value: int) None[source]

Writes a variable 16-bit unsigned integer value to the underlying storage.

Parameters:

value – Value to write.

Raises:

PythonRuntimeException – If the value is out of the range.