Package org.mariadb.jdbc.plugin

## Interface Codec<T>

Type Parameters:
  `T` - java type supported

All Known Implementing Classes:
  `BigDecimalCodec`, `BigIntegerCodec`, `BitSetCodec`, `BlobCodec`, `BooleanCodec`, `ByteArrayCodec`, `ByteCodec`, `ClobCodec`, `DateCodec`, `DoubleCodec`, `DurationCodec`, `FloatCodec`, `GeometryCollectionCodec`, `InstantCodec`, `IntCodec`, `LineStringCodec`, `LocalDateCodec`, `LocalDateTimeCodec`, `LocalTimeCodec`, `LongCodec`, `MultiLinestringCodec`, `MultiPointCodec`, `MultiPolygonCodec`, `OffsetDateTimeCodec`, `PointCodec`, `PolygonCodec`, `ReaderCodec`, `ShortCodec`, `StreamCodec`, `StringCodec`, `TimeCodec`, `TimestampCodec`, `UuidCodec`, `ZonedDateTimeCodec`

    public interface Codec<T>

Codec interface, to describe how a certain type of data must be encoded / decoded

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`boolean` `canDecode​(org.mariadb.jdbc.client.ColumnDecoder column, Class<?> type)` If codec can decode this a server datatype to a java class type
`boolean` `canEncode​(Object value)` Can Codec encode the java object type
`default boolean` `canEncodeLongData()` Indicate if can encode long data
`String` `className()` Codec native type
`T` `decodeBinary​(org.mariadb.jdbc.client.ReadableByteBuf buffer, MutableInt fieldLength, org.mariadb.jdbc.client.ColumnDecoder column, Calendar cal, org.mariadb.jdbc.client.Context context)` Decode from a mysql packet binary encoded a value to codec java type
`T` `decodeText​(org.mariadb.jdbc.client.ReadableByteBuf buffer, MutableInt fieldLength, org.mariadb.jdbc.client.ColumnDecoder column, Calendar cal, org.mariadb.jdbc.client.Context context)` Decode from a mysql packet text encoded a value to codec java type
`void` `encodeBinary​(Writer encoder, org.mariadb.jdbc.client.Context context, Object value, Calendar cal, Long length)` Binary encode value to writer
`default byte[]` `encodeData​(T value, Long length)` binary encoding value to a byte[]
`default void` `encodeLongData​(Writer encoder, T value, Long length)` binary encoding value to a long data packet
`void` `encodeText​(Writer encoder, org.mariadb.jdbc.client.Context context, Object value, Calendar cal, Long length)` Text encode value to writer
`int` `getBinaryEncodeType()` Return server encoding data type

### Method Detail

#### className

    String className()

Codec native type

Returns:
  code native return type

#### canDecode

    boolean canDecode​(org.mariadb.jdbc.client.ColumnDecoder column,
                      Class<?> type)

If codec can decode this a server datatype to a java class type

Parameters:
  `column` - server datatype
  `type` - java return class
Returns:
  true if codec can decode it

#### canEncode

    boolean canEncode​(Object value)

Can Codec encode the java object type

Parameters:
  `value` - java object type
Returns:
  true if codec can encode java type

#### decodeText

    T decodeText​(org.mariadb.jdbc.client.ReadableByteBuf buffer,
                 MutableInt fieldLength,
                 org.mariadb.jdbc.client.ColumnDecoder column,
                 Calendar cal,
                 org.mariadb.jdbc.client.Context context)
          throws SQLDataException

Decode from a mysql packet text encoded a value to codec java type

Parameters:
  `buffer` - mysql packet buffer
  `fieldLength` - encoded value length
  `column` - server column metadata
  `cal` - calendar
  `context` - connection context
Returns:
  decoded value
Throws:
  `SQLDataException` - if unexpected error occurs during decoding

#### decodeBinary

    T decodeBinary​(org.mariadb.jdbc.client.ReadableByteBuf buffer,
                   MutableInt fieldLength,
                   org.mariadb.jdbc.client.ColumnDecoder column,
                   Calendar cal,
                   org.mariadb.jdbc.client.Context context)
            throws SQLDataException

Decode from a mysql packet binary encoded a value to codec java type

Parameters:
  `buffer` - mysql packet buffer
  `fieldLength` - encoded value length
  `column` - server column metadata
  `cal` - calendar
  `context` - connection context
Returns:
  decoded value
Throws:
  `SQLDataException` - if unexpected error occurs during decoding

#### encodeText

    void encodeText​(Writer encoder,
                    org.mariadb.jdbc.client.Context context,
                    Object value,
                    Calendar cal,
                    Long length)
             throws IOException,
                    SQLException

Text encode value to writer

Parameters:
  `encoder` - writer
  `context` - connection context
  `value` - value to encode
  `cal` - calendar
  `length` - maximum value length
Throws:
  `IOException` - if any socket error occurs
  `SQLException` - if encoding error occurs

#### encodeBinary

    void encodeBinary​(Writer encoder,
                      org.mariadb.jdbc.client.Context context,
                      Object value,
                      Calendar cal,
                      Long length)
               throws IOException,
                      SQLException

Binary encode value to writer

Parameters:
  `encoder` - writer
  `context` - connection context
  `value` - value to encode
  `cal` - calendar
  `length` - maximum value length
Throws:
  `IOException` - if any socket error occurs
  `SQLException` - if encoding error occurs

#### canEncodeLongData

    default boolean canEncodeLongData()

Indicate if can encode long data

Returns:
  true if possible

#### encodeLongData

    default void encodeLongData​(Writer encoder,
                                T value,
                                Long length)
                         throws IOException,
                                SQLException

binary encoding value to a long data packet

Parameters:
  `encoder` - writer
  `value` - value to encode
  `length` - maximum length value
Throws:
  `IOException` - if any socket error occurs
  `SQLException` - if encoding error occurs

#### encodeData

    default byte[] encodeData​(T value,
                              Long length)
                       throws IOException,
                              SQLException

binary encoding value to a byte[]

Parameters:
  `value` - value to encode
  `length` - maximum length value
Returns:
  encoded value
Throws:
  `IOException` - if any socket error occurs
  `SQLException` - if encoding error occurs

#### getBinaryEncodeType

    int getBinaryEncodeType()

Return server encoding data type

Returns:
  server encoding data type