Package org.yamcs.utils
Class BitWriter
- java.lang.Object
-
- org.yamcs.utils.BitWriter
-
public class BitWriter extends Object
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
Constructors Constructor Description BitWriter(ByteBuffer bb)
Constructs a BitWriter around an existing ByteBuffer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 Detail
-
BitWriter
public BitWriter(ByteBuffer bb)
Constructs a BitWriter around an existing ByteBuffer- Parameters:
bb
-
-
-
Method Detail
-
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!!
-
-