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.RawDateTimeStructFRACTIONS_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(byte[] byte_int)Decode a  bytearray into aDatevalue. | 
| java.sql.Date | decodeDate(java.sql.Date d,
          java.util.Calendar cal)Decode a  Datevalue using a givenCalendar. | 
| java.sql.Date | decodeDateCalendar(byte[] byte_int,
                  java.util.Calendar c) | 
| DatatypeCoder.RawDateTimeStruct | decodeDateRaw(byte[] byte_int)Decode a  bytearray 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  bytearray into adoublevalue. | 
| float | decodeFloat(byte[] byte_int)Decode a  bytearray into afloatvalue. | 
| int | decodeInt(byte[] byte_int)Decode a  bytearray into anintvalue. | 
| int | decodeInt(byte[] bytes,
         int fromIndex)Decode a  bytearray to anintvalue. | 
| java.math.BigInteger | decodeInt128(byte[] data)Decodes a BigInteger from byte array. | 
| long | decodeLong(byte[] byte_int)Decode a  bytearray into alongvalue. | 
| short | decodeShort(byte[] byte_int)Decode a  bytearray into ashortvalue. | 
| short | decodeShort(byte[] bytes,
           int fromIndex)Decode from a  bytearray to ashortvalue. | 
| java.lang.String | decodeString(byte[] value)Decode an encoded  bytearray into aStringusing the encoding of this datatype coder. | 
| java.sql.Time | decodeTime(byte[] int_byte)Decode a  bytearray into aTimevalue. | 
| java.sql.Time | decodeTime(java.sql.Time d,
          java.util.Calendar cal,
          boolean invertTimeZone)Decode a  Timevalue using a givenCalendar. | 
| java.sql.Time | decodeTimeCalendar(byte[] int_byte,
                  java.util.Calendar c) | 
| DatatypeCoder.RawDateTimeStruct | decodeTimeRaw(byte[] int_byte)Decode a  bytearray into a raw date time struct. | 
| java.sql.Timestamp | decodeTimestamp(byte[] byte_long)Decode a 8-byte  bytearray into aTimestamp. | 
| java.sql.Timestamp | decodeTimestamp(java.sql.Timestamp value,
               java.util.Calendar cal)Decode a  Timestampvalue using a givenCalendar. | 
| java.sql.Timestamp | decodeTimestamp(java.sql.Timestamp value,
               java.util.Calendar cal,
               boolean invertTimeZone)Decode a  Timestampvalue using a givenCalendar. | 
| java.sql.Timestamp | decodeTimestampCalendar(byte[] byte_long,
                       java.util.Calendar c) | 
| DatatypeCoder.RawDateTimeStruct | decodeTimestampRaw(byte[] byte_long)Decode a 8-byte  bytearray into a raw date time struct. | 
| byte[] | encodeBoolean(boolean value)Encodes boolean to 1 byte data. | 
| byte[] | encodeDate(java.sql.Date d)Encode a  Datevalue into abytearray. | 
| java.sql.Date | encodeDate(java.sql.Date d,
          java.util.Calendar cal)Encode a given  Datevalue using a givenCalendar. | 
| byte[] | encodeDateCalendar(java.sql.Date d,
                  java.util.Calendar c) | 
| byte[] | encodeDateRaw(DatatypeCoder.RawDateTimeStruct raw)Encode the date portion of a raw date time struct into a  bytearray. | 
| 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  doublevalue as abytearray. | 
| byte[] | encodeFloat(float value)Encode a  floatvalue as abytearray. | 
| byte[] | encodeInt(int value)Encode an  intvalue as abytearray. | 
| void | encodeInt(int value,
         byte[] target,
         int fromIndex)Encode an  intvalue into thetargetbyte array starting at indexfromIndex. | 
| byte[] | encodeInt128(java.math.BigInteger bigInteger)Encodes a BigInteger to a 16-byte byte array. | 
| byte[] | encodeLocalDate(int year,
               int month,
               int day)Encodes a java.time.LocalDate equivalent to date bytes. | 
| byte[] | encodeLocalDateTime(int year,
                   int month,
                   int day,
                   int hour,
                   int minute,
                   int second,
                   int nanos)Encodes a java.time.LocalDateTime equivalent to timestamp bytes. | 
