Class ByteReader
- All Implemented Interfaces:
Proxy
GstByteReader 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.-
Constructor Summary
ConstructorsConstructorDescriptionAllocate a new ByteReader.ByteReader(byte[] data, int size, int byte_) Allocate a new ByteReader with the fields set to the provided values.ByteReader(byte[] data, int size, int byte_, Arena arena) Allocate a new ByteReader with the fields set to the provided values.ByteReader(Arena arena) Allocate a new ByteReader.ByteReader(MemorySegment address) Create a ByteReader proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanFree-function: g_freebooleandupStringUtf32(@Nullable Out<int[]> str) Free-function: g_freebooleandupStringUtf8(@Nullable Out<String[]> str) Free-function: g_freevoidfree()Frees aGstByteReaderinstance, which was previously allocated by gst_byte_reader_new().booleanReturns a constant pointer to the current data position if at leastsizebytes are left and updates the current position.booleangetFloat32Be(Out<Float> val) Read a 32 bit big endian floating point value intovaland update the current position.booleangetFloat32Le(Out<Float> val) Read a 32 bit little endian floating point value intovaland update the current position.booleangetFloat64Be(Out<Double> val) Read a 64 bit big endian floating point value intovaland update the current position.booleangetFloat64Le(Out<Double> val) Read a 64 bit little endian floating point value intovaland update the current position.booleangetInt16Be(Out<Short> val) Read a signed 16 bit big endian integer intovaland update the current position.booleangetInt16Le(Out<Short> val) Read a signed 16 bit little endian integer intovaland update the current position.booleangetInt24Be(Out<Integer> val) Read a signed 24 bit big endian integer intovaland update the current position.booleangetInt24Le(Out<Integer> val) Read a signed 24 bit little endian integer intovaland update the current position.booleangetInt32Be(Out<Integer> val) Read a signed 32 bit big endian integer intovaland update the current position.booleangetInt32Le(Out<Integer> val) Read a signed 32 bit little endian integer intovaland update the current position.booleangetInt64Be(Out<Long> val) Read a signed 64 bit big endian integer intovaland update the current position.booleangetInt64Le(Out<Long> val) Read a signed 64 bit little endian integer intovaland update the current position.booleanRead a signed 8 bit integer intovaland update the current position.static MemoryLayoutThe memory layout of the native struct.intgetPos()Returns the current position of aGstByteReaderinstance in bytes.intReturns the remaining number of bytes of aGstByteReaderinstance.intgetSize()Returns the total number of bytes of aGstByteReaderinstance.booleangetStringUtf8(@Nullable Out<String[]> 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.booleangetSubReader(ByteReader subReader, int size) Initializes aGstByteReadersub-reader instance to containsizebytes of data from the current position ofreader.This is useful to read chunked formats and make sure that one doesn't read beyond the size of the sub-chunk.booleangetUint16Be(Out<Short> val) Read an unsigned 16 bit big endian integer intovaland update the current position.booleangetUint16Le(Out<Short> val) Read an unsigned 16 bit little endian integer intovaland update the current position.booleangetUint24Be(Out<Integer> val) Read an unsigned 24 bit big endian integer intovaland update the current position.booleangetUint24Le(Out<Integer> val) Read an unsigned 24 bit little endian integer intovaland update the current position.booleangetUint32Be(Out<Integer> val) Read an unsigned 32 bit big endian integer intovaland update the current position.booleangetUint32Le(Out<Integer> val) Read an unsigned 32 bit little endian integer intovaland update the current position.booleangetUint64Be(Out<Long> val) Read an unsigned 64 bit big endian integer intovaland update the current position.booleangetUint64Le(Out<Long> val) Read an unsigned 64 bit little endian integer intovaland update the current position.booleanRead an unsigned 8 bit integer intovaland update the current position.voidinit(@org.jspecify.annotations.Nullable byte @Nullable [] data) Initializes aGstByteReaderinstance to read fromdata.This function can be called on already initialized instances.intmaskedScanUint32(int mask, int pattern, int offset, int size) Scan for patternpatternwith applied maskmaskin the byte reader data, starting from offsetoffsetrelative to the current position.intmaskedScanUint32Peek(int mask, int pattern, int offset, int size, Out<Integer> value) Scan for patternpatternwith applied maskmaskin the byte reader data, starting from offsetoffsetrelative to the current position.static ByteReadernew_(@org.jspecify.annotations.Nullable byte @Nullable [] data) Create a newGstByteReaderinstance, which will read fromdata.booleanReturns a constant pointer to the current data position if at leastsizebytes are left and keeps the current position.booleanpeekFloat32Be(Out<Float> val) Read a 32 bit big endian floating point value intovalbut keep the current position.booleanpeekFloat32Le(Out<Float> val) Read a 32 bit little endian floating point value intovalbut keep the current position.booleanpeekFloat64Be(Out<Double> val) Read a 64 bit big endian floating point value intovalbut keep the current position.booleanpeekFloat64Le(Out<Double> val) Read a 64 bit little endian floating point value intovalbut keep the current position.booleanpeekInt16Be(Out<Short> val) Read a signed 16 bit big endian integer intovalbut keep the current position.booleanpeekInt16Le(Out<Short> val) Read a signed 16 bit little endian integer intovalbut keep the current position.booleanpeekInt24Be(Out<Integer> val) Read a signed 24 bit big endian integer intovalbut keep the current position.booleanpeekInt24Le(Out<Integer> val) Read a signed 24 bit little endian integer intovalbut keep the current position.booleanpeekInt32Be(Out<Integer> val) Read a signed 32 bit big endian integer intovalbut keep the current position.booleanpeekInt32Le(Out<Integer> val) Read a signed 32 bit little endian integer intovalbut keep the current position.booleanpeekInt64Be(Out<Long> val) Read a signed 64 bit big endian integer intovalbut keep the current position.booleanpeekInt64Le(Out<Long> val) Read a signed 64 bit little endian integer intovalbut keep the current position.booleanRead a signed 8 bit integer intovalbut keep the current position.booleanpeekStringUtf8(@Nullable Out<String[]> 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).booleanpeekSubReader(ByteReader subReader, int size) Initializes aGstByteReadersub-reader instance to containsizebytes of data from the current position ofreader.This is useful to read chunked formats and make sure that one doesn't read beyond the size of the sub-chunk.booleanpeekUint16Be(Out<Short> val) Read an unsigned 16 bit big endian integer intovalbut keep the current position.booleanpeekUint16Le(Out<Short> val) Read an unsigned 16 bit little endian integer intovalbut keep the current position.booleanpeekUint24Be(Out<Integer> val) Read an unsigned 24 bit big endian integer intovalbut keep the current position.booleanpeekUint24Le(Out<Integer> val) Read an unsigned 24 bit little endian integer intovalbut keep the current position.booleanpeekUint32Be(Out<Integer> val) Read an unsigned 32 bit big endian integer intovalbut keep the current position.booleanpeekUint32Le(Out<Integer> val) Read an unsigned 32 bit little endian integer intovalbut keep the current position.booleanpeekUint64Be(Out<Long> val) Read an unsigned 64 bit big endian integer intovalbut keep the current position.booleanpeekUint64Le(Out<Long> val) Read an unsigned 64 bit little endian integer intovalbut keep the current position.booleanRead an unsigned 8 bit integer intovalbut keep the current position.intreadByte()Read the value of the fieldbyte.@org.jspecify.annotations.Nullable byte @Nullable []readData()Read the value of the fielddata.intreadSize()Read the value of the fieldsize.booleansetPos(int pos) Sets the new position of aGstByteReaderinstance toposin bytes.booleanskip(int nbytes) Skipsnbytesbytes of theGstByteReaderinstance.booleanSkips a NUL-terminated UTF-16 string in theGstByteReaderinstance, advancing the current position to the byte after the string.booleanSkips a NUL-terminated UTF-32 string in theGstByteReaderinstance, advancing the current position to the byte after the string.booleanSkips a NUL-terminated string in theGstByteReaderinstance, advancing the current position to the byte after the string.voidwriteByte(int byte_) Write a value in the fieldbyte.voidWrite a value in the fielddata.voidwriteSize(int size) Write a value in the fieldsize.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
ByteReader
Create a ByteReader proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
ByteReader
Allocate a new ByteReader.- Parameters:
arena- to control the memory allocation scope
-
ByteReader
public ByteReader()Allocate a new ByteReader. The memory is allocated withArena.ofAuto(). -
ByteReader
Allocate a new ByteReader with the fields set to the provided values.- Parameters:
data- value for the fielddatasize- value for the fieldsizebyte_- value for the fieldbyte_arena- to control the memory allocation scope
-
ByteReader
public ByteReader(byte[] data, int size, int byte_) Allocate a new ByteReader with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
data- value for the fielddatasize- value for the fieldsizebyte_- value for the fieldbyte_
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readData
public @org.jspecify.annotations.Nullable byte @Nullable [] readData()Read the value of the fielddata.- Returns:
- The value of the field
data
-
writeData
Write a value in the fielddata.- Parameters:
data- The new value for the fielddata_arena- to control the memory allocation scope
-
readSize
public int readSize()Read the value of the fieldsize.- Returns:
- The value of the field
size
-
writeSize
public void writeSize(int size) Write a value in the fieldsize.- Parameters:
size- The new value for the fieldsize
-
readByte
public int readByte()Read the value of the fieldbyte.- Returns:
- The value of the field
byte
-
writeByte
public void writeByte(int byte_) Write a value in the fieldbyte.- Parameters:
byte_- The new value for the fieldbyte
-
new_
Create a newGstByteReaderinstance, which will read fromdata.Free-function: gst_byte_reader_free
- Parameters:
data- data from which theGstByteReadershould read- Returns:
- a new
GstByteReaderinstance
-
dupData
Free-function: g_freeReturns a newly-allocated copy of the current data position if at least
sizebytes are left and updates the current position. Free with g_free() when no longer needed.- Parameters:
val- address of aguint8pointer variable in which to store the result- Returns:
trueif successful,falseotherwise.
-
dupStringUtf32
Free-function: g_freeReturns 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.
- Parameters:
str- address of aguint32pointer variable in which to store the result- Returns:
trueif a string could be read,falseotherwise. The string put intostrmust be freed with g_free() when no longer needed.
-
dupStringUtf8
Free-function: g_freeFIXME:Reads (copies) a NUL-terminated string in the
GstByteReaderinstance, 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.
- Parameters:
str- address of agcharpointer variable in which to store the result- Returns:
trueif a string could be read intostr,falseotherwise. The string put intostrmust be freed with g_free() when no longer needed.
-
free
public void free()Frees aGstByteReaderinstance, which was previously allocated by gst_byte_reader_new(). -
getData
Returns a constant pointer to the current data position if at leastsizebytes are left and updates the current position.- Parameters:
val- address of aguint8pointer variable in which to store the result- Returns:
trueif successful,falseotherwise.
-
getFloat32Be
-
getFloat32Le
-
getFloat64Be
-
getFloat64Le
-
getInt16Be
-
getInt16Le
-
getInt24Be
-
getInt24Le
-
getInt32Be
-
getInt32Le
-
getInt64Be
-
getInt64Le
-
getInt8
-
getPos
public int getPos()Returns the current position of aGstByteReaderinstance in bytes.- Returns:
- The current position of this ByteReader in bytes.
-
getRemaining
public int getRemaining()Returns the remaining number of bytes of aGstByteReaderinstance.- Returns:
- The remaining number of bytes of this ByteReader instance.
-
getSize
public int getSize()Returns the total number of bytes of aGstByteReaderinstance.- Returns:
- The total number of bytes of this ByteReader instance.
-
getStringUtf8
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.
- Parameters:
str- address of agcharpointer variable in which to store the result- Returns:
trueif a string could be found,falseotherwise.
-
getSubReader
Initializes aGstByteReadersub-reader instance to containsizebytes of data from the current position ofreader.This is useful to read chunked formats and make sure that one doesn't read beyond the size of the sub-chunk.Unlike gst_byte_reader_peek_sub_reader(), this function also modifies the position of this ByteReader and moves it forward by
sizebytes.- Parameters:
subReader- aGstByteReaderinstance to initialize as sub-readersize- size ofsubReaderin bytes- Returns:
- FALSE on error or if this ByteReader does not contain
sizemore bytes from the current position, and otherwise TRUE - Since:
- 1.6
-
getUint16Be
-
getUint16Le
-
getUint24Be
-
getUint24Le
-
getUint32Be
-
getUint32Le
-
getUint64Be
-
getUint64Le
-
getUint8
-
init
public void init(@org.jspecify.annotations.Nullable byte @Nullable [] data) Initializes aGstByteReaderinstance to read fromdata.This function can be called on already initialized instances.- Parameters:
data- data from which theGstByteReadershould read
-
maskedScanUint32
public int maskedScanUint32(int mask, int pattern, int offset, int size) Scan for patternpatternwith applied maskmaskin the byte reader data, starting from offsetoffsetrelative to the current position.The bytes in
patternandmaskare 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.
- Parameters:
mask- mask to apply to data before matching againstpatternpattern- pattern to match (after mask is applied)offset- offset from which to start scanning, relative to the current positionsize- 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
-
maskedScanUint32Peek
Scan for patternpatternwith applied maskmaskin the byte reader data, starting from offsetoffsetrelative to the current position.The bytes in
patternandmaskare 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.
- Parameters:
mask- mask to apply to data before matching againstpatternpattern- pattern to match (after mask is applied)offset- offset from which to start scanning, relative to the current positionsize- number of bytes to scan from offsetvalue- pointer to uint32 to return matching data- Returns:
- offset of the first match, or -1 if no match was found.
- Since:
- 1.6
-
peekData
Returns a constant pointer to the current data position if at leastsizebytes are left and keeps the current position.- Parameters:
val- address of aguint8pointer variable in which to store the result- Returns:
trueif successful,falseotherwise.
-
peekFloat32Be
-
peekFloat32Le
-
peekFloat64Be
-
peekFloat64Le
-
peekInt16Be
-
peekInt16Le
-
peekInt24Be
-
peekInt24Le
-
peekInt32Be
-
peekInt32Le
-
peekInt64Be
-
peekInt64Le
-
peekInt8
-
peekStringUtf8
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.
- Parameters:
str- address of agcharpointer variable in which to store the result- Returns:
trueif a string could be skipped,falseotherwise.
-
peekSubReader
Initializes aGstByteReadersub-reader instance to containsizebytes of data from the current position ofreader.This is useful to read chunked formats and make sure that one doesn't read beyond the size of the sub-chunk.Unlike gst_byte_reader_get_sub_reader(), this function does not modify the current position of
reader.- Parameters:
subReader- aGstByteReaderinstance to initialize as sub-readersize- size ofsubReaderin bytes- Returns:
- FALSE on error or if this ByteReader does not contain
sizemore bytes from the current position, and otherwise TRUE - Since:
- 1.6
-
peekUint16Be
-
peekUint16Le
-
peekUint24Be
-
peekUint24Le
-
peekUint32Be
-
peekUint32Le
-
peekUint64Be
-
peekUint64Le
-
peekUint8
-
setPos
public boolean setPos(int pos) Sets the new position of aGstByteReaderinstance toposin bytes.- Parameters:
pos- The new position in bytes- Returns:
trueif the position could be set successfully,falseotherwise.
-
skip
public boolean skip(int nbytes) Skipsnbytesbytes of theGstByteReaderinstance.- Parameters:
nbytes- the number of bytes to skip- Returns:
trueifnbytesbytes could be skipped,falseotherwise.
-
skipStringUtf16
public boolean skipStringUtf16()Skips a NUL-terminated UTF-16 string in theGstByteReaderinstance, 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.
- Returns:
trueif a string could be skipped,falseotherwise.
-
skipStringUtf32
public boolean skipStringUtf32()Skips a NUL-terminated UTF-32 string in theGstByteReaderinstance, 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.
- Returns:
trueif a string could be skipped,falseotherwise.
-
skipStringUtf8
public boolean skipStringUtf8()Skips a NUL-terminated string in theGstByteReaderinstance, 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.
- Returns:
trueif a string could be skipped,falseotherwise.
-