public class DefaultDatatypeCoder extends java.lang.Object implements DatatypeCoder
Implements the encoding and decoding for the wire protocol.
As a lot of the implementation also applies to the big endian and little endian decoders for the JNA implementation,
this class is not placed in package org.firebirdsql.gds.ng.wire
DatatypeCoder.RawDateTimeStruct
FRACTIONS_PER_HOUR, FRACTIONS_PER_MILLISECOND, FRACTIONS_PER_MINUTE, FRACTIONS_PER_SECOND, NANOSECONDS_PER_FRACTION
Constructor and Description |
---|
DefaultDatatypeCoder(IEncodingFactory encodingFactory)
Creates a default datatype coder for the wire protocol.
|
Modifier and Type | Method and Description |
---|---|
java.io.Reader |
createReader(java.io.InputStream inputStream)
Creates a reader wrapping an input stream.
|
java.io.Writer |
createWriter(java.io.OutputStream outputStream)
Creates a writer wrapping an input stream.
|
boolean |
decodeBoolean(byte[] data)
Decode boolean from supplied data.
|
java.sql.Date |
decodeDate(java.sql.Date d,
java.util.Calendar cal)
Decode a
Date value using a given Calendar . |
java.sql.Date |
decodeDateCalendar(byte[] byte_int,
java.util.Calendar c)
Decode a
byte array into a Date value. |
DatatypeCoder.RawDateTimeStruct |
decodeDateRaw(byte[] byte_int)
Decode a
byte array into a raw date time struct. |
Decimal128 |
decodeDecimal128(byte[] data)
Decodes a decimal128 from byte array.
|
Decimal64 |
decodeDecimal64(byte[] data)
Decodes a decimal64 from byte array.
|
double |
decodeDouble(byte[] byte_int)
Decode a
byte array into a double value. |
float |
decodeFloat(byte[] byte_int)
Decode a
byte array into a float value. |
int |
decodeInt(byte[] byte_int)
Decode a
byte array into an int value. |
int |
decodeInt(byte[] bytes,
int fromIndex)
Decode a
byte array to an int value. |
java.math.BigInteger |
decodeInt128(byte[] data)
Decodes a BigInteger from byte array.
|
java.time.LocalDate |
decodeLocalDate(byte[] data)
Decode LocalDate from supplied data.
|
java.time.LocalDateTime |
decodeLocalDateTime(byte[] data)
Decode LocalDateTime from supplied data.
|
java.time.LocalTime |
decodeLocalTime(byte[] data)
Decode LocalTime from supplied data.
|
long |
decodeLong(byte[] byte_int)
Decode a
byte array into a long value. |
short |
decodeShort(byte[] byte_int)
Decode a
byte array into a short value. |
short |
decodeShort(byte[] bytes,
int fromIndex)
Decode from a
byte array to a short value. |
java.lang.String |
decodeString(byte[] value)
Decode an encoded
byte array into a String using the encoding of this datatype coder. |
java.sql.Time |
decodeTime(java.sql.Time d,
java.util.Calendar cal,
boolean invertTimeZone)
Decode a
Time value using a given Calendar . |
java.sql.Time |
decodeTimeCalendar(byte[] int_byte,
java.util.Calendar c)
Decode a
byte array into a Time value. |
DatatypeCoder.RawDateTimeStruct |
decodeTimeRaw(byte[] int_byte)
Decode a
byte array into a raw date time struct. |
java.sql.Timestamp |
decodeTimestamp(java.sql.Timestamp value,
java.util.Calendar cal,
boolean invertTimeZone)
Decode a
Timestamp value using a given Calendar . |
java.sql.Timestamp |
decodeTimestampCalendar(byte[] byte_long,
java.util.Calendar c)
Decode an 8-byte
byte array into a Timestamp . |
DatatypeCoder.RawDateTimeStruct |
decodeTimestampRaw(byte[] byte_long)
Decode an 8-byte
byte array into a raw date time struct. |
byte[] |
encodeBoolean(boolean value)
Encodes boolean to 1 byte data.
|
java.sql.Date |
encodeDate(java.sql.Date d,
java.util.Calendar cal)
Encode a given
Date value using a given Calendar . |
byte[] |
encodeDateCalendar(java.sql.Date d,
java.util.Calendar c)
Encode a
Date value into a byte array. |
byte[] |
encodeDateRaw(DatatypeCoder.RawDateTimeStruct raw)
Encode the date portion of a raw date time struct into a
byte array. |
byte[] |
encodeDecimal128(Decimal128 decimal128)
Encodes a decimal128 to a byte array.
|
byte[] |
encodeDecimal64(Decimal64 decimal64)
Encodes a decimal64 to a byte array.
|
byte[] |
encodeDouble(double value)
Encode a
double value as a byte array. |
byte[] |
encodeFloat(float value)
Encode a
float value as a byte array. |
byte[] |
encodeInt(int value)
Encode an
int value as a byte array. |
void |
encodeInt(int value,
byte[] target,
int fromIndex)
Encode an
int value into the target byte array starting at index fromIndex . |
byte[] |
encodeInt128(java.math.BigInteger bigInteger)
Encodes a BigInteger to a 16-byte byte array.
|
byte[] |
encodeLocalDate(java.time.LocalDate value)
Encodes a java.time.LocalDate to date bytes.
|
byte[] |
encodeLocalDateTime(java.time.LocalDateTime value)
Encodes a java.time.LocalDateTime to timestamp bytes.
|
byte[] |
encodeLocalTime(java.time.LocalTime value)
Encodes a java.time.LocalTime to time bytes.
|
byte[] |
encodeLong(long value)
Encode a
long value as a byte array. |
byte[] |
encodeShort(int value)
Encode a
short value as a byte array. |
void |
encodeShort(int value,
byte[] target,
int fromIndex)
Encode a
short value into the target byte array starting at index fromIndex . |
byte[] |
encodeShort(short value)
Encode a
short value as a byte array. |
byte[] |
encodeString(java.lang.String value)
Encode a
String value into a byte array using the encoding of this datatype coder. |
java.sql.Time |
encodeTime(java.sql.Time d,
java.util.Calendar cal,
boolean invertTimeZone)
Encode a given
Time value using a given Calendar . |
byte[] |
encodeTimeCalendar(java.sql.Time d,
java.util.Calendar c)
Encode a
Time value into a byte array. |
byte[] |
encodeTimeRaw(DatatypeCoder.RawDateTimeStruct raw)
Encode the time portion of a raw date time struct into a
byte array. |
java.sql.Timestamp |
encodeTimestamp(java.sql.Timestamp value,
java.util.Calendar cal,
boolean invertTimeZone)
Encode a
Timestamp using a given Calendar . |
byte[] |
encodeTimestampCalendar(java.sql.Timestamp value,
java.util.Calendar c)
Encode a
Timestamp as a byte array. |
byte[] |
encodeTimestampRaw(DatatypeCoder.RawDateTimeStruct raw)
Encode the date and time portions of a raw date time struct into a
byte array. |
boolean |
equals(java.lang.Object o) |
DatatypeCoder |
forEncodingDefinition(EncodingDefinition encodingDefinition)
Return a derived datatype coder that applies the supplied encoding definition for string conversions.
|
static DefaultDatatypeCoder |
forEncodingFactory(IEncodingFactory encodingFactory)
Returns an instance of
DefaultDatatypeCoder for an encoding factory. |
Encoding |
getEncoding() |
EncodingDefinition |
getEncodingDefinition() |
IEncodingFactory |
getEncodingFactory() |
int |
hashCode() |
protected byte[] |
intToBytes(int value)
Deprecated.
will be removed in Jaybird 6, use
encodeInt(int) |
int |
sizeOfShort()
The size of an encoded short in this data type coder.
|
DatatypeCoder |
unwrap()
Unwrap this datatype coder to its parent (or itself).
|
public DefaultDatatypeCoder(IEncodingFactory encodingFactory)
In almost all cases, it is better to use forEncodingFactory(IEncodingFactory)
.
encodingFactory
- Encoding factorypublic static DefaultDatatypeCoder forEncodingFactory(IEncodingFactory encodingFactory)
DefaultDatatypeCoder
for an encoding factory.encodingFactory
- Encoding factorypublic int sizeOfShort()
DatatypeCoder
sizeOfShort
in interface DatatypeCoder
2
or 4
bytes)public byte[] encodeShort(short value)
DatatypeCoder
short
value as a byte
array.encodeShort
in interface DatatypeCoder
value
- The value to be encodedvalue
encoded as a byte
arrayDatatypeCoder.encodeShort(int)
public byte[] encodeShort(int value)
DatatypeCoder
short
value as a byte
array.encodeShort
in interface DatatypeCoder
value
- The value to be encodedvalue
encoded as a byte
arraypublic void encodeShort(int value, byte[] target, int fromIndex)
DatatypeCoder
short
value into the target
byte array starting at index fromIndex
.encodeShort
in interface DatatypeCoder
value
- The value to be encodedtarget
- Target byte array of sufficient size (warning: this may be datatype coder specific)fromIndex
- Index to start writingpublic short decodeShort(byte[] byte_int)
DatatypeCoder
byte
array into a short
value.decodeShort
in interface DatatypeCoder
byte_int
- The byte
array to be decodedshort
value of the decoded byte
arraypublic short decodeShort(byte[] bytes, int fromIndex)
DatatypeCoder
byte
array to a short
value.decodeShort
in interface DatatypeCoder
bytes
- The byte
array to be decodedfromIndex
- The index to start readingshort
value of the decoded byte
arraypublic byte[] encodeInt(int value)
DatatypeCoder
int
value as a byte
array.encodeInt
in interface DatatypeCoder
value
- The value to be encodedvalue
encoded as a byte
arraypublic void encodeInt(int value, byte[] target, int fromIndex)
DatatypeCoder
int
value into the target
byte array starting at index fromIndex
.encodeInt
in interface DatatypeCoder
value
- The value to be encodedtarget
- Target byte array of sufficient sizefromIndex
- Index to start writing@Deprecated protected byte[] intToBytes(int value)
encodeInt(int)
int
value as a byte
array in network-order(big-endian) representation.value
- The value to be encodedvalue
encoded as a byte
arraypublic int decodeInt(byte[] byte_int)
DatatypeCoder
byte
array into an int
value.decodeInt
in interface DatatypeCoder
byte_int
- The byte
array to be decodedint
value of the decoded byte
arraypublic int decodeInt(byte[] bytes, int fromIndex)
DatatypeCoder
byte
array to an int
value.decodeInt
in interface DatatypeCoder
bytes
- The byte
array to be decodedfromIndex
- The index to start readingint
value of the decoded byte
arraypublic byte[] encodeLong(long value)
DatatypeCoder
long
value as a byte
array.encodeLong
in interface DatatypeCoder
value
- The value to be encodedvalue
encoded as a byte
arraypublic long decodeLong(byte[] byte_int)
DatatypeCoder
byte
array into a long
value.decodeLong
in interface DatatypeCoder
byte_int
- The byte
array to be decodedlong
value of the decoded byte
arraypublic byte[] encodeFloat(float value)
DatatypeCoder
float
value as a byte
array.encodeFloat
in interface DatatypeCoder
value
- The value to be encodedvalue
encoded as a byte
arraypublic float decodeFloat(byte[] byte_int)
DatatypeCoder
byte
array into a float
value.decodeFloat
in interface DatatypeCoder
byte_int
- The byte
array to be decodedfloat
value of the decoded byte
arraypublic byte[] encodeDouble(double value)
DatatypeCoder
double
value as a byte
array.encodeDouble
in interface DatatypeCoder
value
- The value to be encodedvalue
encoded as a byte
arraypublic double decodeDouble(byte[] byte_int)
DatatypeCoder
byte
array into a double
value.decodeDouble
in interface DatatypeCoder
byte_int
- The byte
array to be decodeddouble
value of the decoded byte
arraypublic final byte[] encodeString(java.lang.String value)
DatatypeCoder
String
value into a byte
array using the encoding of this datatype coder.encodeString
in interface DatatypeCoder
value
- The String
to be encodedvalue
as a byte
arraypublic final java.io.Writer createWriter(java.io.OutputStream outputStream)
DatatypeCoder
createWriter
in interface DatatypeCoder
outputStream
- Input streampublic final java.lang.String decodeString(byte[] value)
DatatypeCoder
byte
array into a String
using the encoding of this datatype coder.decodeString
in interface DatatypeCoder
value
- The value to be decodedString
public final java.io.Reader createReader(java.io.InputStream inputStream)
DatatypeCoder
createReader
in interface DatatypeCoder
inputStream
- Input streampublic java.sql.Timestamp encodeTimestamp(java.sql.Timestamp value, java.util.Calendar cal, boolean invertTimeZone)
DatatypeCoder
Timestamp
using a given Calendar
.encodeTimestamp
in interface DatatypeCoder
value
- The Timestamp
to be encodedcal
- The Calendar
to be used for encoding,
may be null
invertTimeZone
- If true
, the timezone offset value
will be subtracted from the encoded value, otherwise it will
be addedTimestamp
public byte[] encodeTimestampRaw(DatatypeCoder.RawDateTimeStruct raw)
DatatypeCoder
byte
array.encodeTimestampRaw
in interface DatatypeCoder
raw
- The RawDateTimeStruct
to be encodedbyte
s representing the date and time of the given RawDateTimeStruct
public byte[] encodeTimestampCalendar(java.sql.Timestamp value, java.util.Calendar c)
DatatypeCoder
Timestamp
as a byte
array.encodeTimestampCalendar
in interface DatatypeCoder
value
- The Timestamp
to be encodedc
- Calendar to use for time zone calculationbyte
s that represents the given Timestamp
valuepublic java.sql.Timestamp decodeTimestamp(java.sql.Timestamp value, java.util.Calendar cal, boolean invertTimeZone)
DatatypeCoder
Timestamp
value using a given Calendar
.decodeTimestamp
in interface DatatypeCoder
value
- The Timestamp
to be decodedcal
- The Calendar
to be used in decoding,
may be null
invertTimeZone
- If true
, the timezone offset value
will be subtracted from the decoded value, otherwise it will
be addedTimestamp
public DatatypeCoder.RawDateTimeStruct decodeTimestampRaw(byte[] byte_long)
DatatypeCoder
byte
array into a raw date time struct.decodeTimestampRaw
in interface DatatypeCoder
byte_long
- The byte
array to be decodedDatatypeCoder.RawDateTimeStruct
.public java.sql.Timestamp decodeTimestampCalendar(byte[] byte_long, java.util.Calendar c)
DatatypeCoder
byte
array into a Timestamp
.decodeTimestampCalendar
in interface DatatypeCoder
byte_long
- The byte
array to be decodedc
- Calendar to use for time zone calculationTimestamp
value from the decoded bytespublic java.sql.Time encodeTime(java.sql.Time d, java.util.Calendar cal, boolean invertTimeZone)
DatatypeCoder
Time
value using a given Calendar
.encodeTime
in interface DatatypeCoder
d
- The Time
to be encodedcal
- The Calendar
to be used in the encoding, may be null
Time
public byte[] encodeTimeRaw(DatatypeCoder.RawDateTimeStruct raw)
DatatypeCoder
byte
array.encodeTimeRaw
in interface DatatypeCoder
raw
- The RawDateTimeStruct
to be encodedbyte
s representing the time of the given RawDateTimeStruct
public byte[] encodeTimeCalendar(java.sql.Time d, java.util.Calendar c)
DatatypeCoder
Time
value into a byte
array.encodeTimeCalendar
in interface DatatypeCoder
d
- The Time
to be encodedc
- Calendar to use for time zone calculationbyte
s representing the given Time
public java.sql.Time decodeTime(java.sql.Time d, java.util.Calendar cal, boolean invertTimeZone)
DatatypeCoder
Time
value using a given Calendar
.decodeTime
in interface DatatypeCoder
d
- The Time
to be decodedcal
- The Calendar
to be used in the decoding, may be null
Time
public DatatypeCoder.RawDateTimeStruct decodeTimeRaw(byte[] int_byte)
DatatypeCoder
byte
array into a raw date time struct.decodeTimeRaw
in interface DatatypeCoder
int_byte
- The byte
array to be decodedDatatypeCoder.RawDateTimeStruct
public java.sql.Time decodeTimeCalendar(byte[] int_byte, java.util.Calendar c)
DatatypeCoder
byte
array into a Time
value.decodeTimeCalendar
in interface DatatypeCoder
int_byte
- The byte
array to be decodedc
- Calendar to use for time zone calculationTime
public java.sql.Date encodeDate(java.sql.Date d, java.util.Calendar cal)
DatatypeCoder
Date
value using a given Calendar
.encodeDate
in interface DatatypeCoder
d
- The Date
to be encodedcal
- The Calendar
to be used in the encoding, may be null
Date
public byte[] encodeDateRaw(DatatypeCoder.RawDateTimeStruct raw)
DatatypeCoder
byte
array.encodeDateRaw
in interface DatatypeCoder
raw
- The RawDateTimeStruct
to be encodedbyte
s representing the date of the given RawDateTimeStruct
public byte[] encodeDateCalendar(java.sql.Date d, java.util.Calendar c)
DatatypeCoder
Date
value into a byte
array.encodeDateCalendar
in interface DatatypeCoder
d
- The Date
to be encodedc
- Calendar to use for time zone calculationbyte
s representing the given Date
public java.sql.Date decodeDate(java.sql.Date d, java.util.Calendar cal)
DatatypeCoder
Date
value using a given Calendar
.decodeDate
in interface DatatypeCoder
d
- The Date
to be decodedcal
- The Calendar
to be used in the decoding, may be null
Date
public DatatypeCoder.RawDateTimeStruct decodeDateRaw(byte[] byte_int)
DatatypeCoder
byte
array into a raw date time struct.decodeDateRaw
in interface DatatypeCoder
byte_int
- The byte
array to be decodedDatatypeCoder.RawDateTimeStruct
public java.sql.Date decodeDateCalendar(byte[] byte_int, java.util.Calendar c)
DatatypeCoder
byte
array into a Date
value.decodeDateCalendar
in interface DatatypeCoder
byte_int
- The byte
array to be decodedc
- Calendar to use for time zone calculationDate
public boolean decodeBoolean(byte[] data)
DatatypeCoder
decodeBoolean
in interface DatatypeCoder
data
- (expected) 1 bytesfalse
when 0, true
for all other valuespublic byte[] encodeBoolean(boolean value)
DatatypeCoder
encodeBoolean
in interface DatatypeCoder
value
- Boolean value to encodetrue
as 1, false
as 0.public java.time.LocalTime decodeLocalTime(byte[] data)
DatatypeCoder
decodeLocalTime
in interface DatatypeCoder
data
- (expected) 4 bytespublic byte[] encodeLocalTime(java.time.LocalTime value)
DatatypeCoder
encodeLocalTime
in interface DatatypeCoder
value
- LocalTime value to encodepublic java.time.LocalDate decodeLocalDate(byte[] data)
DatatypeCoder
decodeLocalDate
in interface DatatypeCoder
data
- (expected) 4 bytespublic byte[] encodeLocalDate(java.time.LocalDate value)
DatatypeCoder
encodeLocalDate
in interface DatatypeCoder
value
- LocalDate to encodepublic java.time.LocalDateTime decodeLocalDateTime(byte[] data)
DatatypeCoder
decodeLocalDateTime
in interface DatatypeCoder
data
- (expected) 8 bytespublic byte[] encodeLocalDateTime(java.time.LocalDateTime value)
DatatypeCoder
encodeLocalDateTime
in interface DatatypeCoder
value
- LocalDateTime to encodepublic Decimal64 decodeDecimal64(byte[] data)
DatatypeCoder
decodeDecimal64
in interface DatatypeCoder
data
- Data to decode (expected 8 bytes)public byte[] encodeDecimal64(Decimal64 decimal64)
DatatypeCoder
encodeDecimal64
in interface DatatypeCoder
decimal64
- The decimal64 value to be encodedpublic Decimal128 decodeDecimal128(byte[] data)
DatatypeCoder
decodeDecimal128
in interface DatatypeCoder
data
- Data to decode (expected 16 bytes)public byte[] encodeDecimal128(Decimal128 decimal128)
DatatypeCoder
encodeDecimal128
in interface DatatypeCoder
decimal128
- The decimal128 value to be encodedpublic java.math.BigInteger decodeInt128(byte[] data)
DatatypeCoder
decodeInt128
in interface DatatypeCoder
data
- Data to decode (expected 16 bytes)public byte[] encodeInt128(java.math.BigInteger bigInteger)
DatatypeCoder
The implementation expects to be passed a value that fits in 16 bytes. If a larger value is passed, and
IllegalArgumentException
is thrown.
encodeInt128
in interface DatatypeCoder
bigInteger
- The BigInteger value to be encodedpublic final IEncodingFactory getEncodingFactory()
getEncodingFactory
in interface DatatypeCoder
public final EncodingDefinition getEncodingDefinition()
getEncodingDefinition
in interface DatatypeCoder
public final Encoding getEncoding()
getEncoding
in interface DatatypeCoder
public final DatatypeCoder forEncodingDefinition(EncodingDefinition encodingDefinition)
DatatypeCoder
forEncodingDefinition
in interface DatatypeCoder
encodingDefinition
- Encoding definitionpublic DatatypeCoder unwrap()
DatatypeCoder
unwrap
in interface DatatypeCoder
public final boolean equals(java.lang.Object o)
DatatypeCoder
Equality: same basic type (ie: 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.
equals
in interface DatatypeCoder
equals
in class java.lang.Object
o
- Object to compare totrue
if other is an equivalent datatype coder.public final int hashCode()
hashCode
in interface DatatypeCoder
hashCode
in class java.lang.Object
Copyright © 2001-2023 Jaybird (Firebird JDBC) team. All rights reserved.