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 classpublic abstract class GPBCodec<S,T extends S,M extends com.google.protobuf.Message> extends Object implements PersistCodec<S,T,M>
| Modifier | Constructor and Description |
|---|---|
protected |
GPBCodec(M instance)
Subclasses use this constructor to provide a prototype message instance,
indicating the message type they expect to handle.
|
| Modifier and Type | Method and Description |
|---|---|
T |
fromByteArray(byte[] data)
Given an encoded representation generated by
PersistCodec.toByteArray(S),
decode and build an instance of T (always exactly this type,
regardless of the actual type previously passed to PersistCodec.toByteArray(S)) |
abstract T |
fromMessage(M message)
Given a protobuf message returned from
PersistCodec.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.
|
abstract M |
toMessage(S data)
Given an instance of S, encode it as a protobuf message.
|
protected GPBCodec(M instance)
instance - any instance of M (e.g. M.getDefaultInstance())public final byte[] toByteArray(S data) throws EncodeException
PersistCodectoByteArray in interface PersistCodec<S,T extends S,M extends com.google.protobuf.Message>data - the instance to encodenull if data was nullEncodeException - if the data could not be encodedpublic final T fromByteArray(byte[] data) throws DecodeException
PersistCodecPersistCodec.toByteArray(S),
decode and build an instance of T (always exactly this type,
regardless of the actual type previously passed to PersistCodec.toByteArray(S))fromByteArray in interface PersistCodec<S,T extends S,M extends com.google.protobuf.Message>data - the encoded form to decodenull if data was nullDecodeException - if the data could not be decodedpublic abstract M toMessage(S data)
PersistCodecpublic abstract T fromMessage(M message)
PersistCodecPersistCodec.toMessage(S),
decode and build an instance of T.fromMessage in interface PersistCodec<S,T extends S,M extends com.google.protobuf.Message>message - the message instance to decode, or null if message was null