Package org.freedesktop.gstreamer.base
Class ByteWriter
java.lang.Object
org.javagi.base.ProxyInstance
org.freedesktop.gstreamer.base.ByteWriter
- All Implemented Interfaces:
Proxy
GstByteWriter 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.-
Constructor Summary
ConstructorsConstructorDescriptionAllocate a new ByteWriter.ByteWriter(Arena arena) Allocate a new ByteWriter.ByteWriter(MemorySegment address) Create a ByteWriter proxy instance for the provided memory address.ByteWriter(ByteReader parent, int allocSize, boolean fixed, boolean owned) Allocate a new ByteWriter with the fields set to the provided values.ByteWriter(ByteReader parent, int allocSize, boolean fixed, boolean owned, Arena arena) Allocate a new ByteWriter with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionbooleanensureFreeSpace(int size) Checks if enough free space from the current write cursor is available and reallocates if necessary.booleanfill(byte value, int size) Writessizebytes containingvaluetowriter.voidfree()Frees this ByteWriter and all memory allocated by it.Frees this ByteWriter and all memory allocated by it except the current data, which is returned asGstBuffer.Frees this ByteWriter and all memory allocated by it except the current data, which is returned.static MemoryLayoutThe memory layout of the native struct.intReturns the remaining size of data that can still be written.voidinit()Initializes this ByteWriter to an empty instancevoidinitWithData(@org.jspecify.annotations.Nullable byte @Nullable [] data, boolean initialized) Initializes this ByteWriter with the given memory area.voidinitWithSize(int size, boolean fixed) Initializes this ByteWriter with the given initial data size.static ByteWriternew_()Creates a new, emptyGstByteWriterinstancestatic ByteWriternewWithData(MemorySegment data, int size, boolean initialized) Creates a newGstByteWriterinstance with the given memory area.static ByteWriternewWithSize(int size, boolean fixed) Creates a newGstByteWriterinstance with the given initial data size.booleanWritessizebytes ofdatatowriter.booleanputData(@org.jspecify.annotations.Nullable byte @Nullable [] data) Writessizebytes ofdatatowriter.booleanputFloat32Be(float val) Writes a big endian 32 bit float towriter.booleanputFloat32Le(float val) Writes a little endian 32 bit float towriter.booleanputFloat64Be(double val) Writes a big endian 64 bit float towriter.booleanputFloat64Le(double val) Writes a little endian 64 bit float towriter.booleanputInt16Be(short val) Writes a signed big endian 16 bit integer towriter.booleanputInt16Le(short val) Writes a signed little endian 16 bit integer towriter.booleanputInt24Be(int val) Writes a signed big endian 24 bit integer towriter.booleanputInt24Le(int val) Writes a signed little endian 24 bit integer towriter.booleanputInt32Be(int val) Writes a signed big endian 32 bit integer towriter.booleanputInt32Le(int val) Writes a signed little endian 32 bit integer towriter.booleanputInt64Be(long val) Writes a signed big endian 64 bit integer towriter.booleanputInt64Le(long val) Writes a signed little endian 64 bit integer towriter.booleanputInt8(byte val) Writes a signed 8 bit integer towriter.booleanputStringUtf16(@org.jspecify.annotations.Nullable short @Nullable [] data) Writes a NUL-terminated UTF16 string to this ByteWriter (including the terminator).booleanputStringUtf32(@org.jspecify.annotations.Nullable int @Nullable [] data) Writes a NUL-terminated UTF32 string to this ByteWriter (including the terminator).booleanputStringUtf8(String data) Writes a NUL-terminated UTF8 string to this ByteWriter (including the terminator).booleanputUint16Be(short val) Writes a unsigned big endian 16 bit integer towriter.booleanputUint16Le(short val) Writes a unsigned little endian 16 bit integer towriter.booleanputUint24Be(int val) Writes a unsigned big endian 24 bit integer towriter.booleanputUint24Le(int val) Writes a unsigned little endian 24 bit integer towriter.booleanputUint32Be(int val) Writes a unsigned big endian 32 bit integer towriter.booleanputUint32Le(int val) Writes a unsigned little endian 32 bit integer towriter.booleanputUint64Be(long val) Writes a unsigned big endian 64 bit integer towriter.booleanputUint64Le(long val) Writes a unsigned little endian 64 bit integer towriter.booleanputUint8(byte val) Writes a unsigned 8 bit integer towriter.intRead the value of the fieldalloc_size.booleanRead the value of the fieldfixed.booleanRead the value of the fieldowned.@Nullable ByteReaderRead the value of the fieldparent.voidreset()Resets this ByteWriter and frees the data if it's owned bywriter.Resets this ByteWriter and returns the current data as buffer.byte[]Resets this ByteWriter and returns the current data.voidwriteAllocSize(int allocSize) Write a value in the fieldalloc_size.voidwriteFixed(boolean fixed) Write a value in the fieldfixed.voidwriteOwned(boolean owned) Write a value in the fieldowned.voidwriteParent(@Nullable ByteReader parent) Write a value in the fieldparent.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
ByteWriter
Create a ByteWriter proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
ByteWriter
Allocate a new ByteWriter.- Parameters:
arena- to control the memory allocation scope
-
ByteWriter
public ByteWriter()Allocate a new ByteWriter. The memory is allocated withArena.ofAuto(). -
ByteWriter
Allocate a new ByteWriter with the fields set to the provided values.- Parameters:
parent- value for the fieldparentallocSize- value for the fieldallocSizefixed- value for the fieldfixedowned- value for the fieldownedarena- to control the memory allocation scope
-
ByteWriter
Allocate a new ByteWriter with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
parent- value for the fieldparentallocSize- value for the fieldallocSizefixed- value for the fieldfixedowned- value for the fieldowned
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readParent
Read the value of the fieldparent.- Returns:
- The value of the field
parent
-
writeParent
Write a value in the fieldparent.- Parameters:
parent- The new value for the fieldparent
-
readAllocSize
public int readAllocSize()Read the value of the fieldalloc_size.- Returns:
- The value of the field
alloc_size
-
writeAllocSize
public void writeAllocSize(int allocSize) Write a value in the fieldalloc_size.- Parameters:
allocSize- The new value for the fieldalloc_size
-
readFixed
public boolean readFixed()Read the value of the fieldfixed.- Returns:
- The value of the field
fixed
-
writeFixed
public void writeFixed(boolean fixed) Write a value in the fieldfixed.- Parameters:
fixed- The new value for the fieldfixed
-
readOwned
public boolean readOwned()Read the value of the fieldowned.- Returns:
- The value of the field
owned
-
writeOwned
public void writeOwned(boolean owned) Write a value in the fieldowned.- Parameters:
owned- The new value for the fieldowned
-
new_
Creates a new, emptyGstByteWriterinstanceFree-function: gst_byte_writer_free
- Returns:
- a new, empty
GstByteWriterinstance
-
newWithData
Creates a newGstByteWriterinstance with the given memory area. Ifinitializedistrueit is possible to readsizebytes from theGstByteWriterfrom the beginning.Free-function: gst_byte_writer_free
- Parameters:
data- Memory area for writingsize- Size ofdatain bytesinitialized- Iftruethe complete data can be read from the beginning- Returns:
- a new
GstByteWriterinstance
-
newWithSize
Creates a newGstByteWriterinstance with the given initial data size.Free-function: gst_byte_writer_free
- Parameters:
size- Initial size of datafixed- Iftruethe data can't be reallocated- Returns:
- a new
GstByteWriterinstance
-
ensureFreeSpace
public boolean ensureFreeSpace(int size) 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- Returns:
trueif at leastsizebytes are still available
-
fill
public boolean fill(byte value, int size) Writessizebytes containingvaluetowriter.- Parameters:
value- Value to be writtensize- Number of bytes to be written- Returns:
trueif the value could be written
-
free
public void free()Frees this ByteWriter and all memory allocated by it. -
freeAndGetBuffer
Frees this ByteWriter and all memory allocated by it except the current data, which is returned asGstBuffer.Free-function: gst_buffer_unref
- Returns:
- the current data as buffer. gst_buffer_unref() after usage.
-
freeAndGetData
Frees this ByteWriter and all memory allocated by it except the current data, which is returned.Free-function: g_free
- Returns:
- the current data. g_free() after usage.
-
getRemaining
public int getRemaining()Returns the remaining size of data that can still be written. If -1 is returned the remaining size is only limited by system resources.- Returns:
- the remaining size of data that can still be written
-
init
public void init()Initializes this ByteWriter to an empty instance -
initWithData
public void initWithData(@org.jspecify.annotations.Nullable byte @Nullable [] data, boolean initialized) Initializes this ByteWriter with the given memory area. Ifinitializedistrueit is possible to readsizebytes from theGstByteWriterfrom the beginning.- Parameters:
data- Memory area for writinginitialized- Iftruethe complete data can be read from the beginning
-
initWithSize
public void initWithSize(int size, boolean fixed) Initializes this ByteWriter with the given initial data size.- Parameters:
size- Initial size of datafixed- Iftruethe data can't be reallocated
-
putBuffer
Writessizebytes ofdatatowriter.- Parameters:
buffer- sourceGstBufferoffset- offset to copy fromsize- total size to copy. If -1, all data is copied- Returns:
trueif the data could be written
-
putData
public boolean putData(@org.jspecify.annotations.Nullable byte @Nullable [] data) Writessizebytes ofdatatowriter.- Parameters:
data- Data to write- Returns:
trueif the value could be written
-
putFloat32Be
public boolean putFloat32Be(float val) Writes a big endian 32 bit float towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putFloat32Le
public boolean putFloat32Le(float val) Writes a little endian 32 bit float towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putFloat64Be
public boolean putFloat64Be(double val) Writes a big endian 64 bit float towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putFloat64Le
public boolean putFloat64Le(double val) Writes a little endian 64 bit float towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt16Be
public boolean putInt16Be(short val) Writes a signed big endian 16 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt16Le
public boolean putInt16Le(short val) Writes a signed little endian 16 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt24Be
public boolean putInt24Be(int val) Writes a signed big endian 24 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt24Le
public boolean putInt24Le(int val) Writes a signed little endian 24 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt32Be
public boolean putInt32Be(int val) Writes a signed big endian 32 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt32Le
public boolean putInt32Le(int val) Writes a signed little endian 32 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt64Be
public boolean putInt64Be(long val) Writes a signed big endian 64 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt64Le
public boolean putInt64Le(long val) Writes a signed little endian 64 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putInt8
public boolean putInt8(byte val) Writes a signed 8 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putStringUtf16
public boolean putStringUtf16(@org.jspecify.annotations.Nullable short @Nullable [] data) Writes a NUL-terminated UTF16 string to this ByteWriter (including the terminator).- Parameters:
data- UTF16 string to write- Returns:
trueif the value could be written
-
putStringUtf32
public boolean putStringUtf32(@org.jspecify.annotations.Nullable int @Nullable [] data) Writes a NUL-terminated UTF32 string to this ByteWriter (including the terminator).- Parameters:
data- UTF32 string to write- Returns:
trueif the value could be written
-
putStringUtf8
Writes a NUL-terminated UTF8 string to this ByteWriter (including the terminator).- Parameters:
data- UTF8 string to write- Returns:
trueif the value could be written
-
putUint16Be
public boolean putUint16Be(short val) Writes a unsigned big endian 16 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint16Le
public boolean putUint16Le(short val) Writes a unsigned little endian 16 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint24Be
public boolean putUint24Be(int val) Writes a unsigned big endian 24 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint24Le
public boolean putUint24Le(int val) Writes a unsigned little endian 24 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint32Be
public boolean putUint32Be(int val) Writes a unsigned big endian 32 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint32Le
public boolean putUint32Le(int val) Writes a unsigned little endian 32 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint64Be
public boolean putUint64Be(long val) Writes a unsigned big endian 64 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint64Le
public boolean putUint64Le(long val) Writes a unsigned little endian 64 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
putUint8
public boolean putUint8(byte val) Writes a unsigned 8 bit integer towriter.- Parameters:
val- Value to write- Returns:
trueif the value could be written
-
reset
public void reset()Resets this ByteWriter and frees the data if it's owned bywriter. -
resetAndGetBuffer
Resets this ByteWriter and returns the current data as buffer.Free-function: gst_buffer_unref
- Returns:
- the current data as buffer. gst_buffer_unref() after usage.
-
resetAndGetData
public byte[] resetAndGetData()Resets this ByteWriter and returns the current data.Free-function: g_free
- Returns:
- the current data. g_free() after usage.
-