public abstract class BitBufferHelper extends Object
Modifier and Type | Field and Description |
---|---|
static long |
BYTE_MASK |
Constructor and Description |
---|
BitBufferHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
checkExceptions(byte[] data,
int startOffset,
int numBits)
Checks for overflow and underflow exceptions.
|
static byte[] |
getBits(byte[] data,
int startOffset,
int numBits)
Reads the specified number of bits from the passed byte array starting to
read from the specified offset The bits read are stored in a byte array
which size is dictated by the number of bits to be stored.
|
static byte |
getByte(byte[] data)
Returns the first byte from the byte array.
|
static int |
getInt(byte[] data)
Returns the int value for the byte array passed.
|
static int |
getInt(byte[] data,
int numBits)
Returns the int value for the last numBits of the byte array passed.
|
static long |
getLong(byte[] data)
Returns the long value for the byte array passed.
|
static long |
getLong(byte[] data,
int numBits)
Returns the long value for the last numBits of the byte array passed.
|
static int |
getLSBMask(int numBits)
Returns numBits 1's in the LSB position.
|
static int |
getMSBMask(int numBits)
Returns numBits 1's in the MSB position.
|
static short |
getShort(byte[] data)
Returns the short value for the byte array passed.
|
static short |
getShort(byte[] data,
int numBits)
Returns the short value for the last numBits of the byte array passed.
|
static void |
setBytes(byte[] data,
byte[] input,
int startOffset,
int numBits)
Deprecated.
Use
copyBitsFromLsb(byte[], byte[], int, int) instead. |
static byte[] |
shiftBitsToLSB(byte[] inputBytes,
int numBits)
It aligns the first numBits bits to the right end of the byte array
preceding them with numBits % 8 zero bits.
|
static byte[] |
shiftBitsToMSB(byte[] inputBytes,
int numBits)
Takes an LSB aligned byte array and returned the LSB numBits in a MSB
aligned byte array.
|
static byte[] |
toByteArray(Number input)
Accepts a number as input and returns its value in byte form in LSB
aligned form example: input = 5000 [1001110001000] bytes = 19, -120
[00010011] [10001000].
|
static byte[] |
toByteArray(Number input,
int numBits)
Accepts a number as input and returns its value in byte form in MSB
aligned form example: input = 5000 [1001110001000] bytes = -114, 64
[10011100] [01000000].
|
static long |
toNumber(byte[] array)
Returns the numerical value of the byte array passed.
|
static long |
toNumber(byte[] array,
int numBits)
Returns the numerical value of the last numBits (LSB bits) of the byte array passed.
|
public static final long BYTE_MASK
public static byte getByte(byte[] data)
public static short getShort(byte[] data)
public static short getShort(byte[] data, int numBits)
public static int getInt(byte[] data)
public static int getInt(byte[] data, int numBits)
public static long getLong(byte[] data)
public static long getLong(byte[] data, int numBits)
@Nonnull public static byte[] getBits(byte[] data, int startOffset, int numBits) throws BufferException
Ex. Read 7 bits at offset 10 0 9 10 16 17 0101000010 | 0000101 | 1111001010010101011 will be returned as {0,0,0,0,0,1,0,1}
startOffset
- - offset to start fetching bits from data fromnumBits
- - number of bits to be fetched from dataBufferException
- when the startOffset and numBits parameters are not congruent
with the data buffer size@Deprecated public static void setBytes(byte[] data, byte[] input, int startOffset, int numBits) throws BufferException
copyBitsFromLsb(byte[], byte[], int, int)
instead.data
- to set the input byteinput
- bytes to be insertedstartOffset
- offset of data[] to start inserting byte fromnumBits
- number of bits of input to be inserted into data[]BufferException
- when the startOffset and numBits parameters are not congruent
with data and input buffers' sizepublic static int getMSBMask(int numBits)
public static int getLSBMask(int numBits)
public static long toNumber(byte[] array)
public static long toNumber(byte[] array, int numBits)
public static byte[] toByteArray(Number input)
public static byte[] toByteArray(Number input, int numBits)
numBits
- - the number of bits to be returnedpublic static byte[] shiftBitsToMSB(byte[] inputBytes, int numBits)
It aligns the last numBits bits to the head of the byte array following them with numBits % 8 zero bits.
Example: For inputbytes = [00000111][01110001] and numBits = 12 it returns: shiftedBytes = [01110111][00010000]
numBits
- - number of bits to be left alignedpublic static byte[] shiftBitsToLSB(byte[] inputBytes, int numBits)
Example: For inputbytes = [01110111][00010000] and numBits = 12 it returns: shiftedBytes = [00000111][01110001]
inputBytes
- input bytesnumBits
- - number of bits to be right alignedpublic static void checkExceptions(byte[] data, int startOffset, int numBits) throws BufferException
BufferException
- when the startOffset and numBits parameters are not congruent
with the data buffer's sizeCopyright © 2020 OpenDaylight. All rights reserved.