GstBase.ByteReader

Fields

Name

Type

Access

Description

byte

int

r/w

Current byte position

data

bytes

r/w

Data from which the bit reader will read

size

int

r/w

Size of data in bytes

Methods

dup_data ()

dup_string_utf16 ()

dup_string_utf32 ()

dup_string_utf8 ()

free ()

get_data ()

get_float32_be ()

get_float32_le ()

get_float64_be ()

get_float64_le ()

get_int16_be ()

get_int16_le ()

get_int24_be ()

get_int24_le ()

get_int32_be ()

get_int32_le ()

get_int64_be ()

get_int64_le ()

get_int8 ()

get_pos ()

get_remaining ()

get_size ()

get_string_utf8 ()

get_uint16_be ()

get_uint16_le ()

get_uint24_be ()

get_uint24_le ()

get_uint32_be ()

get_uint32_le ()

get_uint64_be ()

get_uint64_le ()

get_uint8 ()

init (data)

masked_scan_uint32 (mask, pattern, offset, size)

masked_scan_uint32_peek (mask, pattern, offset, size)

peek_data ()

peek_float32_be ()

peek_float32_le ()

peek_float64_be ()

peek_float64_le ()

peek_int16_be ()

peek_int16_le ()

peek_int24_be ()

peek_int24_le ()

peek_int32_be ()

peek_int32_le ()

peek_int64_be ()

peek_int64_le ()

peek_int8 ()

peek_string_utf8 ()

peek_uint16_be ()

peek_uint16_le ()

peek_uint24_be ()

peek_uint24_le ()

peek_uint32_be ()

peek_uint32_le ()

peek_uint64_be ()

peek_uint64_le ()

peek_uint8 ()

set_pos (pos)

skip (nbytes)

skip_string_utf16 ()

skip_string_utf32 ()

skip_string_utf8 ()

Details

class GstBase.ByteReader

GstBase.ByteReader provides a byte reader that can read different integer and floating point types from a memory buffer. It provides functions for 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 read NUL-terminated strings in various character encodings.

dup_data()
Returns:

True if successful, False otherwise.

val:

address of a #guint8 pointer variable in which to store the result

Return type:

(bool, val: bytes)

Free-function: GLib.free

Returns a newly-allocated copy of the current data position if at least size bytes are left and updates the current position. Free with GLib.free() when no longer needed.

dup_string_utf16()
Returns:

True if a string could be read, False otherwise. The string put into str must be freed with GLib.free() when no longer needed.

str:

address of a #guint16 pointer variable in which to store the result

Return type:

(bool, str: [int])

Free-function: GLib.free

Returns a newly-allocated copy of the current data position if there is a NUL-terminated UTF-16 string in the data (this could be an empty string as well), and advances the current position.

No input checking for valid UTF-16 is done. This function is endianness agnostic - you should not assume the UTF-16 characters are in host endianness.

This function will fail if no NUL-terminator was found in in the data.

Note: there is no peek or get variant of this function to ensure correct byte alignment of the UTF-16 string.

dup_string_utf32()
Returns:

True if a string could be read, False otherwise. The string put into str must be freed with GLib.free() when no longer needed.

str:

address of a #guint32 pointer variable in which to store the result

Return type:

(bool, str: [int])

Free-function: GLib.free

Returns a newly-allocated copy of the current data position if there is a NUL-terminated UTF-32 string in the data (this could be an empty string as well), and advances the current position.

No input checking for valid UTF-32 is done. This function is endianness agnostic - you should not assume the UTF-32 characters are in host endianness.

This function will fail if no NUL-terminator was found in in the data.

Note: there is no peek or get variant of this function to ensure correct byte alignment of the UTF-32 string.

dup_string_utf8()
Returns:

True if a string could be read into str, False otherwise. The string put into str must be freed with GLib.free() when no longer needed.

str:

address of a str pointer variable in which to store the result

Return type:

(bool, str: [str])

Free-function: GLib.free

FIXME:Reads (copies) a NUL-terminated string in the GstBase.ByteReader instance, advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

free()

Frees a GstBase.ByteReader instance, which was previously allocated by gst_byte_reader_new().

get_data()
Returns:

True if successful, False otherwise.

val:

address of a #guint8 pointer variable in which to store the result

Return type:

(bool, val: bytes)

Returns a constant pointer to the current data position if at least size bytes are left and updates the current position.

get_float32_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 32 bit big endian floating point value into val and update the current position.

get_float32_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 32 bit little endian floating point value into val and update the current position.

get_float64_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 64 bit big endian floating point value into val and update the current position.

