Package org.firebirdsql.gds.ng
Interface DatatypeCoder
- All Known Implementing Classes:
BigEndianDatatypeCoder,DefaultDatatypeCoder,EncodingSpecificDatatypeCoder,LittleEndianDatatypeCoder
public interface DatatypeCoder
Interface defining the encoding and decoding for Firebird (numerical) data types.
- Since:
- 3.0
- Author:
- Mark Rotteveel
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classRaw date/time value. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptioncreateReader(InputStream inputStream) Creates a reader wrapping an input stream.createWriter(OutputStream outputStream) Creates a writer wrapping an input stream.booleandecodeBoolean(byte[] data) Decode boolean from supplied data.decodeDate(byte[] byte_int) Decode abytearray into aDatevalue.decodeDate(Date d, Calendar cal) Decode aDatevalue using a givenCalendar.decodeDateCalendar(byte[] byte_int, Calendar c) decodeDateRaw(byte[] byte_int) Decode abytearray into a raw date time struct.decodeDecimal128(byte[] data) Decodes a decimal128 from byte array.decodeDecimal64(byte[] data) Decodes a decimal64 from byte array.doubledecodeDouble(byte[] byte_int) Decode abytearray into adoublevalue.floatdecodeFloat(byte[] byte_int) Decode abytearray into afloatvalue.intdecodeInt(byte[] byte_int) Decode abytearray into anintvalue.intdecodeInt(byte[] bytes, int fromIndex) Decode abytearray to anintvalue.decodeInt128(byte[] data) Decodes a BigInteger from byte array.longdecodeLong(byte[] byte_int) Decode abytearray into alongvalue.shortdecodeShort(byte[] byte_int) Decode abytearray into ashortvalue.shortdecodeShort(byte[] bytes, int fromIndex) Decode from abytearray to ashortvalue.decodeString(byte[] value) Decode an encodedbytearray into aStringusing the encoding of this datatype coder.decodeTime(byte[] int_byte) Decode abytearray into aTimevalue.decodeTime(Time d, Calendar cal, boolean invertTimeZone) Decode aTimevalue using a givenCalendar.decodeTimeCalendar(byte[] int_byte, Calendar c) decodeTimeRaw(byte[] int_byte) Decode abytearray into a raw date time struct.decodeTimestamp(byte[] byte_long) Decode a 8-bytebytearray into aTimestamp.decodeTimestamp(Timestamp value, Calendar cal) Decode aTimestampvalue using a givenCalendar.decodeTimestamp(Timestamp value, Calendar cal, boolean invertTimeZone) Decode aTimestampvalue using a givenCalendar.decodeTimestampCalendar(byte[] byte_long, Calendar c) decodeTimestampRaw(byte[] byte_long) Decode a 8-bytebytearray into a raw date time struct.byte[]encodeBoolean(boolean value) Encodes boolean to 1 byte data.byte[]encodeDate(Date d) Encode aDatevalue into abytearray.encodeDate(Date d, Calendar cal) Encode a givenDatevalue using a givenCalendar.byte[]encodeDateCalendar(Date d, Calendar c) byte[]Encode the date portion of a raw date time struct into abytearray.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 adoublevalue as abytearray.byte[]encodeFloat(float value) Encode afloatvalue as abytearray.byte[]encodeInt(int value) Encode anintvalue as abytearray.voidencodeInt(int value, byte[] target, int fromIndex) Encode anintvalue into thetargetbyte array starting at indexfromIndex.byte[]encodeInt128(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 alongvalue as abytearray.byte[]encodeShort(int value) Encode ashortvalue as abytearray.voidencodeShort(int value, byte[] target, int fromIndex) Encode ashortvalue into thetargetbyte array starting at indexfromIndex.byte[]encodeShort(short value) Encode ashortvalue as abytearray.byte[]encodeString(String value) Encode aStringvalue into abytearray using the encoding of this datatype coder.byte[]encodeTime(Time d) Encode aTimevalue into abytearray.encodeTime(Time d, Calendar cal, boolean invertTimeZone) Encode a givenTimevalue using a givenCalendar.byte[]encodeTimeCalendar(Time d, Calendar c) byte[]Encode the time portion of a raw date time struct into abytearray.byte[]encodeTimestamp(Timestamp value) Encode aTimestampas abytearray.encodeTimestamp(Timestamp value, Calendar cal) Encode aTimestampusing a givenCalendar.encodeTimestamp(Timestamp value, Calendar cal, boolean invertTimeZone) Encode aTimestampusing a givenCalendar.byte[]encodeTimestampCalendar(Timestamp value, Calendar c) byte[]Encode the date and time portions of a raw date time struct into abytearray.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:
- The size of an encoded short (either
2or4bytes) - Since:
- 4.0
-
encodeShort
byte[] encodeShort(short value) Encode ashortvalue as abytearray.- Parameters:
value- The value to be encoded- Returns:
- The value of
valueencoded as abytearray - See Also:
-
encodeShort
byte[] encodeShort(int value) Encode ashortvalue as abytearray.- Parameters:
value- The value to be encoded- Returns:
- The value of
valueencoded as abytearray
-
encodeShort
void encodeShort(int value, byte[] target, int fromIndex) Encode ashortvalue into thetargetbyte array starting at indexfromIndex.- Parameters:
value- The value to be encodedtarget- Target byte array of sufficient size (warning: this may be datatype coder specific)fromIndex- Index to start writing- Since:
- 4.0
-
decodeShort
short decodeShort(byte[] byte_int) Decode abytearray into ashortvalue.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The
shortvalue of the decodedbytearray
-
decodeShort
short decodeShort(byte[] bytes, int fromIndex) Decode from abytearray to ashortvalue.- Parameters:
bytes- Thebytearray to be decodedfromIndex- The index to start reading- Returns:
- The
shortvalue of the decodedbytearray - Since:
- 4.0
-
encodeInt
byte[] encodeInt(int value) Encode anintvalue as abytearray.- Parameters:
value- The value to be encoded- Returns:
- The value of
valueencoded as abytearray
-
encodeInt
void encodeInt(int value, byte[] target, int fromIndex) Encode anintvalue into thetargetbyte array starting at indexfromIndex.- Parameters:
value- The value to be encodedtarget- Target byte array of sufficient sizefromIndex- Index to start writing- Since:
- 4.0
-
decodeInt
int decodeInt(byte[] byte_int) Decode abytearray into anintvalue.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The
intvalue of the decodedbytearray
-
decodeInt
int decodeInt(byte[] bytes, int fromIndex) Decode abytearray to anintvalue.- Parameters:
bytes- Thebytearray to be decodedfromIndex- The index to start reading- Returns:
- The
intvalue of the decodedbytearray - Since:
- 4.0
-
encodeLong
byte[] encodeLong(long value) Encode alongvalue as abytearray.- Parameters:
value- The value to be encoded- Returns:
- The value of
valueencoded as abytearray
-
decodeLong
long decodeLong(byte[] byte_int) Decode abytearray into alongvalue.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The
longvalue of the decodedbytearray
-
encodeFloat
byte[] encodeFloat(float value) Encode afloatvalue as abytearray.- Parameters:
value- The value to be encoded- Returns:
- The value of
valueencoded as abytearray
-
decodeFloat
float decodeFloat(byte[] byte_int) Decode abytearray into afloatvalue.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The
floatvalue of the decodedbytearray
-
encodeDouble
byte[] encodeDouble(double value) Encode adoublevalue as abytearray.- Parameters:
value- The value to be encoded- Returns:
- The value of
valueencoded as abytearray
-
decodeDouble
double decodeDouble(byte[] byte_int) Decode abytearray into adoublevalue.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The
doublevalue of the decodedbytearray
-
encodeString
Encode aStringvalue into abytearray using the encoding of this datatype coder.- Parameters:
value- TheStringto be encoded- Returns:
- The value of
valueas abytearray - Since:
- 4.0
-
createWriter
Creates a writer wrapping an input stream.- Parameters:
outputStream- Input stream- Returns:
- Writer applying the encoding of this datatype when writing
- Since:
- 4.0
-
decodeString
Decode an encodedbytearray into aStringusing the encoding of this datatype coder.- Parameters:
value- The value to be decoded- Returns:
- The decoded
String - Since:
- 4.0
-
createReader
Creates a reader wrapping an input stream.- Parameters:
inputStream- Input stream- Returns:
- Reader applying the encoding of this datatype coder when reading
- Since:
- 4.0
-
encodeTimestamp
Encode aTimestampusing a givenCalendar.- Parameters:
value- TheTimestampto be encodedcal- TheCalendarto be used for encoding, may benull
-
encodeTimestamp
Encode aTimestampusing a givenCalendar.- Parameters:
value- TheTimestampto be encodedcal- TheCalendarto be used for encoding, may benullinvertTimeZone- Iftrue, the timezone offset value will be subtracted from the encoded value, otherwise it will be added- Returns:
- The encoded
Timestamp
-
encodeTimestamp
Encode aTimestampas abytearray.- Parameters:
value- TheTimestampto be encoded- Returns:
- The array of
bytes that represents the givenTimestampvalue
-
encodeTimestampRaw
Encode the date and time portions of a raw date time struct into abytearray.- Parameters:
raw- TheRawDateTimeStructto be encoded- Returns:
- The array of
bytes representing the date and time of the givenRawDateTimeStruct
-
encodeTimestampCalendar
-
decodeTimestamp
Decode aTimestampvalue using a givenCalendar.- Parameters:
value- TheTimestampto be decodedcal- TheCalendarto be used in decoding, may benull- Returns:
- The decoded
Timestamp
-
decodeTimestamp
Decode aTimestampvalue using a givenCalendar.- Parameters:
value- TheTimestampto be decodedcal- TheCalendarto be used in decoding, may benullinvertTimeZone- Iftrue, the timezone offset value will be subtracted from the decoded value, otherwise it will be added- Returns:
- The encoded
Timestamp
-
decodeTimestamp
Decode a 8-bytebytearray into aTimestamp.- Parameters:
byte_long- Thebytearray to be decoded- Returns:
- A
Timestampvalue from the decoded bytes
-
decodeTimestampRaw
Decode a 8-bytebytearray into a raw date time struct.- Parameters:
byte_long- Thebytearray to be decoded- Returns:
- A
DatatypeCoder.RawDateTimeStruct.
-
decodeTimestampCalendar
-
encodeTime
Encode a givenTimevalue using a givenCalendar.- Parameters:
d- TheTimeto be encodedcal- TheCalendarto be used in the encoding, may benull- Returns:
- The encoded
Time
-
encodeTime
Encode aTimevalue into abytearray.- Parameters:
d- TheTimeto be encoded- Returns:
- The array of
bytes representing the givenTime
-
encodeTimeRaw
Encode the time portion of a raw date time struct into abytearray.- Parameters:
raw- TheRawDateTimeStructto be encoded- Returns:
- The array of
bytes representing the time of the givenRawDateTimeStruct
-
encodeTimeCalendar
-
decodeTime
Decode aTimevalue using a givenCalendar.- Parameters:
d- TheTimeto be decodedcal- TheCalendarto be used in the decoding, may benull- Returns:
- The decooded
Time
-
decodeTime
Decode abytearray into aTimevalue.- Parameters:
int_byte- Thebytearray to be decoded- Returns:
- The decoded
Time
-
decodeTimeRaw
Decode abytearray into a raw date time struct.- Parameters:
int_byte- Thebytearray to be decoded- Returns:
- The
DatatypeCoder.RawDateTimeStruct
-
decodeTimeCalendar
-
encodeDate
Encode a givenDatevalue using a givenCalendar.- Parameters:
d- TheDateto be encodedcal- TheCalendarto be used in the encoding, may benull- Returns:
- The encoded
Date
-
encodeDate
Encode aDatevalue into abytearray.- Parameters:
d- TheDateto be encoded- Returns:
- The array of
bytes representing the givenDate
-
encodeDateRaw
Encode the date portion of a raw date time struct into abytearray.- Parameters:
raw- TheRawDateTimeStructto be encoded- Returns:
- The array of
bytes representing the date of the givenRawDateTimeStruct
-
encodeDateCalendar
-
decodeDate
Decode aDatevalue using a givenCalendar.- Parameters:
d- TheDateto be decodedcal- TheCalendarto be used in the decoding, may benull- Returns:
- The decoded
Date
-
decodeDate
Decode abytearray into aDatevalue.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The decoded
Date
-
decodeDateRaw
Decode abytearray into a raw date time struct.- Parameters:
byte_int- Thebytearray to be decoded- Returns:
- The
DatatypeCoder.RawDateTimeStruct
-
decodeDateCalendar
-
decodeBoolean
boolean decodeBoolean(byte[] data) Decode boolean from supplied data.- Parameters:
data- (expected) 1 bytes- Returns:
falsewhen 0,truefor all other values
-
encodeBoolean
byte[] encodeBoolean(boolean value) Encodes boolean to 1 byte data.- Parameters:
value- Boolean value to encode- Returns:
trueas 1,falseas 0.
-
encodeLocalTime
byte[] encodeLocalTime(int hour, int minute, int second, int nanos) Encodes a java.time.LocalTime equivalent to time bytes.- Parameters:
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)- Returns:
- Byte array for time
-
encodeLocalDate
byte[] encodeLocalDate(int year, int month, int day) Encodes a java.time.LocalDate equivalent to date bytes.- Parameters:
year- Yearmonth- Month (is assumed to be 1..12)day- Day (is assumed to be valid for year and month)- Returns:
- Byte array for date
-
encodeLocalDateTime
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.- Parameters:
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)- Returns:
- Byte array for timestamp
-
decodeDecimal64
Decodes a decimal64 from byte array.- Parameters:
data- Data to decode (expected 8 bytes)- Returns:
- Decimal64 value
-
encodeDecimal64
Encodes a decimal64 to a byte array.- Parameters:
decimal64- The decimal64 value to be encoded- Returns:
- Byte array for decimal64 value
-
decodeDecimal128
Decodes a decimal128 from byte array.- Parameters:
data- Data to decode (expected 16 bytes)- Returns:
- Decimal128 value
-
encodeDecimal128
Encodes a decimal128 to a byte array.- Parameters:
decimal128- The decimal128 value to be encoded- Returns:
- Byte array for decimal128 value
-
decodeInt128
Decodes a BigInteger from byte array.- Parameters:
data- Data to decode (expected 16 bytes)- Returns:
- BigInteger value
-
encodeInt128
Encodes a BigInteger to a 16-byte byte array.The implementation expects to be passed a value that fits in 16 bytes. If a larger value is passed, and
IllegalArgumentExceptionis thrown.- Parameters:
bigInteger- The BigInteger value to be encoded- Returns:
- Byte array for bigInteger value
-
getEncodingFactory
IEncodingFactory getEncodingFactory()- Returns:
- The encoding factory.
-
getEncodingDefinition
EncodingDefinition getEncodingDefinition()- Returns:
- The encoding definition used by this datatype coder for string conversions.
-
getEncoding
Encoding getEncoding()- Returns:
- The 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 (may be this instance if encoding definition is the same)
- Since:
- 4.0
-
unwrap
DatatypeCoder unwrap()Unwrap this datatype coder to its parent (or itself).- Returns:
- Return the parent of this datatype code, or itself if it has no parent.
- Since:
- 4.0
-
equals
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.
-
hashCode
int hashCode()
-