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
  • Constructor Details

    • 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 Details

    • forEncodingFactory

      public static LittleEndianDatatypeCoder forEncodingFactory(IEncodingFactory encodingFactory)
      Returns an instance of LittleEndianDatatypeCoder 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 interface DatatypeCoder
      Overrides:
      sizeOfShort in class DefaultDatatypeCoder
      Returns:
      The size of an encoded short (either 2 or 4 bytes)
    • encodeShort

      public byte[] encodeShort(short value)
      Description copied from interface: DatatypeCoder
      Encode a short value as a byte array.
      Specified by:
      encodeShort in interface DatatypeCoder
      Overrides:
      encodeShort in class DefaultDatatypeCoder
      Parameters:
      value - The value to be encoded
      Returns:
      The value of value encoded as a byte array
      See Also:
    • encodeShort

      public void encodeShort(int value, byte[] target, int fromIndex)
      Description copied from interface: DatatypeCoder
      Encode a short value into the target byte array starting at index fromIndex.
      Specified by:
      encodeShort in interface DatatypeCoder
      Overrides:
      encodeShort in class DefaultDatatypeCoder
      Parameters:
      value - The value to be encoded
      target - 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 a byte array into a short value.
      Specified by:
      decodeShort in interface DatatypeCoder
      Overrides:
      decodeShort in class DefaultDatatypeCoder
      Parameters:
      byte_int - The byte array to be decoded
      Returns:
      The short value of the decoded byte array
    • decodeShort

      public short decodeShort(byte[] bytes, int fromIndex)
      Description copied from interface: DatatypeCoder
      Decode from a byte array to a short value.
      Specified by:
      decodeShort in interface DatatypeCoder
      Overrides:
      decodeShort in class DefaultDatatypeCoder
      Parameters:
      bytes - The byte array to be decoded
      fromIndex - The index to start reading
      Returns:
      The short value of the decoded byte array
    • encodeInt

      public byte[] encodeInt(int value)
      Description copied from interface: DatatypeCoder
      Encode an int value as a byte array.
      Specified by:
      encodeInt in interface DatatypeCoder
      Overrides:
      encodeInt in class DefaultDatatypeCoder
      Parameters:
      value - The value to be encoded
      Returns:
      The value of value encoded as a byte array
    • encodeInt

      public void encodeInt(int value, byte[] target, int fromIndex)
      Description copied from interface: DatatypeCoder
      Encode an int value into the target byte array starting at index fromIndex.
      Specified by:
      encodeInt in interface DatatypeCoder
      Overrides:
      encodeInt in class DefaultDatatypeCoder
      Parameters:
      value - The value to be encoded
      target - Target byte array of sufficient size
      fromIndex - Index to start writing
    • decodeInt

      public int decodeInt(byte[] byte_int)
      Description copied from interface: DatatypeCoder
      Decode a byte array into an int value.
      Specified by:
      decodeInt in interface DatatypeCoder
      Overrides:
      decodeInt in class DefaultDatatypeCoder
      Parameters:
      byte_int - The byte array to be decoded
      Returns:
      The int value of the decoded byte array
    • decodeInt

      public int decodeInt(byte[] bytes, int fromIndex)
      Description copied from interface: DatatypeCoder
      Decode a byte array to an int value.
      Specified by:
      decodeInt in interface DatatypeCoder
      Overrides:
      decodeInt in class DefaultDatatypeCoder
      Parameters:
      bytes - The byte array to be decoded
      fromIndex - The index to start reading
      Returns:
      The int value of the decoded byte array
    • encodeLong

      public byte[] encodeLong(long value)
      Description copied from interface: DatatypeCoder
      Encode a long value as a byte array.
      Specified by:
      encodeLong in interface DatatypeCoder
      Overrides:
      encodeLong in class DefaultDatatypeCoder
      Parameters:
      value - The value to be encoded
      Returns:
      The value of value encoded as a byte array
    • decodeLong

      public long decodeLong(byte[] byte_int)
      Description copied from interface: DatatypeCoder
      Decode a byte array into a long value.
      Specified by:
      decodeLong in interface DatatypeCoder
      Overrides:
      decodeLong in class DefaultDatatypeCoder
      Parameters:
      byte_int - The byte array to be decoded
      Returns:
      The long value of the decoded byte array
    • decodeDecimal64

      public Decimal64 decodeDecimal64(byte[] data)
      Description copied from interface: DatatypeCoder
      Decodes a decimal64 from byte array.
      Specified by:
      decodeDecimal64 in interface DatatypeCoder
      Overrides:
      decodeDecimal64 in class DefaultDatatypeCoder
      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 interface DatatypeCoder
      Overrides:
      encodeDecimal64 in class DefaultDatatypeCoder
      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 interface DatatypeCoder
      Overrides:
      decodeDecimal128 in class DefaultDatatypeCoder
      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 interface DatatypeCoder
      Overrides:
      encodeDecimal128 in class DefaultDatatypeCoder
      Parameters:
      decimal128 - The decimal128 value to be encoded
      Returns:
      Byte array for decimal128 value
    • decodeInt128

      public BigInteger decodeInt128(byte[] data)
      Description copied from interface: DatatypeCoder
      Decodes a BigInteger from byte array.
      Specified by:
      decodeInt128 in interface DatatypeCoder
      Overrides:
      decodeInt128 in class DefaultDatatypeCoder
      Parameters:
      data - Data to decode (expected 16 bytes)
      Returns:
      BigInteger value
    • encodeInt128

      public byte[] encodeInt128(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 interface DatatypeCoder
      Overrides:
      encodeInt128 in class DefaultDatatypeCoder
      Parameters:
      bigInteger - The BigInteger value to be encoded
      Returns:
      Byte array for bigInteger value