get_float64_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 64 bit little endian floating point value into val and update the current position.

get_int16_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint16 to store the result

Return type:

(bool, val: int)

Read a signed 16 bit big endian integer into val and update the current position.

get_int16_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint16 to store the result

Return type:

(bool, val: int)

Read a signed 16 bit little endian integer into val and update the current position.

get_int24_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 24 bit big endian integer into val and update the current position.

get_int24_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 24 bit little endian integer into val and update the current position.

get_int32_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 32 bit big endian integer into val and update the current position.

get_int32_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 32 bit little endian integer into val and update the current position.

get_int64_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint64 to store the result

Return type:

(bool, val: int)

Read a signed 64 bit big endian integer into val and update the current position.

get_int64_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint64 to store the result

Return type:

(bool, val: int)

Read a signed 64 bit little endian integer into val and update the current position.

get_int8()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint8 to store the result

Return type:

(bool, val: int)

Read a signed 8 bit integer into val and update the current position.

get_pos()
Returns:

The current position of self in bytes.

Return type:

int

Returns the current position of a GstBase.ByteReader instance in bytes.

get_remaining()
Returns:

The remaining number of bytes of self instance.

Return type:

int

Returns the remaining number of bytes of a GstBase.ByteReader instance.

get_size()
Returns:

The total number of bytes of self instance.

Return type:

int

Returns the total number of bytes of a GstBase.ByteReader instance.

get_string_utf8()
Returns:

True if a string could be found, False otherwise.

str:

address of a str pointer variable in which to store the result

Return type:

(bool, str: [str])

Returns a constant pointer to the current data position if there is a NUL-terminated string in the data (this could be just a NUL terminator), advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc.

No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

get_uint16_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint16 to store the result

Return type:

(bool, val: int)

Read an unsigned 16 bit big endian integer into val and update the current position.

get_uint16_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint16 to store the result

Return type:

(bool, val: int)

Read an unsigned 16 bit little endian integer into val and update the current position.

get_uint24_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 24 bit big endian integer into val and update the current position.

get_uint24_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 24 bit little endian integer into val and update the current position.

get_uint32_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 32 bit big endian integer into val and update the current position.

get_uint32_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 32 bit little endian integer into val and update the current position.

get_uint64_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint64 to store the result

Return type:

(bool, val: int)

Read an unsigned 64 bit big endian integer into val and update the current position.

get_uint64_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint64 to store the result

Return type:

(bool, val: int)

Read an unsigned 64 bit little endian integer into val and update the current position.

get_uint8()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint8 to store the result

Return type:

(bool, val: int)

Read an unsigned 8 bit integer into val and update the current position.

init(data)
Parameters:

data (bytes) – data from which the GstBase.ByteReader should read

Initializes a GstBase.ByteReader instance to read from data. This function can be called on already initialized instances.

masked_scan_uint32(mask, pattern, offset, size)
Parameters:
  • mask (int) – mask to apply to data before matching against pattern

  • pattern (int) – pattern to match (after mask is applied)

  • offset (int) – offset from which to start scanning, relative to the current position

  • size (int) – number of bytes to scan from offset

Returns:

offset of the first match, or -1 if no match was found.

Example:

// Assume the reader contains 0x00 0x01 0x02 ... 0xfe 0xff

gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 0, 256);
// -> returns 0
gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 1, 255);
// -> returns -1
gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x01020304, 1, 255);
// -> returns 1
gst_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0001, 0, 256);
// -> returns -1
gst_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0203, 0, 256);
// -> returns 0
gst_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 256);
// -> returns 2
gst_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 4);
// -> returns -1

Return type:

int

Scan for pattern pattern with applied mask mask in the byte reader data, starting from offset offset relative to the current position.

The bytes in pattern and mask are interpreted left-to-right, regardless of endianness. All four bytes of the pattern must be present in the byte reader data for it to match, even if the first or last bytes are masked out.

It is an error to call this function without making sure that there is enough data (offset+size bytes) in the byte reader.

masked_scan_uint32_peek(mask, pattern, offset, size)
Parameters:
  • mask (int) – mask to apply to data before matching against pattern

  • pattern (int) – pattern to match (after mask is applied)

  • offset (int) – offset from which to start scanning, relative to the current position

  • size (int) – number of bytes to scan from offset

Returns:

offset of the first match, or -1 if no match was found.

value:

pointer to uint32 to return matching data

Return type:

(int, value: int)

Scan for pattern pattern with applied mask mask in the byte reader data, starting from offset offset relative to the current position.

The bytes in pattern and mask are interpreted left-to-right, regardless of endianness. All four bytes of the pattern must be present in the byte reader data for it to match, even if the first or last bytes are masked out.

