Package org.freedesktop.gstreamer.base
Class BitWriter
java.lang.Object
io.github.jwharm.javagi.base.ProxyInstance
org.freedesktop.gstreamer.base.BitWriter
- All Implemented Interfaces:
Proxy
GstBitWriter
provides a bit writer that can write any number of
bits into a memory buffer. It provides functions for writing any
number of bits into 8, 16, 32 and 64 bit variables.-
Constructor Summary
ConstructorDescriptionAllocate a new BitWriter.Allocate a new BitWriter.BitWriter
(MemorySegment address) Create a BitWriter proxy instance for the provided memory address.BitWriter
(MemorySegment data, int bitSize, int bitCapacity, boolean autoGrow, boolean owned) Allocate a new BitWriter with the fields set to the provided values.BitWriter
(MemorySegment data, int bitSize, int bitCapacity, boolean autoGrow, boolean owned, Arena arena) Allocate a new BitWriter with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionboolean
alignBytes
(byte trailingBit) Write trailing bit to align last byte ofdata
.void
free()
Frees this BitWriter and the allocated data inside.Frees this BitWriter without destroying the internal data, which is returned asGstBuffer
.byte[]
Frees this BitWriter without destroying the internal data, which is returned.byte[]
getData()
Get written data pointerstatic MemoryLayout
The memory layout of the native struct.int
int
getSize()
Get size of writtendata
void
init()
Initializes this BitWriter to an empty instance.void
initWithData
(byte[] data, boolean initialized) Initializes this BitWriter with the given memory areadata
.void
initWithSize
(int size, boolean fixed) Initializes aGstBitWriter
instance and allocates the given datasize
.static BitWriter
new_()
Creates a new, emptyGstBitWriter
instance.static BitWriter
newWithData
(byte[] data, boolean initialized) Creates a newGstBitWriter
instance with the given memory area.static BitWriter
newWithSize
(int size, boolean fixed) Creates aGstBitWriter
instance with the given initial data size.boolean
putBitsUint16
(short value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.boolean
putBitsUint32
(int value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.boolean
putBitsUint64
(long value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.boolean
putBitsUint8
(byte value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.boolean
putBytes
(byte[] data, int nbytes) Writenbytes
bytes ofdata
toGstBitWriter
.boolean
Read the value of the fieldauto_grow
.int
Read the value of the fieldbit_capacity
.int
Read the value of the fieldbit_size
.readData()
Read the value of the fielddata
.boolean
Read the value of the fieldowned
.void
reset()
Resets this BitWriter and frees the data if it's owned by this BitWriter.Resets this BitWriter and returns the current data asGstBuffer
.byte[]
Resets this BitWriter and returns the current data.boolean
setPos
(int pos) void
writeAutoGrow
(boolean autoGrow) Write a value in the fieldauto_grow
.void
writeBitCapacity
(int bitCapacity) Write a value in the fieldbit_capacity
.void
writeBitSize
(int bitSize) Write a value in the fieldbit_size
.void
writeData
(MemorySegment data) Write a value in the fielddata
.void
writeOwned
(boolean owned) Write a value in the fieldowned
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
BitWriter
Create a BitWriter proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
BitWriter
Allocate a new BitWriter.- Parameters:
arena
- to control the memory allocation scope
-
BitWriter
public BitWriter()Allocate a new BitWriter. The memory is allocated withArena.ofAuto()
. -
BitWriter
public BitWriter(MemorySegment data, int bitSize, int bitCapacity, boolean autoGrow, boolean owned, Arena arena) Allocate a new BitWriter with the fields set to the provided values.- Parameters:
data
- value for the fielddata
bitSize
- value for the fieldbitSize
bitCapacity
- value for the fieldbitCapacity
autoGrow
- value for the fieldautoGrow
owned
- value for the fieldowned
arena
- to control the memory allocation scope
-
BitWriter
Allocate a new BitWriter with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
data
- value for the fielddata
bitSize
- value for the fieldbitSize
bitCapacity
- value for the fieldbitCapacity
autoGrow
- value for the fieldautoGrow
owned
- value for the fieldowned
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
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
-
readBitSize
public int readBitSize()Read the value of the fieldbit_size
.- Returns:
- The value of the field
bit_size
-
writeBitSize
public void writeBitSize(int bitSize) Write a value in the fieldbit_size
.- Parameters:
bitSize
- The new value for the fieldbit_size
-
readBitCapacity
public int readBitCapacity()Read the value of the fieldbit_capacity
.- Returns:
- The value of the field
bit_capacity
-
writeBitCapacity
public void writeBitCapacity(int bitCapacity) Write a value in the fieldbit_capacity
.- Parameters:
bitCapacity
- The new value for the fieldbit_capacity
-
readAutoGrow
public boolean readAutoGrow()Read the value of the fieldauto_grow
.- Returns:
- The value of the field
auto_grow
-
writeAutoGrow
public void writeAutoGrow(boolean autoGrow) Write a value in the fieldauto_grow
.- Parameters:
autoGrow
- The new value for the fieldauto_grow
-
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, emptyGstBitWriter
instance.Free-function: gst_bit_writer_free
- Returns:
- a new, empty
GstByteWriter
instance
-
newWithData
Creates a newGstBitWriter
instance with the given memory area. Ifinitialized
istrue
it is possible to readsize
bits from theGstBitWriter
from the beginning.Free-function: gst_bit_writer_free
- Parameters:
data
- Memory area for writinginitialized
- iftrue
the complete data can be read from the beginning- Returns:
- a new
GstBitWriter
instance
-
newWithSize
Creates aGstBitWriter
instance with the given initial data size.Free-function: gst_bit_writer_free
- Parameters:
size
- Initial size of data in bytesfixed
- Iftrue
the data can't be reallocated- Returns:
- a new
GstBitWriter
instance
-
alignBytes
public boolean alignBytes(byte trailingBit) Write trailing bit to align last byte ofdata
.trailingBit
can only be 1 or 0.- Parameters:
trailingBit
- trailing bits of last byte, 0 or 1- Returns:
true
if successful,false
otherwise.
-
free
public void free()Frees this BitWriter and the allocated data inside. -
freeAndGetBuffer
Frees this BitWriter without destroying the internal data, which is returned asGstBuffer
.Free-function: gst_buffer_unref
- Returns:
- a new allocated
GstBuffer
wrapping the data inside. gst_buffer_unref() after usage.
-
freeAndGetData
public byte[] freeAndGetData()Frees this BitWriter without destroying the internal data, which is returned.Free-function: g_free
- Returns:
- the current data. g_free() after usage.
-
getData
public byte[] getData()Get written data pointer- Returns:
- data pointer
-
getRemaining
public int getRemaining() -
getSize
public int getSize()Get size of writtendata
- Returns:
- size of bits written in
data
-
init
public void init()Initializes this BitWriter to an empty instance. -
initWithData
public void initWithData(byte[] data, boolean initialized) Initializes this BitWriter with the given memory areadata
. IFinitialized
istrue
it is possible to readsize
bits from theGstBitWriter
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 aGstBitWriter
instance and allocates the given datasize
.- Parameters:
size
- the size on bytes to allocate for datafixed
- Iftrue
the data can't be reallocated
-
putBitsUint16
public boolean putBitsUint16(short value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.- Parameters:
value
- value ofguint16
to writenbits
- number of bits to write- Returns:
true
if successful,false
otherwise.
-
putBitsUint32
public boolean putBitsUint32(int value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.- Parameters:
value
- value ofguint32
to writenbits
- number of bits to write- Returns:
true
if successful,false
otherwise.
-
putBitsUint64
public boolean putBitsUint64(long value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.- Parameters:
value
- value ofguint64
to writenbits
- number of bits to write- Returns:
true
if successful,false
otherwise.
-
putBitsUint8
public boolean putBitsUint8(byte value, int nbits) Writenbits
bits ofvalue
toGstBitWriter
.- Parameters:
value
- value ofguint8
to writenbits
- number of bits to write- Returns:
true
if successful,false
otherwise.
-
putBytes
public boolean putBytes(byte[] data, int nbytes) Writenbytes
bytes ofdata
toGstBitWriter
.- Parameters:
data
- pointer of data to writenbytes
- number of bytes to write- Returns:
true
if successful,false
otherwise.
-
reset
public void reset()Resets this BitWriter and frees the data if it's owned by this BitWriter. -
resetAndGetBuffer
Resets this BitWriter and returns the current data asGstBuffer
.Free-function: gst_buffer_unref
- Returns:
- a new allocated
GstBuffer
wrapping the current data. gst_buffer_unref() after usage.
-
resetAndGetData
public byte[] resetAndGetData()Resets this BitWriter and returns the current data.Free-function: g_free
- Returns:
- the current data. g_free() after usage.
-
setPos
public boolean setPos(int pos)
-