Interface PersistCodec<S,T extends S,M extends com.google.protobuf.Message>
-
- Type Parameters:
S- the least-specific type this codec will accept when encodingT- the type of instances this codec will build when decodingM- 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 TfromByteArray(byte[] data)Given an encoded representation generated bytoByteArray(S), decode and build an instance of T (always exactly this type, regardless of the actual type previously passed totoByteArray(S))TfromMessage(M message)Given a protobuf message returned fromtoMessage(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.MtoMessage(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
nullifdatawasnull - Throws:
EncodeException- if the data could not be encoded
-
fromByteArray
T fromByteArray(byte[] data) throws DecodeException
Given an encoded representation generated bytoByteArray(S), decode and build an instance of T (always exactly this type, regardless of the actual type previously passed totoByteArray(S))- Parameters:
data- the encoded form to decode- Returns:
- a decoded instance of T, or
nullifdatawasnull - 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
nullifdatawasnull - Throws:
EncodeException- if the data could not be encoded
-
fromMessage
T fromMessage(M message)
Given a protobuf message returned fromtoMessage(S), decode and build an instance of T.- Parameters:
message- the message instance to decode, ornullifmessagewasnull- Returns:
- a decoded instance of T.
- Throws:
DecodeException- if the message could not be decoded
-
-