Class LongPacker


  • public class LongPacker
    extends java.lang.Object
    This class is used to encode(decode) Long in Java with specified bit-width. User need to guarantee that the length of every given Long in binary mode is less than or equal to the bit-width.

    e.g., if bit-width is 31, then Long '2147483648'(2^31) is not allowed but '2147483647'(2^31-1) is allowed.

    • Constructor Summary

      Constructors 
      Constructor Description
      LongPacker​(int width)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void pack8Values​(long[] values, int offset, byte[] buf)
      Encode 8 (NUM_OF_LONGS) Longs from the array 'values' with specified bit-width to bytes.
      void setWidth​(int width)  
      void unpack8Values​(byte[] buf, int offset, long[] values)
      decode values from byte array.
      void unpackAllValues​(byte[] buf, int length, long[] values)
      decode all values from 'buf' with specified offset and length decoded result will be saved in array named 'values'.
      • Methods inherited from class java.lang.Object

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

      • LongPacker

        public LongPacker​(int width)
    • Method Detail

      • pack8Values

        public void pack8Values​(long[] values,
                                int offset,
                                byte[] buf)
        Encode 8 (NUM_OF_LONGS) Longs from the array 'values' with specified bit-width to bytes.
        Parameters:
        values - - array where '8 Longs' are in
        offset - - the offset of first Long to be encoded
        buf - - encoded bytes, buf size must be equal to (NUM_OF_LONGS} * IntPacker.width / 8)
      • unpack8Values

        public void unpack8Values​(byte[] buf,
                                  int offset,
                                  long[] values)
        decode values from byte array.
        Parameters:
        buf - - array where bytes are in.
        offset - - offset of first byte to be decoded in buf
        values - - decoded result , the size of values should be 8
      • unpackAllValues

        public void unpackAllValues​(byte[] buf,
                                    int length,
                                    long[] values)
        decode all values from 'buf' with specified offset and length decoded result will be saved in array named 'values'.
        Parameters:
        buf - array where all bytes are in.
        length - length of bytes to be decoded in buf.
        values - decoded result
      • setWidth

        public void setWidth​(int width)