MessageEntity
- The message entity being serialized/deserialized.public interface MessageSerializer<MessageEntity,WireFormat>
A message serializer is effectively a factory for negotiating serializers/deserializers. They are created by passing the relevant protocol information to then decide on a serializer/deserializer to use.
The returned serializers/deserializers may be invoked once for strict messages, or many times for streamed messages.
This interface doesn't actually specify the wireformat that the serializer must serialize to,
there are two sub interfaces that do, they being StrictMessageSerializer
, which
serializes messages that are primarily in memory, to and from ByteString
, and StreamedMessageSerializer
, which serializes streams of messages. Note that all message
serializers used by the framework must implement one of these two sub interfaces, the framework
does not know how to handle other serializer types.
Modifier and Type | Interface and Description |
---|---|
static interface |
MessageSerializer.NegotiatedDeserializer<MessageEntity,WireFormat>
A negotiated deserializer.
|
static interface |
MessageSerializer.NegotiatedSerializer<MessageEntity,WireFormat>
A negotiated serializer.
|
Modifier and Type | Method and Description |
---|---|
default org.pcollections.PSequence<MessageProtocol> |
acceptResponseProtocols()
The message headers that will be accepted for response serialization.
|
MessageSerializer.NegotiatedDeserializer<MessageEntity,WireFormat> |
deserializer(MessageProtocol protocol)
Get a deserializer for an entity described by the given request or response protocol.
|
default boolean |
isStreamed()
Whether this serializer is a streamed serializer or not.
|
default boolean |
isUsed()
Whether this serializer serializes values that are used or not.
|
MessageSerializer.NegotiatedSerializer<MessageEntity,WireFormat> |
serializerForRequest()
Get a serializer for a client request.
|
MessageSerializer.NegotiatedSerializer<MessageEntity,WireFormat> |
serializerForResponse(List<MessageProtocol> acceptedMessageProtocols)
Negotiate a serializer for the response, given the accepted message headers.
|
default org.pcollections.PSequence<MessageProtocol> acceptResponseProtocols()
default boolean isUsed()
If false, it means this serializer is for an empty request/response, eg, they use the NotUsed
type.
default boolean isStreamed()
MessageSerializer.NegotiatedSerializer<MessageEntity,WireFormat> serializerForRequest()
Since a client is the initiator of the request, it simply returns the default serializer for the entity.
MessageSerializer.NegotiatedDeserializer<MessageEntity,WireFormat> deserializer(MessageProtocol protocol) throws UnsupportedMediaType
protocol
- The protocol of the message request or response associated with the entity.UnsupportedMediaType
- If the deserializer can't deserialize that protocol.MessageSerializer.NegotiatedSerializer<MessageEntity,WireFormat> serializerForResponse(List<MessageProtocol> acceptedMessageProtocols) throws NotAcceptable
acceptedMessageProtocols
- The accepted message headers is a list of message headers that
will be accepted by the client. Any empty values in a message protocol, including the list
itself, indicate that any format is acceptable.NotAcceptable
- If the serializer can't meet the requirements of any of the accept
headers.