| byte[] | encodeLocalTime(int hour,
               int minute,
               int second,
               int nanos)Encodes a java.time.LocalTime equivalent to time bytes. | 
| byte[] | encodeLong(long value)Encode a  longvalue as abytearray. | 
| byte[] | encodeShort(int value)Encode a  shortvalue as abytearray. | 
| void | encodeShort(int value,
           byte[] target,
           int fromIndex)Encode a  shortvalue into thetargetbyte array starting at indexfromIndex. | 
| byte[] | encodeShort(short value)Encode a  shortvalue as abytearray. | 
| byte[] | encodeString(java.lang.String value)Encode a  Stringvalue into abytearray using the encoding of this datatype coder. | 
| byte[] | encodeTime(java.sql.Time d)Encode a  Timevalue into abytearray. | 
| java.sql.Time | encodeTime(java.sql.Time d,
          java.util.Calendar cal,
          boolean invertTimeZone)Encode a given  Timevalue using a givenCalendar. | 
| byte[] | encodeTimeCalendar(java.sql.Time d,
                  java.util.Calendar c) | 
| byte[] | encodeTimeRaw(DatatypeCoder.RawDateTimeStruct raw)Encode the time portion of a raw date time struct into a  bytearray. | 
| byte[] | encodeTimestamp(java.sql.Timestamp value)Encode a  Timestampas abytearray. | 
| java.sql.Timestamp | encodeTimestamp(java.sql.Timestamp value,
               java.util.Calendar cal)Encode a  Timestampusing a givenCalendar. | 
| java.sql.Timestamp | encodeTimestamp(java.sql.Timestamp value,
               java.util.Calendar cal,
               boolean invertTimeZone)Encode a  Timestampusing a givenCalendar. | 
| byte[] | encodeTimestampCalendar(java.sql.Timestamp value,
                       java.util.Calendar c) | 
| byte[] | encodeTimestampRaw(DatatypeCoder.RawDateTimeStruct raw)Encode the date and time portions of a raw date time struct into a  bytearray. | 
| 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  DefaultDatatypeCoderfor an encoding factory. | 
| Encoding | getEncoding() | 
| EncodingDefinition | getEncodingDefinition() | 
| IEncodingFactory | getEncodingFactory() | 
| int | hashCode() | 
| protected byte[] | intToBytes(int value)Encode an  intvalue as abytearray in network-order(big-endian) representation. | 
| 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()
DatatypeCodersizeOfShort in interface DatatypeCoder2 or 4 bytes)public byte[] encodeShort(short value)
DatatypeCodershort value as a byte array.encodeShort in interface DatatypeCodervalue - The value to be encodedvalue encoded as a byte arrayDatatypeCoder.encodeShort(int)public byte[] encodeShort(int value)
DatatypeCodershort value as a byte array.encodeShort in interface DatatypeCodervalue - The value to be encodedvalue encoded as a byte arraypublic void encodeShort(int value,
                        byte[] target,
                        int fromIndex)
DatatypeCodershort value into the target byte array starting at index fromIndex.encodeShort in interface DatatypeCodervalue - 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)
DatatypeCoderbyte array into a short value.decodeShort in interface DatatypeCoderbyte_int - The byte array to be decodedshort value of the decoded byte arraypublic short decodeShort(byte[] bytes,
                         int fromIndex)
DatatypeCoderbyte array to a short value.decodeShort in interface DatatypeCoderbytes - The byte array to be decodedfromIndex - The index to start readingshort value of the decoded byte arraypublic byte[] encodeInt(int value)
DatatypeCoderint value as a byte array.encodeInt in interface DatatypeCodervalue - The value to be encodedvalue encoded as a byte arraypublic void encodeInt(int value,
                      byte[] target,
                      int fromIndex)
DatatypeCoderint value into the target byte array starting at index fromIndex.encodeInt in interface DatatypeCodervalue - The value to be encodedtarget - Target byte array of sufficient sizefromIndex - Index to start writingprotected byte[] intToBytes(int value)
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)
DatatypeCoderbyte array into an int value.decodeInt in interface DatatypeCoderbyte_int - The byte array to be decodedint value of the decoded byte arraypublic int decodeInt(byte[] bytes,
                     int fromIndex)
