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 containingvalue
towriter
.- Parameters:
value – Value to be written
size – Number of bytes to be written
- free_and_get_buffer() Buffer
Frees
writer
and all memory allocated by it except the current data, which is returned asBuffer
.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_with_data(data: Sequence[int], initialized: bool) None
Initializes
writer
with the given memory area. Ifinitialized
isTrue
it is possible to readsize
bytes from theByteWriter
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 ofdata
towriter
.- 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 ofdata
towriter
.- 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_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
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