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
    Constructs a BitWriter around an existing ByteBuffer
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BitWriter

      public BitWriter(ByteBuffer bb)
      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!!