DatatypeCoderbyte array to an int value.decodeInt in interface DatatypeCoderbytes - The byte array to be decodedfromIndex - The index to start readingint value of the decoded byte arraypublic byte[] encodeLong(long value)
DatatypeCoderlong value as a byte array.encodeLong in interface DatatypeCodervalue - The value to be encodedvalue encoded as a byte arraypublic long decodeLong(byte[] byte_int)
DatatypeCoderbyte array into a long value.decodeLong in interface DatatypeCoderbyte_int - The byte array to be decodedlong value of the decoded byte arraypublic byte[] encodeFloat(float value)
DatatypeCoderfloat value as a byte array.encodeFloat in interface DatatypeCodervalue - The value to be encodedvalue encoded as a byte arraypublic float decodeFloat(byte[] byte_int)
DatatypeCoderbyte array into a float value.decodeFloat in interface DatatypeCoderbyte_int - The byte array to be decodedfloat value of the decoded byte arraypublic byte[] encodeDouble(double value)
DatatypeCoderdouble value as a byte array.encodeDouble in interface DatatypeCodervalue - The value to be encodedvalue encoded as a byte arraypublic double decodeDouble(byte[] byte_int)
DatatypeCoderbyte array into a double value.decodeDouble in interface DatatypeCoderbyte_int - The byte array to be decodeddouble value of the decoded byte arraypublic final byte[] encodeString(java.lang.String value)
DatatypeCoderString value into a byte array using the encoding of this datatype coder.encodeString in interface DatatypeCodervalue - The String to be encodedvalue as a byte arraypublic final java.io.Writer createWriter(java.io.OutputStream outputStream)
DatatypeCodercreateWriter in interface DatatypeCoderoutputStream - Input streampublic final java.lang.String decodeString(byte[] value)
DatatypeCoderbyte array into a String using the encoding of this datatype coder.decodeString in interface DatatypeCodervalue - The value to be decodedStringpublic final java.io.Reader createReader(java.io.InputStream inputStream)
DatatypeCodercreateReader in interface DatatypeCoderinputStream - Input streampublic java.sql.Timestamp encodeTimestamp(java.sql.Timestamp value,
                                          java.util.Calendar cal)
DatatypeCoderTimestamp using a given Calendar.encodeTimestamp in interface DatatypeCodervalue - The Timestamp to be encodedcal - The Calendar to be used for encoding, may be nullpublic java.sql.Timestamp encodeTimestamp(java.sql.Timestamp value,
                                          java.util.Calendar cal,
                                          boolean invertTimeZone)
DatatypeCoderTimestamp using a given Calendar.encodeTimestamp in interface DatatypeCodervalue - The Timestamp to be encodedcal - The Calendar to be used for encoding,
        may be nullinvertTimeZone - If true, the timezone offset value
        will be subtracted from the encoded value, otherwise it will
        be addedTimestamppublic byte[] encodeTimestamp(java.sql.Timestamp value)
DatatypeCoderTimestamp as a byte array.encodeTimestamp in interface DatatypeCodervalue - The Timestamp to be encodedbytes that represents the given Timestamp valuepublic byte[] encodeTimestampRaw(DatatypeCoder.RawDateTimeStruct raw)
DatatypeCoderbyte array.encodeTimestampRaw in interface DatatypeCoderraw - The RawDateTimeStruct to be encodedbytes representing the date and time of the given RawDateTimeStructpublic byte[] encodeTimestampCalendar(java.sql.Timestamp value,
                                      java.util.Calendar c)
encodeTimestampCalendar in interface DatatypeCoderpublic java.sql.Timestamp decodeTimestamp(java.sql.Timestamp value,
                                          java.util.Calendar cal)
DatatypeCoderTimestamp value using a given Calendar.decodeTimestamp in interface DatatypeCodervalue - The Timestamp to be decodedcal - The Calendar to be used in decoding,
        may be nullTimestamppublic java.sql.Timestamp decodeTimestamp(java.sql.Timestamp value,
                                          java.util.Calendar cal,
                                          boolean invertTimeZone)
