- All Known Implementing Classes:
DefaultDatatypeCoder
,EncodingSpecificDatatypeCoder
- Since:
- 3
- Author:
- Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionCreates a reader wrapping an input stream.createWriter
(OutputStream out) Creates a writer wrapping an input stream.boolean
decodeBoolean
(byte[] buf) Decode a boolean frombuf
from 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.double
decodeDouble
(byte[] buf) Decode a double value frombuf
from the first 8 bytes.float
decodeFloat
(byte[] buf) Decode a float value frombuf
from the first 4 bytes.int
decodeInt
(byte[] buf) Decode an int value frombuf
from the first 4 bytes.int
decodeInt
(byte[] buf, int off) Decode an int value frombuf
starting at offsetoff
for 4 bytes.decodeInt128
(byte[] buf) Decodes a BigInteger from a byte array of 16 bytes (int128 format).decodeLocalDate
(byte[] buf) Decodejava.time.LocalDate
frombuf
from the first 4 bytes.decodeLocalDate
(byte[] buf, int off) Decodejava.time.LocalDate
frombuf
from the 4 bytes starting atoff
.decodeLocalDateTime
(byte[] buf) Decodejava.time.LocalDateTime
frombuf
from the first 8 bytes.decodeLocalDateTime
(byte[] buf, int off) Decodejava.time.LocalDateTime
frombuf
from the 8 bytes starting atoff
.decodeLocalTime
(byte[] buf) Decodejava.time.LocalTime
frombuf
from the first 4 bytes.decodeLocalTime
(byte[] buf, int off) Decodejava.time.LocalTime
frombuf
from the 4 bytes starting atoff
.long
decodeLong
(byte[] buf) Decode a long value frombuf
from the first 8 bytes.short
decodeShort
(byte[] buf) Decode a short value frombuf
from the firstsizeOfShort()
bytes.short
decodeShort
(byte[] buf, int off) decodeString
(byte[] buf) Decode aString
frombuf
using 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.void
encodeInt
(int val, byte[] buf, int off) Encode an int value intobuf
starting at indexoff
for 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.LocalDate
as a byte array of 4 bytes.void
encodeLocalDate
(LocalDate val, byte[] buf, int off) Encode ajava.time.LocalDate
to a byte array, requiring 4 bytes.byte[]
Encode ajava.time.LocalDateTime
as a byte array of 8 bytes.void
encodeLocalDateTime
(LocalDateTime val, byte[] buf, int off) Encode ajava.time.LocalDateTime
to a byte array, requiring 8 bytes.byte[]
encodeLocalTime
(LocalTime val) Encode ajava.time.LocalTime
as a byte array of 4 bytes.void
encodeLocalTime
(LocalTime val, byte[] buf, int off) Encode ajava.time.LocalTime
to 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()
.void
encodeShort
(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 aString
value as a byte array using the encoding of this datatype coder.boolean
forEncodingDefinition
(EncodingDefinition encodingDefinition) Return a derived datatype coder that applies the supplied encoding definition for string conversions.int
hashCode()
int
The 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
2
or4
bytes) - Since:
- 4
-
encodeShort
byte[] encodeShort(short val) Encode a short value as a byte array of lengthsizeOfShort()
.- Parameters:
val
- value to be encoded- Returns:
val
encoded 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:
val
encoded as a byte array
-
encodeShort
void encodeShort(int val, byte[] buf, int off) Encode a short value intobuf
starting at offsetoff
forsizeOfShort()
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()
), nevernull
off
- offset to start encoding- Since:
- 4
-
decodeShort
short decodeShort(byte[] buf) Decode a short value frombuf
from the firstsizeOfShort()
bytes.- Parameters:
buf
- byte array of sufficient size (warning: this is datatype coder specific, seesizeOfShort()
)- Returns:
- short value from
buf
, or0
whenbuf
isnull
-
decodeShort
short decodeShort(byte[] buf, int off) - Parameters:
buf
- byte array of sufficient size (warning: this is datatype coder specific, seesizeOfShort()
), nevernull
off
- 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:
val
encoded as a byte array, or0
whenbuf
isnull
-
encodeInt
void encodeInt(int val, byte[] buf, int off) Encode an int value intobuf
starting at indexoff
for 4 bytes.- Parameters:
val
- value to be encodedbuf
- byte array of sufficient size, nevernull
off
- offset to start encoding- Since:
- 4
-
decodeInt
int decodeInt(byte[] buf) Decode an int value frombuf
from the first 4 bytes.- Parameters:
buf
- byte array of sufficient size- Returns:
- int value decoded from
buf
, or0
whenbuf
isnull
-
decodeInt
int decodeInt(byte[] buf, int off) Decode an int value frombuf
starting at offsetoff
for 4 bytes.- Parameters:
buf
- byte array of sufficient size, nevernull
off
- 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:
val
encoded as a byte array
-
decodeLong
long decodeLong(byte[] buf) Decode a long value frombuf
from the first 8 bytes.- Parameters:
buf
- byte array of sufficient size, or0
whenbuf
isnull
- 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:
val
encoded as a byte array
-
decodeFloat
float decodeFloat(byte[] buf) Decode a float value frombuf
from the first 4 bytes.- Parameters:
buf
- byte array of sufficient size, or0
whenbuf
isnull
- 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:
val
encoded as a byte array
-
decodeDouble
double decodeDouble(byte[] buf) Decode a double value frombuf
from the first 8 bytes.- Parameters:
buf
- byte array of sufficient size, or0
whenbuf
isnull
- Returns:
- double value decoded from
buf
-
encodeString
Encode aString
value as a byte array using the encoding of this datatype coder.- Parameters:
val
- value to be encoded- Returns:
val
encoded as a byte array, ornull
ifval
isnull
- 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 aString
frombuf
using the encoding of this datatype coder.- Parameters:
buf
- byte array to be decoded- Returns:
String
decoded frombuf
, ornull
ifbuf
isnull
- 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 frombuf
from the first byte.- Parameters:
buf
- (expected) 1 bytes- Returns:
false
when 0,true
for all other values, orfalse
ifbuf
isnull
-
encodeBoolean
byte[] encodeBoolean(boolean val) Encodes boolean as a byte array of 1 byte.- Parameters:
val
- value to encode- Returns:
true
as 1,false
as 0.
-
decodeLocalTime
Decodejava.time.LocalTime
frombuf
from the first 4 bytes.- Parameters:
buf
- (expected) at least 4 bytes- Returns:
LocalTime
decoded frombuf
, ornull
ifbuf
isnull
- Since:
- 5
-
decodeLocalTime
Decodejava.time.LocalTime
frombuf
from the 4 bytes starting atoff
.- Parameters:
buf
- (expected) at least 4 bytes fromoff
, nevernull
off
- offset of the time value inbuf
- Returns:
LocalTime
decoded frombuf
- Since:
- 6
-
encodeLocalTime
Encode ajava.time.LocalTime
as a byte array of 4 bytes.- Parameters:
val
- value to encode- Returns:
val
encoded as a byte array, ornull
ifval
isnull
- Since:
- 5
-
encodeLocalTime
Encode ajava.time.LocalTime
to a byte array, requiring 4 bytes.- Parameters:
val
- value to encodebuf
- byte array with at least 4 bytes starting atoff
, nevernull
off
- offset of the time value inbuf
- Since:
- 6
-
decodeLocalDate
Decodejava.time.LocalDate
frombuf
from the first 4 bytes.- Parameters:
buf
- (expected) at least 4 bytes- Returns:
LocalDate
decoded frombuf
, ornull
ifbuf
isnull
- Since:
- 5
-
decodeLocalDate
Decodejava.time.LocalDate
frombuf
from the 4 bytes starting atoff
.- Parameters:
buf
- (expected) at least 4 bytes fromoff
, nevernull
off
- offset of the time value inbuf
- Returns:
LocalDate
decoded frombuf
- Since:
- 6
-
encodeLocalDate
Encode ajava.time.LocalDate
as a byte array of 4 bytes.- Parameters:
val
- value to encode- Returns:
val
encoded as a byte array, ornull
ifval
isnull
- Since:
- 5
-
encodeLocalDate
Encode ajava.time.LocalDate
to a byte array, requiring 4 bytes.- Parameters:
val
- value to encodebuf
- byte array with at least 4 bytes starting atoff
, nevernull
off
- offset of the date value inbuf
- Since:
- 6
-
decodeLocalDateTime
Decodejava.time.LocalDateTime
frombuf
from the first 8 bytes.- Parameters:
buf
- (expected) at least 8 bytes- Returns:
LocalDateTime
decoded frombuf
, ornull
ifbuf
isnull
- Since:
- 5
-
decodeLocalDateTime
Decodejava.time.LocalDateTime
frombuf
from the 8 bytes starting atoff
.- Parameters:
buf
- (expected) at least 8 bytes fromoff
, nevernull
off
- offset of the datetime value inbuf
- Returns:
LocalDateTime
decoded frombuf
- Since:
- 6
-
encodeLocalDateTime
Encode ajava.time.LocalDateTime
as a byte array of 8 bytes.- Parameters:
val
- value to encode- Returns:
val
encoded as a byte array, ornull
ifval
isnull
- Since:
- 5
-
encodeLocalDateTime
Encode ajava.time.LocalDateTime
to a byte array, requiring 8 bytes.- Parameters:
val
- value to encodebuf
- byte array with at least 8 bytes starting atoff
, nevernull
off
- 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
, ornull
ifbuf
isnull
-
encodeDecimal64
Encodes a decimal64 as a byte array of 8 bytes.- Parameters:
val
- value to be encoded- Returns:
val
encoded as a byte array, ornull
ifval
isnull
-
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
, ornull
ifbuf
isnull
-
encodeDecimal128
Encodes a decimal128 as a byte array of 16 bytes.- Parameters:
val
- value to be encoded- Returns:
val
encoded as a byte array, ornull
ifval
isnull
-
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
, ornull
ifval
isnull
-
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
IllegalArgumentException
is thrown.- Parameters:
val
- value to be encoded- Returns:
val
encoded as a byte array, ornull
ifval
isnull
-
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()
-