ByteWriter

class ByteWriter(*args, **kwargs)

ByteWriter provides a byte writer and reader that can write/read different integer and floating point types to/from a memory buffer. It provides functions for writing/reading signed/unsigned, little/big endian integers of 8, 16, 24, 32 and 64 bits and functions for reading little/big endian floating points numbers of 32 and 64 bits. It also provides functions to write/read NUL-terminated strings in various character encodings.

Methods

class ByteWriter
ensure_free_space(size: int) bool

Checks if enough free space from the current write cursor is available and reallocates if necessary.

Parameters:

size – Number of bytes that should be available

fill(value: int, size: int) bool

Writes size bytes containing value to writer.

Parameters:
  • value – Value to be written

  • size – Number of bytes to be written

free() None

Frees writer and all memory allocated by it.

free_and_get_buffer() Buffer

Frees writer and all memory allocated by it except the current data, which is returned as Buffer.

Free-function: gst_buffer_unref

free_and_get_data() int

Frees writer and all memory allocated by it except the current data, which is returned.

Free-function: g_free

get_remaining() int

Returns the remaining size of data that can still be written. If

-1 is returned the remaining size is only limited by system resources.

init() None

Initializes writer to an empty instance

init_with_data(data: Sequence[int], initialized: bool) None

Initializes writer with the given memory area. If initialized is True it is possible to read size bytes from the ByteWriter from the beginning.

Parameters:
  • data – Memory area for writing

  • initialized – If True the complete data can be read from the beginning

init_with_size(size: int, fixed: bool) None

Initializes writer with the given initial data size.

Parameters:
  • size – Initial size of data

  • fixed – If True the data can’t be reallocated

put_buffer(buffer: Buffer, offset: int, size: int) bool

Writes size bytes of data to writer.

Parameters:
  • buffer – source Buffer

  • offset – offset to copy from

  • size – total size to copy. If -1, all data is copied

put_data(data: Sequence[int]) bool

Writes size bytes of data to writer.

Parameters:

data – Data to write

put_float32_be(val: float) bool

Writes a big endian 32 bit float to writer.

Parameters:

val – Value to write

put_float32_le(val: float) bool

Writes a little endian 32 bit float to writer.

Parameters:

val – Value to write

put_float64_be(val: float) bool

Writes a big endian 64 bit float to writer.

Parameters:

val – Value to write

put_float64_le(val: float) bool

Writes a little endian 64 bit float to writer.

Parameters:

val – Value to write

put_int16_be(val: int) bool

Writes a signed big endian 16 bit integer to writer.

Parameters:

val – Value to write

put_int16_le(val: int) bool

Writes a signed little endian 16 bit integer to writer.

Parameters:

val – Value to write

put_int24_be(val: int) bool

Writes a signed big endian 24 bit integer to writer.

Parameters:

val – Value to write

put_int24_le(val: int) bool

Writes a signed little endian 24 bit integer to writer.

Parameters:

val – Value to write

put_int32_be(val: int) bool

Writes a signed big endian 32 bit integer to writer.

Parameters:

val – Value to write

put_int32_le(val: int) bool

Writes a signed little endian 32 bit integer to writer.

Parameters:

val – Value to write

put_int64_be(val: int) bool

Writes a signed big endian 64 bit integer to writer.

Parameters:

val – Value to write

put_int64_le(val: int) bool

Writes a signed little endian 64 bit integer to writer.

Parameters:

val – Value to write

put_int8(val: int) bool

Writes a signed 8 bit integer to writer.

Parameters:

val – Value to write

put_string_utf16(data: Sequence[int]) bool

Writes a NUL-terminated UTF16 string to writer (including the terminator).

Parameters:

data – UTF16 string to write

put_string_utf32(data: Sequence[int]) bool

Writes a NUL-terminated UTF32 string to writer (including the terminator).

Parameters:

data – UTF32 string to write

put_string_utf8(data: str) bool

Writes a NUL-terminated UTF8 string to writer (including the terminator).

Parameters:

data – UTF8 string to write

put_uint16_be(val: int) bool

Writes a unsigned big endian 16 bit integer to writer.

Parameters:

val – Value to write

put_uint16_le(val: int) bool

Writes a unsigned little endian 16 bit integer to writer.

Parameters:

val – Value to write

put_uint24_be(val: int) bool

Writes a unsigned big endian 24 bit integer to writer.

Parameters:

val – Value to write

put_uint24_le(val: int) bool

Writes a unsigned little endian 24 bit integer to writer.

Parameters:

val – Value to write

put_uint32_be(val: int) bool

Writes a unsigned big endian 32 bit integer to writer.

Parameters:

val – Value to write

put_uint32_le(val: int) bool

Writes a unsigned little endian 32 bit integer to writer.

Parameters:

val – Value to write

put_uint64_be(val: int) bool

Writes a unsigned big endian 64 bit integer to writer.

Parameters:

val – Value to write

put_uint64_le(val: int) bool

Writes a unsigned little endian 64 bit integer to writer.

Parameters:

val – Value to write

put_uint8(val: int) bool

Writes a unsigned 8 bit integer to writer.

Parameters:

val – Value to write

reset() None

Resets writer and frees the data if it’s owned by writer.

reset_and_get_buffer() Buffer

Resets writer and returns the current data as buffer.

Free-function: gst_buffer_unref

reset_and_get_data() bytes

Resets writer and returns the current data.

Free-function: g_free

Fields

class ByteWriter
alloc_size

Allocation size of the data

fixed

If True no reallocations are allowed

owned

If False no reallocations are allowed and copies of data are returned

parent

ByteReader parent