DatatypeCoderTimestamp value using a given Calendar.decodeTimestamp in interface DatatypeCodervalue - The Timestamp to be decodedcal - The Calendar to be used in decoding,
        may be nullinvertTimeZone - If true, the timezone offset value
        will be subtracted from the decoded value, otherwise it will
        be addedTimestamppublic java.sql.Timestamp decodeTimestamp(byte[] byte_long)
DatatypeCoderbyte array into a Timestamp.decodeTimestamp in interface DatatypeCoderbyte_long - The byte array to be decodedTimestamp value from the decoded bytespublic DatatypeCoder.RawDateTimeStruct decodeTimestampRaw(byte[] byte_long)
DatatypeCoderbyte array into a raw date time struct.decodeTimestampRaw in interface DatatypeCoderbyte_long - The byte array to be decodedDatatypeCoder.RawDateTimeStruct.public java.sql.Timestamp decodeTimestampCalendar(byte[] byte_long,
                                                  java.util.Calendar c)
decodeTimestampCalendar in interface DatatypeCoderpublic java.sql.Time encodeTime(java.sql.Time d,
                                java.util.Calendar cal,
                                boolean invertTimeZone)
DatatypeCoderTime value using a given Calendar.encodeTime in interface DatatypeCoderd - The Time to be encodedcal - The Calendar to be used in the encoding, may be nullTimepublic byte[] encodeTime(java.sql.Time d)
DatatypeCoderTime value into a byte array.encodeTime in interface DatatypeCoderd - The Time to be encodedbytes representing the given Timepublic byte[] encodeTimeRaw(DatatypeCoder.RawDateTimeStruct raw)
DatatypeCoderbyte array.encodeTimeRaw in interface DatatypeCoderraw - The RawDateTimeStruct to be encodedbytes representing the time of the given RawDateTimeStructpublic byte[] encodeTimeCalendar(java.sql.Time d,
                                 java.util.Calendar c)
encodeTimeCalendar in interface DatatypeCoderpublic java.sql.Time decodeTime(java.sql.Time d,
                                java.util.Calendar cal,
                                boolean invertTimeZone)
DatatypeCoderTime value using a given Calendar.decodeTime in interface DatatypeCoderd - The Time to be decodedcal - The Calendar to be used in the decoding, may be nullTimepublic java.sql.Time decodeTime(byte[] int_byte)
DatatypeCoderbyte array into a Time value.decodeTime in interface DatatypeCoderint_byte - The byte array to be decodedTimepublic DatatypeCoder.RawDateTimeStruct decodeTimeRaw(byte[] int_byte)
DatatypeCoderbyte array into a raw date time struct.decodeTimeRaw in interface DatatypeCoderint_byte - The byte array to be decodedDatatypeCoder.RawDateTimeStructpublic java.sql.Time decodeTimeCalendar(byte[] int_byte,
                                        java.util.Calendar c)
decodeTimeCalendar in interface DatatypeCoderpublic java.sql.Date encodeDate(java.sql.Date d,
                                java.util.Calendar cal)
DatatypeCoderDate value using a given Calendar.encodeDate in interface DatatypeCoderd - The Date to be encodedcal - The Calendar to be used in the encoding, may be nullDatepublic byte[] encodeDate(java.sql.Date d)
DatatypeCoderDate value into a byte array.encodeDate in interface DatatypeCoderd - The Date to be encodedbytes representing the given Datepublic byte[] encodeDateRaw(DatatypeCoder.RawDateTimeStruct raw)
DatatypeCoderbyte array.encodeDateRaw in interface DatatypeCoderraw - The RawDateTimeStruct to be encodedbytes representing the date of the given RawDateTimeStructpublic byte[] encodeDateCalendar(java.sql.Date d,
                                 java.util.Calendar c)
encodeDateCalendar in interface DatatypeCoderpublic java.sql.Date decodeDate(java.sql.Date d,
                                java.util.Calendar cal)
