T
- Message type or a common supertype of several message types,
that this handler is able to encode and decode.public interface MessageHandler<T extends Message> extends Protocol<T>
Modifier and Type | Method and Description |
---|---|
int |
decode(DecodingContext context,
ByteBufferView buffer)
Tries to decode message from the byte buffer.
|
boolean |
encode(EncodingContext context,
T message,
ByteBuffer buffer)
Tries to encode the provided message and place the result into the byte buffer.
|
getSupportedTypes, readMessageType
boolean encode(EncodingContext context, T message, ByteBuffer buffer)
context
- Encoding contextbuffer
- Byte buffer of arbitrary capacity.
Encoded message should be placed into the buffer starting with its current position.
Protocol should check if the buffer has sufficient space available, and return false
if it's not the case.InvalidMessageException
- if message type is not supported or the message is invalidint decode(DecodingContext context, ByteBufferView buffer)
context
context
- Message context. In case of success the decoded message must be put into this context.buffer
- Byte buffer of arbitrary length containing (a part of) the message.
Decoding should be performed starting with the current position of the buffer.InvalidMessageException
- if data is invalidCopyright © 2016–2021. All rights reserved.