public static class EncodedInteger.GenericCodec extends EncodedInteger.Codec
Constructor and Description |
---|
EncodedInteger.GenericCodec(int minValue,
int maxValue,
int width,
boolean bigEndian,
boolean signed) |
Modifier and Type | Method and Description |
---|---|
int |
decode(byte[] data,
int start,
int len)
Decode a value from some part of a bytearray
|
byte[] |
encode(int value)
Encode the given value to a new bytearray
|
void |
encodeTo(int value,
byte[] toArray,
int start)
Encode the given value to some location in an existing bytearray
|
void |
rangeCheck(int value)
Check if a given value is in the encodable range for this codec.
|
decode
public EncodedInteger.GenericCodec(int minValue, int maxValue, int width, boolean bigEndian, boolean signed)
minValue
- the minimum acceptable valuemaxValue
- the maximum acceptable valuewidth
- how many bytes to encode tobigEndian
- if true, encode MSB first; if false, encode LSB firstsigned
- if true, treat the most significant bit as a sign bit when decodingpublic byte[] encode(int value)
EncodedInteger.Codec
encode
in class EncodedInteger.Codec
value
- the valuepublic void encodeTo(int value, byte[] toArray, int start)
EncodedInteger.Codec
encodeTo
in class EncodedInteger.Codec
value
- the valuetoArray
- the array to populatestart
- the start index to begin encoding atpublic int decode(byte[] data, int start, int len)
EncodedInteger.Codec
decode
in class EncodedInteger.Codec
data
- the bytearraystart
- where to start decodinglen
- how many bytes to decodepublic void rangeCheck(int value) throws EncodeException
EncodedInteger.Codec
rangeCheck
in class EncodedInteger.Codec
value
- the value to checkEncodeException
- if value
is out of range