DatatypeCoderDate value using a given Calendar.decodeDate in interface DatatypeCoderd - The Date to be decodedcal - The Calendar to be used in the decoding, may be nullDatepublic java.sql.Date decodeDate(byte[] byte_int)
DatatypeCoderbyte array into a Date value.decodeDate in interface DatatypeCoderbyte_int - The byte array to be decodedDatepublic DatatypeCoder.RawDateTimeStruct decodeDateRaw(byte[] byte_int)
DatatypeCoderbyte array into a raw date time struct.decodeDateRaw in interface DatatypeCoderbyte_int - The byte array to be decodedDatatypeCoder.RawDateTimeStructpublic java.sql.Date decodeDateCalendar(byte[] byte_int,
                                        java.util.Calendar c)
decodeDateCalendar in interface DatatypeCoderpublic boolean decodeBoolean(byte[] data)
DatatypeCoderdecodeBoolean in interface DatatypeCoderdata - (expected) 1 bytesfalse when 0, true for all other valuespublic byte[] encodeBoolean(boolean value)
DatatypeCoderencodeBoolean in interface DatatypeCodervalue - Boolean value to encodetrue as 1, false as 0.public byte[] encodeLocalTime(int hour,
                              int minute,
                              int second,
                              int nanos)
DatatypeCoderencodeLocalTime in interface DatatypeCoderhour - Number of hours (is assumed to be 0..23)minute - Number of minutes (is assumed to be 0..59)second - Number of seconds (is assumed to be 0..59)nanos - Sub-second nanoseconds (actual resolution is 100 microseconds, is assumed to be 0 .. 10^9 - 1 ns)public byte[] encodeLocalDate(int year,
                              int month,
                              int day)
DatatypeCoderencodeLocalDate in interface DatatypeCoderyear - Yearmonth - Month (is assumed to be 1..12)day - Day (is assumed to be valid for year and month)public byte[] encodeLocalDateTime(int year,
                                  int month,
                                  int day,
                                  int hour,
                                  int minute,
                                  int second,
                                  int nanos)
DatatypeCoderencodeLocalDateTime in interface DatatypeCoderyear - Yearmonth - Month (is assumed to be 1..12)day - Day (is assumed to be valid for year and month)hour - Number of hours (is assumed to be 0..23)minute - Number of minutes (is assumed to be 0..59)second - Number of seconds (is assumed to be 0..59)nanos - Sub-second nanoseconds (actual resolution is 100 microseconds, is assumed to be 0 .. 10^9 - 1 ns)public Decimal64 decodeDecimal64(byte[] data)
DatatypeCoderdecodeDecimal64 in interface DatatypeCoderdata - Data to decode (expected 8 bytes)public byte[] encodeDecimal64(Decimal64 decimal64)
DatatypeCoderencodeDecimal64 in interface DatatypeCoderdecimal64 - The decimal64 value to be encodedpublic Decimal128 decodeDecimal128(byte[] data)
DatatypeCoderdecodeDecimal128 in interface DatatypeCoderdata - Data to decode (expected 16 bytes)public byte[] encodeDecimal128(Decimal128 decimal128)
DatatypeCoderencodeDecimal128 in interface DatatypeCoderdecimal128 - The decimal128 value to be encodedpublic java.math.BigInteger decodeInt128(byte[] data)
DatatypeCoderdecodeInt128 in interface DatatypeCoderdata - 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 DatatypeCoderbigInteger - The BigInteger value to be encodedpublic final IEncodingFactory getEncodingFactory()
getEncodingFactory in interface DatatypeCoderpublic final EncodingDefinition getEncodingDefinition()
getEncodingDefinition in interface DatatypeCoderpublic final Encoding getEncoding()
getEncoding in interface DatatypeCoderpublic final DatatypeCoder forEncodingDefinition(EncodingDefinition encodingDefinition)
DatatypeCoderforEncodingDefinition in interface DatatypeCoderencodingDefinition - Encoding definitionpublic DatatypeCoder unwrap()
DatatypeCoderunwrap in interface DatatypeCoderpublic final boolean equals(java.lang.Object o)
DatatypeCoderEquality: 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 DatatypeCoderequals in class java.lang.Objecto - Object to compare totrue if other is an equivalent datatype coder.public final int hashCode()
hashCode in interface DatatypeCoderhashCode in class java.lang.ObjectCopyright © 2001-2022 Jaybird (Firebird JDBC/JCA) team. All rights reserved.