Interface Codec<T>

Type Parameters:
T - the type that is handled by this codec.
All Known Implementing Classes:
EnumCodec, OffsetTimeCodec, StringCodec, VectorCodec, VectorFloatCodec

public interface Codec<T>
Codec to encode and decode values based on Postgres OIDs and Format.

Codecs can decode one or more server-specific data types and represent them as a specific Java type. The type parameter of Codec indicates the interchange type that is handled by this codec.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canDecode(int dataType, io.r2dbc.postgresql.message.Format format, Class<?> type)
    Determine whether this Codec is capable of decoding a value for the given dataType and Format and whether it can represent the decoded value as the desired type.
    boolean
    Determine whether this Codec is capable of encoding the value.
    boolean
    Determine whether this Codec is capable of encoding a null value for the given Class type.
    decode(io.netty.buffer.ByteBuf buffer, int dataType, io.r2dbc.postgresql.message.Format format, Class<? extends T> type)
    Decode the buffer and return it as the requested type.
    io.r2dbc.postgresql.client.EncodedParameter
    encode(Object value)
    Encode the value to be used as RPC parameter.
    io.r2dbc.postgresql.client.EncodedParameter
    encode(Object value, int dataType)
    Encode the value to be used as RPC parameter.
    io.r2dbc.postgresql.client.EncodedParameter
    Encode a null value.
  • Method Details

    • canDecode

      boolean canDecode(int dataType, io.r2dbc.postgresql.message.Format format, Class<?> type)
      Determine whether this Codec is capable of decoding a value for the given dataType and Format and whether it can represent the decoded value as the desired type.
      Parameters:
      dataType - the Postgres OID to decode
      format - the data type Format, text or binary
      type - the desired value type
      Returns:
      true if this codec is able to decode values for tge given dataType and Format
    • canEncode

      boolean canEncode(Object value)
      Determine whether this Codec is capable of encoding the value.
      Parameters:
      value - the parameter value
      Returns:
      true if this Codec is able to encode the value.
      See Also:
    • canEncodeNull

      boolean canEncodeNull(Class<?> type)
      Determine whether this Codec is capable of encoding a null value for the given Class type.
      Parameters:
      type - the desired value type
      Returns:
      true if this Codec is able to encode null values for the given Class type.
      See Also:
    • decode

      @Nullable T decode(@Nullable io.netty.buffer.ByteBuf buffer, int dataType, io.r2dbc.postgresql.message.Format format, Class<? extends T> type)
      Decode the buffer and return it as the requested type.
      Parameters:
      buffer - the data buffer
      dataType - the Postgres OID to encode
      format - the data type Format, text or binary
      type - the desired value type
      Returns:
      the decoded value. Can be null if the value is null.
    • encode

      io.r2dbc.postgresql.client.EncodedParameter encode(Object value)
      Encode the value to be used as RPC parameter.
      Parameters:
      value - the value
      Returns:
      the encoded value
    • encode

      io.r2dbc.postgresql.client.EncodedParameter encode(Object value, int dataType)
      Encode the value to be used as RPC parameter.
      Parameters:
      value - the value
      dataType - the Postgres OID to encode
      Returns:
      the encoded value
      Since:
      0.9
    • encodeNull

      io.r2dbc.postgresql.client.EncodedParameter encodeNull()
      Encode a null value.
      Returns:
      the encoded null value