frysk.value
Class Packing

java.lang.Object
  extended by frysk.value.Packing

 class Packing
extends Object

Utility methods for packing and unpacking BigInteger bit-fields from a big-endian byte[] buffer.


Field Summary
private  BigInteger mask
           
private  int shift
           
private  int signBit
           
 
Constructor Summary
Packing(int size, int bitOffset, int bitLength)
          Create a packing object.
 
Method Summary
(package private)  byte[] pack(byte[] buffer, BigInteger value)
          Pack VALUE into the byte buffer.
 String toString()
           
(package private)  BigInteger unpackSigned(byte[] buffer)
          Unpack the value as a signed.
(package private)  BigInteger unpackUnsigned(byte[] buffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

signBit

private final int signBit

shift

private final int shift

mask

private final BigInteger mask
Constructor Detail

Packing

Packing(int size,
        int bitOffset,
        int bitLength)
Create a packing object. SIZE is the byte size of the value containing the bit field. BIT_SIZE is the number of bits in the packed field. BIT_OFFSET is the number bits to the right of the packed field

Method Detail

toString

public String toString()
Overrides:
toString in class Object

pack

byte[] pack(byte[] buffer,
            BigInteger value)
Pack VALUE into the byte buffer. Note that the returned byte[] buffer may differ in length from the original: leading zeros will be stripped (e.g., byte[]{000,0x01} becomes byte[]{0x01}); and any leading large unsigned byte will be prefixed with a zero (e.g., byte[]{0xff} becomes byte[]{0x00,0xff}). The client may need to truncate or zero extend as necessary. Since the receiving method Location.put(ByteOrder,byte[],int) (with zero fill) used to store the packed result handles all this correctly, this is not normally a problem.


unpackSigned

BigInteger unpackSigned(byte[] buffer)
Unpack the value as a signed.


unpackUnsigned

BigInteger unpackUnsigned(byte[] buffer)