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) |
Modifier and Type | Method and Description |
---|---|
boolean |
decodeBoolean(byte[] data)
Decode boolean from supplied data.
|
java.sql.Date |
decodeDate(byte[] byte_int)
Decode a
byte array into a Date value. |
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) |
DatatypeCoder.RawDateTimeStruct |
decodeDateRaw(byte[] byte_int)
Decode a
byte array into a raw date time struct. |
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. |
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. |
java.lang.String |
decodeString(byte[] value,
Encoding encoding,
java.lang.String mappingPath) |
java.lang.String |
decodeString(byte[] value,
java.lang.String javaEncoding,
java.lang.String mappingPath)
Decode an encoded
byte array into a String using a given encoding. |
java.sql.Time |
decodeTime(byte[] int_byte)
Decode a
byte array into a Time value. |
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) |
DatatypeCoder.RawDateTimeStruct |
decodeTimeRaw(byte[] int_byte)
Decode a
byte array into a raw date time struct. |
java.sql.Timestamp |
decodeTimestamp(byte[] byte_long)
Decode a 8-byte
byte array into a Timestamp . |
java.sql.Timestamp |
decodeTimestamp(java.sql.Timestamp value,
java.util.Calendar cal)
Decode a
Timestamp value using a given Calendar . |
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) |
DatatypeCoder.RawDateTimeStruct |
decodeTimestampRaw(byte[] byte_long)
Decode a 8-byte
byte array into a raw date time struct. |
byte[] |
encodeBoolean(boolean value)
Encodes boolean to 1 byte data.
|
byte[] |
encodeDate(java.sql.Date d)
Encode a
Date value into a byte array. |
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) |
byte[] |
encodeDateRaw(DatatypeCoder.RawDateTimeStruct raw)
Encode the date portion of a raw date time struct into 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. |
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
long value as a byte array. |
byte[] |
encodeShort(int value)
Encode a
short value as a byte array. |
byte[] |
encodeShort(short value)
Encode a
short value as a byte array. |
byte[] |
encodeString(java.lang.String value,
Encoding encoding,
java.lang.String mappingPath) |
byte[] |
encodeString(java.lang.String value,
java.lang.String javaEncoding,
java.lang.String mappingPath)
Encode a
String value into a byte array using a given encoding. |
byte[] |
encodeTime(java.sql.Time d)
Encode a
Time value into a byte array. |
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) |
byte[] |
encodeTimeRaw(DatatypeCoder.RawDateTimeStruct raw)
Encode the time portion of a raw date time struct into a
byte array. |
byte[] |
encodeTimestamp(java.sql.Timestamp value)
Encode a
Timestamp as a byte array. |
java.sql.Timestamp |
encodeTimestamp(java.sql.Timestamp value,
java.util.Calendar cal)
Encode a
Timestamp using a given Calendar . |
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) |
byte[] |
encodeTimestampRaw(DatatypeCoder.RawDateTimeStruct raw)
Encode the date and time portions of a raw date time struct into a
byte array. |
IEncodingFactory |
getEncodingFactory() |
protected byte[] |
intToBytes(int value)
Encode an
int value as a byte array in network-order(big-endian) representation. |
public DefaultDatatypeCoder(IEncodingFactory encodingFactory)
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 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 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
arrayprotected 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)
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 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 byte[] encodeString(java.lang.String value, java.lang.String javaEncoding, java.lang.String mappingPath) throws java.sql.SQLException
DatatypeCoder
String
value into a byte
array using a given encoding.encodeString
in interface DatatypeCoder
value
- The String
to be encodedjavaEncoding
- The java encoding to use in the encoding processmappingPath
- The character mapping path to be used in the encodingvalue
as a byte
arrayjava.sql.SQLException
- if the given encoding cannot be found, or an error
occurs during the encodingpublic byte[] encodeString(java.lang.String value, Encoding encoding, java.lang.String mappingPath) throws java.sql.SQLException
encodeString
in interface DatatypeCoder
java.sql.SQLException
public java.lang.String decodeString(byte[] value, java.lang.String javaEncoding, java.lang.String mappingPath) throws java.sql.SQLException
DatatypeCoder
byte
array into a String
using a given encoding.decodeString
in interface DatatypeCoder
value
- The value to be decodedjavaEncoding
- The java encoding to be used in the decoding processmappingPath
- The character mapping path to be used in the decodingString
java.sql.SQLException
- if the given encoding cannot be found, or an
error occurs during the decodingpublic java.lang.String decodeString(byte[] value, Encoding encoding, java.lang.String mappingPath) throws java.sql.SQLException
decodeString
in interface DatatypeCoder
java.sql.SQLException
public java.sql.Timestamp encodeTimestamp(java.sql.Timestamp value, java.util.Calendar cal)
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
public 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[] encodeTimestamp(java.sql.Timestamp value)
DatatypeCoder
Timestamp
as a byte
array.encodeTimestamp
in interface DatatypeCoder
value
- The Timestamp
to be encodedbyte
s that represents the given Timestamp
valuepublic 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)
encodeTimestampCalendar
in interface DatatypeCoder
public java.sql.Timestamp decodeTimestamp(java.sql.Timestamp value, java.util.Calendar cal)
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
Timestamp
public 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 java.sql.Timestamp decodeTimestamp(byte[] byte_long)
DatatypeCoder
byte
array into a Timestamp
.decodeTimestamp
in interface DatatypeCoder
byte_long
- The byte
array to be decodedTimestamp
value from the decoded bytespublic 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)
decodeTimestampCalendar
in interface DatatypeCoder
public 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[] encodeTime(java.sql.Time d)
DatatypeCoder
Time
value into a byte
array.encodeTime
in interface DatatypeCoder
d
- The Time
to be encodedbyte
s representing the given 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)
encodeTimeCalendar
in interface DatatypeCoder
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 java.sql.Time decodeTime(byte[] int_byte)
DatatypeCoder
byte
array into a Time
value.decodeTime
in interface DatatypeCoder
int_byte
- The byte
array to be decodedTime
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)
decodeTimeCalendar
in interface DatatypeCoder
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[] encodeDate(java.sql.Date d)
DatatypeCoder
Date
value into a byte
array.encodeDate
in interface DatatypeCoder
d
- The Date
to be encodedbyte
s representing the given 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)
encodeDateCalendar
in interface DatatypeCoder
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 java.sql.Date decodeDate(byte[] byte_int)
DatatypeCoder
byte
array into a Date
value.decodeDate
in interface DatatypeCoder
byte_int
- The byte
array to be decodedDate
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)
decodeDateCalendar
in interface DatatypeCoder
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 byte[] encodeLocalTime(int hour, int minute, int second, int nanos)
DatatypeCoder
encodeLocalTime
in interface DatatypeCoder
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 byte[] encodeLocalDate(int year, int month, int day)
DatatypeCoder
encodeLocalDate
in interface DatatypeCoder
year
- 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)
DatatypeCoder
encodeLocalDateTime
in interface DatatypeCoder
year
- 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 IEncodingFactory getEncodingFactory()
getEncodingFactory
in interface DatatypeCoder
Copyright © 2001-2021 Jaybird (Firebird JDBC/JCA) team. All rights reserved.