Package org.firebirdsql.gds.ng.jna
Class LittleEndianDatatypeCoder
- java.lang.Object
-
- org.firebirdsql.gds.ng.DefaultDatatypeCoder
-
- org.firebirdsql.gds.ng.jna.LittleEndianDatatypeCoder
-
- All Implemented Interfaces:
DatatypeCoder
public final class LittleEndianDatatypeCoder extends DefaultDatatypeCoder
Datatype encoder and decoder for little endian platforms, specifically for use with the Firebird client library.For wire protocol use
DefaultDatatypeCoder
.- Since:
- 3.0
- Author:
- Mark Rotteveel
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.firebirdsql.gds.ng.DatatypeCoder
DatatypeCoder.RawDateTimeStruct
-
-
Field Summary
-
Fields inherited from interface org.firebirdsql.gds.ng.DatatypeCoder
FRACTIONS_PER_HOUR, FRACTIONS_PER_MILLISECOND, FRACTIONS_PER_MINUTE, FRACTIONS_PER_SECOND, NANOSECONDS_PER_FRACTION
-
-
Constructor Summary
Constructors Constructor Description LittleEndianDatatypeCoder(IEncodingFactory encodingFactory)
Creates a little-endian datatype coder for native access on little-endian platforms.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Decimal128
decodeDecimal128(byte[] data)
Decodes a decimal128 from byte array.Decimal64
decodeDecimal64(byte[] data)
Decodes a decimal64 from byte array.int
decodeInt(byte[] byte_int)
Decode abyte
array into anint
value.int
decodeInt(byte[] bytes, int fromIndex)
Decode abyte
array to anint
value.java.math.BigInteger
decodeInt128(byte[] data)
Decodes a BigInteger from byte array.long
decodeLong(byte[] byte_int)
Decode abyte
array into along
value.short
decodeShort(byte[] byte_int)
Decode abyte
array into ashort
value.short
decodeShort(byte[] bytes, int fromIndex)
Decode from abyte
array to ashort
value.byte[]
encodeDecimal128(Decimal128 decimal128)
Encodes a decimal128 to a byte array.byte[]
encodeDecimal64(Decimal64 decimal64)
Encodes a decimal64 to a byte array.byte[]
encodeInt(int value)
Encode anint
value as abyte
array.void
encodeInt(int value, byte[] target, int fromIndex)
Encode anint
value into thetarget
byte array starting at indexfromIndex
.byte[]
encodeInt128(java.math.BigInteger bigInteger)
Encodes a BigInteger to a 16-byte byte array.byte[]
encodeLong(long value)
Encode along
value as abyte
array.void
encodeShort(int value, byte[] target, int fromIndex)
Encode ashort
value into thetarget
byte array starting at indexfromIndex
.byte[]
encodeShort(short value)
Encode ashort
value as abyte
array.static LittleEndianDatatypeCoder
forEncodingFactory(IEncodingFactory encodingFactory)
Returns an instance ofLittleEndianDatatypeCoder
for an encoding factory.int
sizeOfShort()
The size of an encoded short in this data type coder.-
Methods inherited from class org.firebirdsql.gds.ng.DefaultDatatypeCoder
createReader, createWriter, decodeBoolean, decodeDate, decodeDateCalendar, decodeDateRaw, decodeDouble, decodeFloat, decodeLocalDate, decodeLocalDateTime, decodeLocalTime, decodeString, decodeTime, decodeTimeCalendar, decodeTimeRaw, decodeTimestamp, decodeTimestampCalendar, decodeTimestampRaw, encodeBoolean, encodeDate, encodeDateCalendar, encodeDateRaw, encodeDouble, encodeFloat, encodeLocalDate, encodeLocalDateTime, encodeLocalTime, encodeShort, encodeString, encodeTime, encodeTimeCalendar, encodeTimeRaw, encodeTimestamp, encodeTimestampCalendar, encodeTimestampRaw, equals, forEncodingDefinition, getEncoding, getEncodingDefinition, getEncodingFactory, hashCode, intToBytes, unwrap
-
-
-
-
Constructor Detail
-
LittleEndianDatatypeCoder
public LittleEndianDatatypeCoder(IEncodingFactory encodingFactory)
Creates a little-endian datatype coder for native access on little-endian platforms.In almost all cases, it is better to use
forEncodingFactory(IEncodingFactory)
.- Parameters:
encodingFactory
- Encoding factory
-
-
Method Detail
-
forEncodingFactory
public static LittleEndianDatatypeCoder forEncodingFactory(IEncodingFactory encodingFactory)
Returns an instance ofLittleEndianDatatypeCoder
for an encoding factory.- Parameters:
encodingFactory
- Encoding factory- Returns:
- Datatype coder, this might be a cached instance
-
sizeOfShort
public int sizeOfShort()
Description copied from interface:DatatypeCoder
The size of an encoded short in this data type coder.- Specified by:
sizeOfShort
in interfaceDatatypeCoder
- Overrides:
sizeOfShort
in classDefaultDatatypeCoder
- Returns:
- The size of an encoded short (either
2
or4
bytes)
-
encodeShort
public byte[] encodeShort(short value)
Description copied from interface:DatatypeCoder
Encode ashort
value as abyte
array.- Specified by:
encodeShort
in interfaceDatatypeCoder
- Overrides:
encodeShort
in classDefaultDatatypeCoder
- Parameters:
value
- The value to be encoded- Returns:
- The value of
value
encoded as abyte
array - See Also:
DatatypeCoder.encodeShort(int)
-
encodeShort
public void encodeShort(int value, byte[] target, int fromIndex)
Description copied from interface:DatatypeCoder
Encode ashort
value into thetarget
byte array starting at indexfromIndex
.- Specified by:
encodeShort
in interfaceDatatypeCoder
- Overrides:
encodeShort
in classDefaultDatatypeCoder
- 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
-
decodeShort
public short decodeShort(byte[] byte_int)
Description copied from interface:DatatypeCoder
Decode abyte
array into ashort
value.- Specified by:
decodeShort
in interfaceDatatypeCoder
- Overrides:
decodeShort
in classDefaultDatatypeCoder
- Parameters:
byte_int
- Thebyte
array to be decoded- Returns:
- The
short
value of the decodedbyte
array
-
decodeShort
public short decodeShort(byte[] bytes, int fromIndex)
Description copied from interface:DatatypeCoder
Decode from abyte
array to ashort
value.- Specified by:
decodeShort
in interfaceDatatypeCoder
- Overrides:
decodeShort
in classDefaultDatatypeCoder
- Parameters:
bytes
- Thebyte
array to be decodedfromIndex
- The index to start reading- Returns:
- The
short
value of the decodedbyte
array
-
encodeInt
public byte[] encodeInt(int value)
Description copied from interface:DatatypeCoder
Encode anint
value as abyte
array.- Specified by:
encodeInt
in interfaceDatatypeCoder
- Overrides:
encodeInt
in classDefaultDatatypeCoder
- Parameters:
value
- The value to be encoded- Returns:
- The value of
value
encoded as abyte
array
-
encodeInt
public void encodeInt(int value, byte[] target, int fromIndex)
Description copied from interface:DatatypeCoder
Encode anint
value into thetarget
byte array starting at indexfromIndex
.- Specified by:
encodeInt
in interfaceDatatypeCoder
- Overrides:
encodeInt
in classDefaultDatatypeCoder
- Parameters:
value
- The value to be encodedtarget
- Target byte array of sufficient sizefromIndex
- Index to start writing
-
decodeInt
public int decodeInt(byte[] byte_int)
Description copied from interface:DatatypeCoder
Decode abyte
array into anint
value.- Specified by:
decodeInt
in interfaceDatatypeCoder
- Overrides:
decodeInt
in classDefaultDatatypeCoder
- Parameters:
byte_int
- Thebyte
array to be decoded- Returns:
- The
int
value of the decodedbyte
array
-
decodeInt
public int decodeInt(byte[] bytes, int fromIndex)
Description copied from interface:DatatypeCoder
Decode abyte
array to anint
value.- Specified by:
decodeInt
in interfaceDatatypeCoder
- Overrides:
decodeInt
in classDefaultDatatypeCoder
- Parameters:
bytes
- Thebyte
array to be decodedfromIndex
- The index to start reading- Returns:
- The
int
value of the decodedbyte
array
-
encodeLong
public byte[] encodeLong(long value)
Description copied from interface:DatatypeCoder
Encode along
value as abyte
array.- Specified by:
encodeLong
in interfaceDatatypeCoder
- Overrides:
encodeLong
in classDefaultDatatypeCoder
- Parameters:
value
- The value to be encoded- Returns:
- The value of
value
encoded as abyte
array
-
decodeLong
public long decodeLong(byte[] byte_int)
Description copied from interface:DatatypeCoder
Decode abyte
array into along
value.- Specified by:
decodeLong
in interfaceDatatypeCoder
- Overrides:
decodeLong
in classDefaultDatatypeCoder
- Parameters:
byte_int
- Thebyte
array to be decoded- Returns:
- The
long
value of the decodedbyte
array
-
decodeDecimal64
public Decimal64 decodeDecimal64(byte[] data)
Description copied from interface:DatatypeCoder
Decodes a decimal64 from byte array.- Specified by:
decodeDecimal64
in interfaceDatatypeCoder
- Overrides:
decodeDecimal64
in classDefaultDatatypeCoder
- Parameters:
data
- Data to decode (expected 8 bytes)- Returns:
- Decimal64 value
-
encodeDecimal64
public byte[] encodeDecimal64(Decimal64 decimal64)
Description copied from interface:DatatypeCoder
Encodes a decimal64 to a byte array.- Specified by:
encodeDecimal64
in interfaceDatatypeCoder
- Overrides:
encodeDecimal64
in classDefaultDatatypeCoder
- Parameters:
decimal64
- The decimal64 value to be encoded- Returns:
- Byte array for decimal64 value
-
decodeDecimal128
public Decimal128 decodeDecimal128(byte[] data)
Description copied from interface:DatatypeCoder
Decodes a decimal128 from byte array.- Specified by:
decodeDecimal128
in interfaceDatatypeCoder
- Overrides:
decodeDecimal128
in classDefaultDatatypeCoder
- Parameters:
data
- Data to decode (expected 16 bytes)- Returns:
- Decimal128 value
-
encodeDecimal128
public byte[] encodeDecimal128(Decimal128 decimal128)
Description copied from interface:DatatypeCoder
Encodes a decimal128 to a byte array.- Specified by:
encodeDecimal128
in interfaceDatatypeCoder
- Overrides:
encodeDecimal128
in classDefaultDatatypeCoder
- Parameters:
decimal128
- The decimal128 value to be encoded- Returns:
- Byte array for decimal128 value
-
decodeInt128
public java.math.BigInteger decodeInt128(byte[] data)
Description copied from interface:DatatypeCoder
Decodes a BigInteger from byte array.- Specified by:
decodeInt128
in interfaceDatatypeCoder
- Overrides:
decodeInt128
in classDefaultDatatypeCoder
- Parameters:
data
- Data to decode (expected 16 bytes)- Returns:
- BigInteger value
-
encodeInt128
public byte[] encodeInt128(java.math.BigInteger bigInteger)
Description copied from interface:DatatypeCoder
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
IllegalArgumentException
is thrown.- Specified by:
encodeInt128
in interfaceDatatypeCoder
- Overrides:
encodeInt128
in classDefaultDatatypeCoder
- Parameters:
bigInteger
- The BigInteger value to be encoded- Returns:
- Byte array for bigInteger value
-
-