Interface Codec<T>

  • Type Parameters:
    T - Base data type that is supported by this codec.
    All Superinterfaces:
    DecodeFunction<T>, EncodeFunction<T>
    All Known Implementing Classes:
    GossipProtocolCodec

    public interface Codec<T>
    extends EncodeFunction<T>, DecodeFunction<T>
    Data serialization codec.

    This interface is responsible for encoding/decoding data to/from its binary form for transferring over the network or storing on disk. Typically instances of this interface are not constructed directly, but CodecFactory.createCodec() should be used instead.

    This interface is assumed to be not thread safe and new instance should be created via CodecFactory for each thread that performs data encoding/decoding.

    • Method Detail

      • isStateful

        boolean isStateful()
        Returns true if this codec maintains an internal state and can't be shared among multiple threads or network connections.

        Stateful codecs are optimized for encoding/decoding data between two stream-based endpoints (i.e. endpoints that maintain some kind of persistent connection, for example TCP socket connections). Stateful codecs can rely on the fact that encoded data is always decoded by the same codec on the receiver side and can perform various optimizations like data compression based on auto-populating dictionaries.

        Returns:
        true if this codec maintains an internal state and can't be shared among multiple threads or network connections.
      • baseType

        Class<T> baseType()
        Returns the base data type that is supported by this codec.
        Returns:
        Base data type that is supported by this codec.