Package org.yamcs.utils
Class BitWriter
java.lang.Object
org.yamcs.utils.BitWriter
Wrapper around a ByteBuffer that allows to write individual bits or group of bits
All the writings/readings are performed to a temporary long which is stored into the backing ByteBuffer when it is "full"
Don't forget to call flush after the last write, such that the long is written to the backing ByteBuffer
-
Constructor Summary
ConstructorDescriptionBitWriter
(ByteBuffer bb) Constructs a BitWriter around an existing ByteBuffer -
Method Summary
Modifier and TypeMethodDescriptionvoid
flush()
flush the temporary long to the ByteBuffer do not call this method twice!!void
write
(int x, int numBits) write the least significant numBits of x into the BitBuffer Note that there is no check that the bits will actually fit into the ByteBuffer, they will be stored in the temporary field.
-
Constructor Details
-
BitWriter
Constructs a BitWriter around an existing ByteBuffer- Parameters:
bb
-
-
-
Method Details
-
write
public void write(int x, int numBits) write the least significant numBits of x into the BitBuffer Note that there is no check that the bits will actually fit into the ByteBuffer, they will be stored in the temporary field. A buffer overflow exception will happen when the temporary field is full and flushed to the buffer- Parameters:
x
-numBits
-
-
flush
public void flush()flush the temporary long to the ByteBuffer do not call this method twice!!
-