It is an error to call this function without making sure that there is enough data (offset+size bytes) in the byte reader.

New in version 1.6.

peek_data()
Returns:

True if successful, False otherwise.

val:

address of a #guint8 pointer variable in which to store the result

Return type:

(bool, val: bytes)

Returns a constant pointer to the current data position if at least size bytes are left and keeps the current position.

peek_float32_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 32 bit big endian floating point value into val but keep the current position.

peek_float32_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 32 bit little endian floating point value into val but keep the current position.

peek_float64_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 64 bit big endian floating point value into val but keep the current position.

peek_float64_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a float to store the result

Return type:

(bool, val: float)

Read a 64 bit little endian floating point value into val but keep the current position.

peek_int16_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint16 to store the result

Return type:

(bool, val: int)

Read a signed 16 bit big endian integer into val but keep the current position.

peek_int16_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint16 to store the result

Return type:

(bool, val: int)

Read a signed 16 bit little endian integer into val but keep the current position.

peek_int24_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 24 bit big endian integer into val but keep the current position.

peek_int24_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 24 bit little endian integer into val but keep the current position.

peek_int32_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 32 bit big endian integer into val but keep the current position.

peek_int32_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint32 to store the result

Return type:

(bool, val: int)

Read a signed 32 bit little endian integer into val but keep the current position.

peek_int64_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint64 to store the result

Return type:

(bool, val: int)

Read a signed 64 bit big endian integer into val but keep the current position.

peek_int64_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint64 to store the result

Return type:

(bool, val: int)

Read a signed 64 bit little endian integer into val but keep the current position.

peek_int8()
Returns:

True if successful, False otherwise.

val:

Pointer to a #gint8 to store the result

Return type:

(bool, val: int)

Read a signed 8 bit integer into val but keep the current position.

peek_string_utf8()
Returns:

True if a string could be skipped, False otherwise.

str:

address of a str pointer variable in which to store the result

Return type:

(bool, str: [str])

Returns a constant pointer to the current data position if there is a NUL-terminated string in the data (this could be just a NUL terminator). The current position will be maintained. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc.

No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

peek_uint16_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint16 to store the result

Return type:

(bool, val: int)

Read an unsigned 16 bit big endian integer into val but keep the current position.

peek_uint16_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint16 to store the result

Return type:

(bool, val: int)

Read an unsigned 16 bit little endian integer into val but keep the current position.

peek_uint24_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 24 bit big endian integer into val but keep the current position.

peek_uint24_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 24 bit little endian integer into val but keep the current position.

peek_uint32_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 32 bit big endian integer into val but keep the current position.

peek_uint32_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint32 to store the result

Return type:

(bool, val: int)

Read an unsigned 32 bit little endian integer into val but keep the current position.

peek_uint64_be()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint64 to store the result

Return type:

(bool, val: int)

Read an unsigned 64 bit big endian integer into val but keep the current position.

peek_uint64_le()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint64 to store the result

Return type:

(bool, val: int)

Read an unsigned 64 bit little endian integer into val but keep the current position.

peek_uint8()
Returns:

True if successful, False otherwise.

val:

Pointer to a #guint8 to store the result

Return type:

(bool, val: int)

Read an unsigned 8 bit integer into val but keep the current position.

set_pos(pos)
Parameters:

pos (int) – The new position in bytes

Returns:

True if the position could be set successfully, False otherwise.

Return type:

bool

Sets the new position of a GstBase.ByteReader instance to pos in bytes.

skip(nbytes)
Parameters:

nbytes (int) – the number of bytes to skip

Returns:

True if nbytes bytes could be skipped, False otherwise.

Return type:

bool

Skips nbytes bytes of the GstBase.ByteReader instance.

skip_string_utf16()
Returns:

True if a string could be skipped, False otherwise.

Return type:

bool

Skips a NUL-terminated UTF-16 string in the GstBase.ByteReader instance, advancing the current position to the byte after the string.

No input checking for valid UTF-16 is done.

This function will fail if no NUL-terminator was found in in the data.

skip_string_utf32()
Returns:

True if a string could be skipped, False otherwise.

Return type:

bool

Skips a NUL-terminated UTF-32 string in the GstBase.ByteReader instance, advancing the current position to the byte after the string.

No input checking for valid UTF-32 is done.

This function will fail if no NUL-terminator was found in in the data.

skip_string_utf8()
Returns:

True if a string could be skipped, False otherwise.

Return type:

bool

Skips a NUL-terminated string in the GstBase.ByteReader instance, advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.