- All Known Implementing Classes:
DefaultDatatypeCoder,EncodingSpecificDatatypeCoder
- Since:
- 3
- Author:
- Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionCreates a reader wrapping an input stream.createWriter(OutputStream out) Creates a writer wrapping an input stream.booleandecodeBoolean(byte[] buf) Decode a boolean frombuffrom the first byte.decodeDecimal128(byte[] buf) Decodes a decimal128 from a byte array of 16 bytes.decodeDecimal64(byte[] buf) Decodes a decimal64 from a byte array of 8 bytes.doubledecodeDouble(byte[] buf) Decode a double value frombuffrom the first 8 bytes.floatdecodeFloat(byte[] buf) Decode a float value frombuffrom the first 4 bytes.intdecodeInt(byte[] buf) Decode an int value frombuffrom the first 4 bytes.intdecodeInt(byte[] buf, int off) Decode an int value frombufstarting at offsetofffor 4 bytes.decodeInt128(byte[] buf) Decodes a BigInteger from a byte array of 16 bytes (int128 format).decodeLocalDate(byte[] buf) Decodejava.time.LocalDatefrombuffrom the first 4 bytes.decodeLocalDate(byte[] buf, int off) Decodejava.time.LocalDatefrombuffrom the 4 bytes starting atoff.decodeLocalDateTime(byte[] buf) Decodejava.time.LocalDateTimefrombuffrom the first 8 bytes.decodeLocalDateTime(byte[] buf, int off) Decodejava.time.LocalDateTimefrombuffrom the 8 bytes starting atoff.decodeLocalTime(byte[] buf) Decodejava.time.LocalTimefrombuffrom the first 4 bytes.decodeLocalTime(byte[] buf, int off) Decodejava.time.LocalTimefrombuffrom the 4 bytes starting atoff.longdecodeLong(byte[] buf) Decode a long value frombuffrom the first 8 bytes.shortdecodeShort(byte[] buf) Decode a short value frombuffrom the firstsizeOfShort()bytes.shortdecodeShort(byte[] buf, int off) decodeString(byte[] buf) Decode aStringfrombufusing the encoding of this datatype coder.byte[]encodeBoolean(boolean val) Encodes boolean as a byte array of 1 byte.byte[]Encodes a decimal128 as a byte array of 16 bytes.byte[]encodeDecimal64(Decimal64 val) Encodes a decimal64 as a byte array of 8 bytes.byte[]encodeDouble(double val) Encode a double value as a byte array of 8 bytes.byte[]encodeFloat(float val) Encode a float value as a byte array of 4 bytes.byte[]encodeInt(int val) Encode an int value as a byte array of 4 bytes.voidencodeInt(int val, byte[] buf, int off) Encode an int value intobufstarting at indexofffor 4 bytes.byte[]encodeInt128(BigInteger val) Encodes a BigInteger as a byte array of 16 bytes (int128 format).byte[]encodeLocalDate(LocalDate val) Encode ajava.time.LocalDateas a byte array of 4 bytes.voidencodeLocalDate(LocalDate val, byte[] buf, int off) Encode ajava.time.LocalDateto a byte array, requiring 4 bytes.byte[]Encode ajava.time.LocalDateTimeas a byte array of 8 bytes.voidencodeLocalDateTime(LocalDateTime val, byte[] buf, int off) Encode ajava.time.LocalDateTimeto a byte array, requiring 8 bytes.byte[]encodeLocalTime(LocalTime val) Encode ajava.time.LocalTimeas a byte array of 4 bytes.voidencodeLocalTime(LocalTime val, byte[] buf, int off) Encode ajava.time.LocalTimeto a byte array, requiring 4 bytes.byte[]encodeLong(long val) Encode a long value as a byte array of 8 bytes.byte[]encodeShort(int val) Encode a short value as a byte array of lengthsizeOfShort().voidencodeShort(int val, byte[] buf, int off) byte[]encodeShort(short val) Encode a short value as a byte array of lengthsizeOfShort().byte[]encodeString(String val) Encode aStringvalue as a byte array using the encoding of this datatype coder.booleanforEncodingDefinition(EncodingDefinition encodingDefinition) Return a derived datatype coder that applies the supplied encoding definition for string conversions.inthashCode()intThe size of an encoded short in this data type coder.unwrap()Unwrap this datatype coder to its parent (or itself).
-
Field Details
-
NANOSECONDS_PER_FRACTION
static final int NANOSECONDS_PER_FRACTION- See Also:
-
FRACTIONS_PER_MILLISECOND
static final int FRACTIONS_PER_MILLISECOND- See Also:
-
FRACTIONS_PER_SECOND
static final int FRACTIONS_PER_SECOND- See Also:
-
FRACTIONS_PER_MINUTE
static final int FRACTIONS_PER_MINUTE- See Also:
-
FRACTIONS_PER_HOUR
static final int FRACTIONS_PER_HOUR- See Also:
-
-
Method Details
-
sizeOfShort
int sizeOfShort()The size of an encoded short in this data type coder.- Returns:
- size of an encoded short (either
2or4bytes) - Since:
- 4
-
encodeShort
byte[] encodeShort(short val) Encode a short value as a byte array of lengthsizeOfShort().- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array
-
encodeShort
byte[] encodeShort(int val) Encode a short value as a byte array of lengthsizeOfShort().- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array
-
encodeShort
void encodeShort(int val, byte[] buf, int off) Encode a short value intobufstarting at offsetoffforsizeOfShort()bytes.NOTE: Implementations using 4 bytes to encode a short may choose to encode
val(an int) as-is (which means the most significant two bytes can have a value other than 0x0000 or 0xFFFF, and a value of 0xFFFF (65_535) may be encoded as 0x0000_FFFF, and not as 0xFFFF_FFFF (-1). This behaviour may change at any time. For consistent behaviour, explicitly cast to short when calling this method.- Parameters:
val- value to be encodedbuf- byte array of sufficient size (warning: this is datatype coder specific, seesizeOfShort()), nevernulloff- offset to start encoding- Since:
- 4
-
decodeShort
short decodeShort(byte[] buf) Decode a short value frombuffrom the firstsizeOfShort()bytes.- Parameters:
buf- byte array of sufficient size (warning: this is datatype coder specific, seesizeOfShort())- Returns:
- short value from
buf, or0whenbufisnull
-
decodeShort
short decodeShort(byte[] buf, int off) - Parameters:
buf- byte array of sufficient size (warning: this is datatype coder specific, seesizeOfShort()), nevernulloff- offset to start decoding- Returns:
- short value from
buf - Since:
- 4
-
encodeInt
byte[] encodeInt(int val) Encode an int value as a byte array of 4 bytes.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array, or0whenbufisnull
-
encodeInt
void encodeInt(int val, byte[] buf, int off) Encode an int value intobufstarting at indexofffor 4 bytes.- Parameters:
val- value to be encodedbuf- byte array of sufficient size, nevernulloff- offset to start encoding- Since:
- 4
-
decodeInt
int decodeInt(byte[] buf) Decode an int value frombuffrom the first 4 bytes.- Parameters:
buf- byte array of sufficient size- Returns:
- int value decoded from
buf, or0whenbufisnull
-
decodeInt
int decodeInt(byte[] buf, int off) Decode an int value frombufstarting at offsetofffor 4 bytes.- Parameters:
buf- byte array of sufficient size, nevernulloff- offset to start decoding- Returns:
- int value decoded from
buf - Since:
- 4
-
encodeLong
byte[] encodeLong(long val) Encode a long value as a byte array of 8 bytes.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array
-
decodeLong
long decodeLong(byte[] buf) Decode a long value frombuffrom the first 8 bytes.- Parameters:
buf- byte array of sufficient size, or0whenbufisnull- Returns:
- long value decoded from
buf
-
encodeFloat
byte[] encodeFloat(float val) Encode a float value as a byte array of 4 bytes.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array
-
decodeFloat
float decodeFloat(byte[] buf) Decode a float value frombuffrom the first 4 bytes.- Parameters:
buf- byte array of sufficient size, or0whenbufisnull- Returns:
- float value decoded from
buf
-
encodeDouble
byte[] encodeDouble(double val) Encode a double value as a byte array of 8 bytes.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array
-
decodeDouble
double decodeDouble(byte[] buf) Decode a double value frombuffrom the first 8 bytes.- Parameters:
buf- byte array of sufficient size, or0whenbufisnull- Returns:
- double value decoded from
buf
-
encodeString
Encode aStringvalue as a byte array using the encoding of this datatype coder.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array, ornullifvalisnull- Since:
- 4
-
createWriter
Creates a writer wrapping an input stream.- Parameters:
out- output stream- Returns:
- writer applying the encoding of this datatype when writing
- Since:
- 4
-
decodeString
Decode aStringfrombufusing the encoding of this datatype coder.- Parameters:
buf- byte array to be decoded- Returns:
Stringdecoded frombuf, ornullifbufisnull- Since:
- 4
-
createReader
Creates a reader wrapping an input stream.- Parameters:
in- input stream- Returns:
- reader applying the encoding of this datatype coder when reading
- Since:
- 4
-
decodeBoolean
boolean decodeBoolean(byte[] buf) Decode a boolean frombuffrom the first byte.- Parameters:
buf- (expected) 1 bytes- Returns:
falsewhen 0,truefor all other values, orfalseifbufisnull
-
encodeBoolean
byte[] encodeBoolean(boolean val) Encodes boolean as a byte array of 1 byte.- Parameters:
val- value to encode- Returns:
trueas 1,falseas 0.
-
decodeLocalTime
Decodejava.time.LocalTimefrombuffrom the first 4 bytes.- Parameters:
buf- (expected) at least 4 bytes- Returns:
LocalTimedecoded frombuf, ornullifbufisnull- Since:
- 5
-
decodeLocalTime
Decodejava.time.LocalTimefrombuffrom the 4 bytes starting atoff.- Parameters:
buf- (expected) at least 4 bytes fromoff, nevernulloff- offset of the time value inbuf- Returns:
LocalTimedecoded frombuf- Since:
- 6
-
encodeLocalTime
Encode ajava.time.LocalTimeas a byte array of 4 bytes.- Parameters:
val- value to encode- Returns:
valencoded as a byte array, ornullifvalisnull- Since:
- 5
-
encodeLocalTime
Encode ajava.time.LocalTimeto a byte array, requiring 4 bytes.- Parameters:
val- value to encodebuf- byte array with at least 4 bytes starting atoff, nevernulloff- offset of the time value inbuf- Since:
- 6
-
decodeLocalDate
Decodejava.time.LocalDatefrombuffrom the first 4 bytes.- Parameters:
buf- (expected) at least 4 bytes- Returns:
LocalDatedecoded frombuf, ornullifbufisnull- Since:
- 5
-
decodeLocalDate
Decodejava.time.LocalDatefrombuffrom the 4 bytes starting atoff.- Parameters:
buf- (expected) at least 4 bytes fromoff, nevernulloff- offset of the time value inbuf- Returns:
LocalDatedecoded frombuf- Since:
- 6
-
encodeLocalDate
Encode ajava.time.LocalDateas a byte array of 4 bytes.- Parameters:
val- value to encode- Returns:
valencoded as a byte array, ornullifvalisnull- Since:
- 5
-
encodeLocalDate
Encode ajava.time.LocalDateto a byte array, requiring 4 bytes.- Parameters:
val- value to encodebuf- byte array with at least 4 bytes starting atoff, nevernulloff- offset of the date value inbuf- Since:
- 6
-
decodeLocalDateTime
Decodejava.time.LocalDateTimefrombuffrom the first 8 bytes.- Parameters:
buf- (expected) at least 8 bytes- Returns:
LocalDateTimedecoded frombuf, ornullifbufisnull- Since:
- 5
-
decodeLocalDateTime
Decodejava.time.LocalDateTimefrombuffrom the 8 bytes starting atoff.- Parameters:
buf- (expected) at least 8 bytes fromoff, nevernulloff- offset of the datetime value inbuf- Returns:
LocalDateTimedecoded frombuf- Since:
- 6
-
encodeLocalDateTime
Encode ajava.time.LocalDateTimeas a byte array of 8 bytes.- Parameters:
val- value to encode- Returns:
valencoded as a byte array, ornullifvalisnull- Since:
- 5
-
encodeLocalDateTime
Encode ajava.time.LocalDateTimeto a byte array, requiring 8 bytes.- Parameters:
val- value to encodebuf- byte array with at least 8 bytes starting atoff, nevernulloff- offset of the datetime value inbuf- Since:
- 6
-
decodeDecimal64
Decodes a decimal64 from a byte array of 8 bytes.- Parameters:
buf- data to decode (expects exactly 8 bytes)- Returns:
- Decimal64 decoded from
buf, ornullifbufisnull
-
encodeDecimal64
Encodes a decimal64 as a byte array of 8 bytes.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array, ornullifvalisnull
-
decodeDecimal128
Decodes a decimal128 from a byte array of 16 bytes.- Parameters:
buf- data to decode (expects exactly 16 bytes)- Returns:
- Decimal128 decoded from
buf, ornullifbufisnull
-
encodeDecimal128
Encodes a decimal128 as a byte array of 16 bytes.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array, ornullifvalisnull
-
decodeInt128
Decodes a BigInteger from a byte array of 16 bytes (int128 format).- Parameters:
buf- data to decode (expects exactly 16 bytes)- Returns:
- BigInteger decoded from
buf, ornullifvalisnull
-
encodeInt128
Encodes a BigInteger as a byte array of 16 bytes (int128 format).The implementation expects to be passed a value that fits in 16 bytes. If a larger value is passed, an
IllegalArgumentExceptionis thrown.- Parameters:
val- value to be encoded- Returns:
valencoded as a byte array, ornullifvalisnull
-
getEncodingFactory
IEncodingFactory getEncodingFactory()- Returns:
- encoding factory.
-
getEncodingDefinition
EncodingDefinition getEncodingDefinition()- Returns:
- encoding definition used by this datatype coder for string conversions.
-
getEncoding
Encoding getEncoding()- Returns:
- encoding used by this datatype coder for string conversions.
-
forEncodingDefinition
Return a derived datatype coder that applies the supplied encoding definition for string conversions.- Parameters:
encodingDefinition- encoding definition- Returns:
- derived datatype coder (this instance, if encoding definition is the same)
- Since:
- 4
-
unwrap
DatatypeCoder unwrap()Unwrap this datatype coder to its parent (or itself).- Returns:
- parent of this datatype code, or itself if it has no parent.
- Since:
- 4.0
-
equals
Equality: same basic type (i.e.: wire protocol/JNA type + endianness) and same encoding definition.
This does not need to take into account the encoding factory, as usage should be limited to datatype coders derived from the same connection.
-
hashCode
int hashCode()
-