Class IntPacker


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

    e.g., if bit-width is 4, then Integer '16'(10000)b is not allowed but '15'(1111)b is allowed.

    • Constructor Summary

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

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

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

      • IntPacker

        public IntPacker​(int width)
    • Method Detail

      • pack8Values

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

        public void unpack8Values​(byte[] buf,
                                  int offset,
                                  int[] values)
        decode Integers from byte array.
        Parameters:
        buf - - array where bytes are in.
        offset - - offset of first byte to be decoded in buf
        values - - decoded result , the length of 'values' should be @{link IntPacker#NUM_OF_INTS}
      • unpackAllValues

        public void unpackAllValues​(byte[] buf,
                                    int length,
                                    int[] values)
        decode all values from 'buf' with specified offset and length decoded result will be saved in the 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)