public abstract class IntegerCodec extends Object
Modifier and Type | Field and Description |
---|---|
static IntegerCodec |
S16BE
A signed 16-bit integer encoded in 2 bytes, MSB-first
|
static IntegerCodec |
S16BEIE |
static IntegerCodec |
S16LE
A signed 16-bit integer encoded in 2 bytes, LSB-first
|
static IntegerCodec |
S16LEIE |
static IntegerCodec |
S24BE
A signed 24-bit integer encoded in 3 bytes, MSB-first
|
static IntegerCodec |
S24BEIE |
static IntegerCodec |
S24LE
A signed 24-bit integer encoded in 3 bytes, LSB-first
|
static IntegerCodec |
S24LEIE |
static IntegerCodec |
S32BE
A signed 32-bit integer encoded in 4 bytes, MSB-first
|
static IntegerCodec |
S32BEIE |
static IntegerCodec |
S32LE
A signed 32-bit integer encoded in 4 bytes, LSB-first
|
static IntegerCodec |
S32LEIE |
static IntegerCodec |
S8
A signed 8-bit integer encoded in 1 byte
|
static IntegerCodec |
S8IE |
static IntegerCodec |
SVARBE
A variable-length signed LSB-first integer
|
static IntegerCodec |
SVARBEIE |
static IntegerCodec |
SVARLE
A variable-length signed MSB-first integer
|
static IntegerCodec |
SVARLEIE |
static IntegerCodec |
U16BE
An unsigned 16-bit integer encoded in 2 bytes, MSB-first
|
static IntegerCodec |
U16BEIE
An unsigned 16-bit integer encoded in 2 bytes, MSB-first, ignore extra octets
|
static IntegerCodec |
U16LE
An unsigned 16-bit integer encoded in 2 bytes, LSB-first
|
static IntegerCodec |
U16LEIE |
static IntegerCodec |
U24BE
An unsigned 24-bit integer encoded in 3 bytes, MSB-first
|
static IntegerCodec |
U24BEIE |
static IntegerCodec |
U24LE
An unsigned 24-bit integer encoded in 3 bytes, LSB-first
|
static IntegerCodec |
U24LEIE |
static IntegerCodec |
U8
An unsigned 8-bit integer encoded in 1 byte
|
static IntegerCodec |
U8IE
An unsigned 8-bit integer encoded in 1 byte, ignore extra octets
|
static IntegerCodec |
UVARBE
A variable-length unsigned LSB-first integer
|
static IntegerCodec |
UVARBEIE |
static IntegerCodec |
UVARLE
A variable-length unsigned MSB-first integer
|
static IntegerCodec |
UVARLEIE |
Modifier | Constructor and Description |
---|---|
protected |
IntegerCodec(int min,
int max) |
Modifier and Type | Method and Description |
---|---|
int |
decode(byte[] data)
Decode the given bytearray to an integer value.
|
abstract int |
decode(byte[] data,
int start,
int len)
Decode a value from some part of a bytearray
|
abstract byte[] |
encode(int value)
Encode the given value to a new bytearray
|
abstract int |
encodeTo(int value,
byte[] toArray,
int start,
int len)
Encode the given value to some location in an existing bytearray
|
static IntegerCodec |
getCodec(int min,
int max,
int width,
boolean bigEndian,
boolean signed,
boolean ignoreExtraOctets)
Return a IntegerCodec instance for the given parameters.
|
void |
rangeCheck(int value)
Check if a given value is in the encodable range for this codec.
|
public static final IntegerCodec U8
public static final IntegerCodec U8IE
public static final IntegerCodec U16BE
public static final IntegerCodec U16BEIE
public static final IntegerCodec U16LE
public static final IntegerCodec U16LEIE
public static final IntegerCodec U24BE
public static final IntegerCodec U24BEIE
public static final IntegerCodec U24LE
public static final IntegerCodec U24LEIE
public static final IntegerCodec S8
public static final IntegerCodec S8IE
public static final IntegerCodec S16BE
public static final IntegerCodec S16BEIE
public static final IntegerCodec S16LE
public static final IntegerCodec S16LEIE
public static final IntegerCodec S24BE
public static final IntegerCodec S24BEIE
public static final IntegerCodec S24LE
public static final IntegerCodec S24LEIE
public static final IntegerCodec S32BE
public static final IntegerCodec S32BEIE
public static final IntegerCodec S32LE
public static final IntegerCodec S32LEIE
public static final IntegerCodec UVARLE
public static final IntegerCodec UVARLEIE
public static final IntegerCodec UVARBE
public static final IntegerCodec UVARBEIE
public static final IntegerCodec SVARLE
public static final IntegerCodec SVARLEIE
public static final IntegerCodec SVARBE
public static final IntegerCodec SVARBEIE
public int decode(byte[] data)
data
- the bytearraypublic abstract byte[] encode(int value)
value
- the valuepublic abstract int encodeTo(int value, byte[] toArray, int start, int len)
value
- the valuetoArray
- the array to populatestart
- the start index to begin encoding atlen
- the maximum number of bytes to encode topublic abstract int decode(byte[] data, int start, int len)
data
- the bytearraystart
- where to start decodinglen
- how many bytes to decodepublic void rangeCheck(int value) throws EncodeException
value
- the value to checkEncodeException
- if value
is out of rangepublic static IntegerCodec getCodec(int min, int max, int width, boolean bigEndian, boolean signed, boolean ignoreExtraOctets)
min
- the minimum value to encodemax
- the maximum value to encodewidth
- the number of bytes to encode, or 0 to use a variable number of bytesbigEndian
- if true, encode MSB-first; if false, encode LSB-firstsigned
- if true, treat the most significant bit as a sign bit; if false, treat the value as unsignedIllegalArgumentException
- if min < max, or if min < 0 and !signed, or if width < 0