Package org.freedesktop.gstreamer.base
Class ByteWriter
java.lang.Object
io.github.jwharm.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
ConstructorDescriptionAllocate 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 TypeMethodDescriptionboolean
ensureFreeSpace
(int size) Checks if enough free space from the current write cursor is available and reallocates if necessary.boolean
fill
(byte value, int size) Writessize
bytes containingvalue
to this ByteWriter.void
free()
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 MemoryLayout
The memory layout of the native struct.int
Returns the remaining size of data that can still be written.void
init()
Initializes this ByteWriter to an empty instancevoid
initWithData
(byte[] data, boolean initialized) Initializes this ByteWriter with the given memory area.void
initWithSize
(int size, boolean fixed) Initializes this ByteWriter with the given initial data size.static ByteWriter
new_()
Creates a new, emptyGstByteWriter
instancestatic ByteWriter
newWithData
(MemorySegment data, int size, boolean initialized) Creates a newGstByteWriter
instance with the given memory area.static ByteWriter
newWithSize
(int size, boolean fixed) Creates a newGstByteWriter
instance with the given initial data size.boolean
Writessize
bytes ofdata
to this ByteWriter.boolean
putData
(byte[] data) Writessize
bytes ofdata
to this ByteWriter.boolean
putFloat32Be
(float val) Writes a big endian 32 bit float to this ByteWriter.boolean
putFloat32Le
(float val) Writes a little endian 32 bit float to this ByteWriter.boolean
putFloat64Be
(double val) Writes a big endian 64 bit float to this ByteWriter.boolean
putFloat64Le
(double val) Writes a little endian 64 bit float to this ByteWriter.boolean
putInt16Be
(short val) Writes a signed big endian 16 bit integer to this ByteWriter.boolean
putInt16Le
(short val) Writes a signed little endian 16 bit integer to this ByteWriter.boolean
putInt24Be
(int val) Writes a signed big endian 24 bit integer to this ByteWriter.boolean
putInt24Le
(int val) Writes a signed little endian 24 bit integer to this ByteWriter.boolean
putInt32Be
(int val) Writes a signed big endian 32 bit integer to this ByteWriter.boolean
putInt32Le
(int val) Writes a signed little endian 32 bit integer to this ByteWriter.boolean
putInt64Be
(long val) Writes a signed big endian 64 bit integer to this ByteWriter.boolean
putInt64Le
(long val) Writes a signed little endian 64 bit integer to this ByteWriter.boolean
putInt8
(byte val) Writes a signed 8 bit integer to this ByteWriter.boolean
putStringUtf16
(short[] data) Writes a NUL-terminated UTF16 string to this ByteWriter (including the terminator).boolean
putStringUtf32
(int[] data) Writes a NUL-terminated UTF32 string to this ByteWriter (including the terminator).boolean
putStringUtf8
(String data) Writes a NUL-terminated UTF8 string to this ByteWriter (including the terminator).boolean
putUint16Be
(short val) Writes a unsigned big endian 16 bit integer to this ByteWriter.boolean
putUint16Le
(short val) Writes a unsigned little endian 16 bit integer to this ByteWriter.boolean
putUint24Be
(int val) Writes a unsigned big endian 24 bit integer to this ByteWriter.boolean
putUint24Le
(int val) Writes a unsigned little endian 24 bit integer to this ByteWriter.boolean
putUint32Be
(int val) Writes a unsigned big endian 32 bit integer to this ByteWriter.boolean
putUint32Le
(int val) Writes a unsigned little endian 32 bit integer to this ByteWriter.boolean
putUint64Be
(long val) Writes a unsigned big endian 64 bit integer to this ByteWriter.boolean
putUint64Le
(long val) Writes a unsigned little endian 64 bit integer to this ByteWriter.boolean
putUint8
(byte val) Writes a unsigned 8 bit integer to this ByteWriter.int
Read the value of the fieldalloc_size
.boolean
Read the value of the fieldfixed
.boolean
Read the value of the fieldowned
.Read the value of the fieldparent
.void
reset()
Resets this ByteWriter and frees the data if it's owned by this ByteWriter.Resets this ByteWriter and returns the current data as buffer.byte[]
Resets this ByteWriter and returns the current data.void
writeAllocSize
(int allocSize) Write a value in the fieldalloc_size
.void
writeFixed
(boolean fixed) Write a value in the fieldfixed
.void
writeOwned
(boolean owned) Write a value in the fieldowned
.void
writeParent
(ByteReader parent) Write a value in the fieldparent
.Methods inherited from class io.github.jwharm.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 fieldparent
allocSize
- value for the fieldallocSize
fixed
- value for the fieldfixed
owned
- value for the fieldowned
arena
- 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 fieldparent
allocSize
- value for the fieldallocSize
fixed
- value for the fieldfixed
owned
- 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, emptyGstByteWriter
instanceFree-function: gst_byte_writer_free
- Returns:
- a new, empty
GstByteWriter
instance
-
newWithData
Creates a newGstByteWriter
instance with the given memory area. Ifinitialized
istrue
it is possible to readsize
bytes from theGstByteWriter
from the beginning.Free-function: gst_byte_writer_free
- Parameters:
data
- Memory area for writingsize
- Size ofdata
in bytesinitialized
- Iftrue
the complete data can be read from the beginning- Returns:
- a new
GstByteWriter
instance
-
newWithSize
Creates a newGstByteWriter
instance with the given initial data size.Free-function: gst_byte_writer_free
- Parameters:
size
- Initial size of datafixed
- Iftrue
the data can't be reallocated- Returns:
- a new
GstByteWriter
instance
-
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:
true
if at leastsize
bytes are still available
-
fill
public boolean fill(byte value, int size) Writessize
bytes containingvalue
to this ByteWriter.- Parameters:
value
- Value to be writtensize
- Number of bytes to be written- Returns:
true
if 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(byte[] data, boolean initialized) Initializes this ByteWriter with the given memory area. Ifinitialized
istrue
it is possible to readsize
bytes from theGstByteWriter
from the beginning.- Parameters:
data
- Memory area for writinginitialized
- Iftrue
the 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
- Iftrue
the data can't be reallocated
-
putBuffer
Writessize
bytes ofdata
to this ByteWriter.- Parameters:
buffer
- sourceGstBuffer
offset
- offset to copy fromsize
- total size to copy. If -1, all data is copied- Returns:
true
if the data could be written
-
putData
public boolean putData(byte[] data) Writessize
bytes ofdata
to this ByteWriter.- Parameters:
data
- Data to write- Returns:
true
if the value could be written
-
putFloat32Be
public boolean putFloat32Be(float val) Writes a big endian 32 bit float to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putFloat32Le
public boolean putFloat32Le(float val) Writes a little endian 32 bit float to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putFloat64Be
public boolean putFloat64Be(double val) Writes a big endian 64 bit float to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putFloat64Le
public boolean putFloat64Le(double val) Writes a little endian 64 bit float to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt16Be
public boolean putInt16Be(short val) Writes a signed big endian 16 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt16Le
public boolean putInt16Le(short val) Writes a signed little endian 16 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt24Be
public boolean putInt24Be(int val) Writes a signed big endian 24 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt24Le
public boolean putInt24Le(int val) Writes a signed little endian 24 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt32Be
public boolean putInt32Be(int val) Writes a signed big endian 32 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt32Le
public boolean putInt32Le(int val) Writes a signed little endian 32 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt64Be
public boolean putInt64Be(long val) Writes a signed big endian 64 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt64Le
public boolean putInt64Le(long val) Writes a signed little endian 64 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putInt8
public boolean putInt8(byte val) Writes a signed 8 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putStringUtf16
public boolean putStringUtf16(short[] data) Writes a NUL-terminated UTF16 string to this ByteWriter (including the terminator).- Parameters:
data
- UTF16 string to write- Returns:
true
if the value could be written
-
putStringUtf32
public boolean putStringUtf32(int[] data) Writes a NUL-terminated UTF32 string to this ByteWriter (including the terminator).- Parameters:
data
- UTF32 string to write- Returns:
true
if 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:
true
if the value could be written
-
putUint16Be
public boolean putUint16Be(short val) Writes a unsigned big endian 16 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint16Le
public boolean putUint16Le(short val) Writes a unsigned little endian 16 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint24Be
public boolean putUint24Be(int val) Writes a unsigned big endian 24 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint24Le
public boolean putUint24Le(int val) Writes a unsigned little endian 24 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint32Be
public boolean putUint32Be(int val) Writes a unsigned big endian 32 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint32Le
public boolean putUint32Le(int val) Writes a unsigned little endian 32 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint64Be
public boolean putUint64Be(long val) Writes a unsigned big endian 64 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint64Le
public boolean putUint64Le(long val) Writes a unsigned little endian 64 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
putUint8
public boolean putUint8(byte val) Writes a unsigned 8 bit integer to this ByteWriter.- Parameters:
val
- Value to write- Returns:
true
if the value could be written
-
reset
public void reset()Resets this ByteWriter and frees the data if it's owned by this ByteWriter. -
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.
-