Interface PersistCodec<S,​T extends S,​M extends com.google.protobuf.Message>

  • Type Parameters:
    S - the least-specific type this codec will accept when encoding
    T - the type of instances this codec will build when decoding
    M - the generated protobuf message class
    All Known Implementing Classes:
    GPBCodec

    public interface PersistCodec<S,​T extends S,​M extends com.google.protobuf.Message>
    A codec for a single CGIN datatype. Each codec is protocol-specific and encodes only data specified in that protocol; for example, the CAP3 codec for CAP3InitialDPArg, if passed a CAP4InitialDPArg instance, will ignore and not encode any CAP4-specific fields. The codec also provides a mapping to a GPB message type.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      T fromByteArray​(byte[] data)
      Given an encoded representation generated by toByteArray(S), decode and build an instance of T (always exactly this type, regardless of the actual type previously passed to toByteArray(S))
      T fromMessage​(M message)
      Given a protobuf message returned from toMessage(S), decode and build an instance of T.
      byte[] toByteArray​(S data)
      Given an instance of S, encode it to a byte-array representation using the encoding rules associated with this codec.
      M toMessage​(S data)
      Given an instance of S, encode it as a protobuf message.
    • Method Detail

      • toByteArray

        byte[] toByteArray​(S data)
                    throws EncodeException
        Given an instance of S, encode it to a byte-array representation using the encoding rules associated with this codec.
        Parameters:
        data - the instance to encode
        Returns:
        an encoded form, or null if data was null
        Throws:
        EncodeException - if the data could not be encoded
      • fromByteArray

        T fromByteArray​(byte[] data)
                 throws DecodeException
        Given an encoded representation generated by toByteArray(S), decode and build an instance of T (always exactly this type, regardless of the actual type previously passed to toByteArray(S))
        Parameters:
        data - the encoded form to decode
        Returns:
        a decoded instance of T, or null if data was null
        Throws:
        DecodeException - if the data could not be decoded
      • toMessage

        M toMessage​(S data)
        Given an instance of S, encode it as a protobuf message.
        Parameters:
        data - the data object to encode
        Returns:
        a message instance representing the data object, or null if data was null
        Throws:
        EncodeException - if the data could not be encoded
      • fromMessage

        T fromMessage​(M message)
        Given a protobuf message returned from toMessage(S), decode and build an instance of T.
        Parameters:
        message - the message instance to decode, or null if message was null
        Returns:
        a decoded instance of T.
        Throws:
        DecodeException - if the message could not be decoded