public class ExtendedProtocol extends BaseMessageHandler<ExtendedMessage>
Modifier and Type | Field and Description |
---|---|
static int |
EXTENDED_MESSAGE_ID
Unique message type ID for all extended message types.
|
Constructor and Description |
---|
ExtendedProtocol(ExtendedMessageTypeMapping messageTypeMapping,
Map<String,MessageHandler<? extends ExtendedMessage>> handlersByTypeName) |
Modifier and Type | Method and Description |
---|---|
int |
doDecode(DecodingContext context,
ByteBufferView buffer)
Decode the payload of a message (excluding message prefix -- see
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE )
and place it into the provided context. |
boolean |
doEncode(EncodingContext context,
ExtendedMessage message,
ByteBuffer buffer)
Encode the payload of a message (excluding message prefix -- see
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE )
and write it into the provided buffer. |
Collection<Class<? extends ExtendedMessage>> |
getSupportedTypes() |
Class<? extends ExtendedMessage> |
readMessageType(ByteBufferView buffer)
Tries to determine the message type based on the (part of the) message available in the byte buffer.
|
decode, encode
public static final int EXTENDED_MESSAGE_ID
ExtendedProtocol
for further processing.@Inject public ExtendedProtocol(ExtendedMessageTypeMapping messageTypeMapping, Map<String,MessageHandler<? extends ExtendedMessage>> handlersByTypeName)
public Collection<Class<? extends ExtendedMessage>> getSupportedTypes()
public Class<? extends ExtendedMessage> readMessageType(ByteBufferView buffer)
Protocol
buffer
- Byte buffer of arbitrary length containing (a part of) the message.
Decoding should be performed starting with the current position of the buffer.public int doDecode(DecodingContext context, ByteBufferView buffer)
BaseMessageHandler
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE
)
and place it into the provided context.doDecode
in class BaseMessageHandler<ExtendedMessage>
context
- The context to place the decoded message into.buffer
- Buffer to decode from. Buffer.remaining()
is set
to the declared length of the message.
Message payload starts precisely at buffer's Buffer.position()
.public boolean doEncode(EncodingContext context, ExtendedMessage message, ByteBuffer buffer)
BaseMessageHandler
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE
)
and write it into the provided buffer.doEncode
in class BaseMessageHandler<ExtendedMessage>
context
- Encoding contextbuffer
- Byte buffer to write to.
Encoded message should be placed into the buffer starting with its current position.
This method should check if the buffer has sufficient space available, and return false
if it's not the case.
After this method returns, the buffer's Buffer.position()
is used
to calculate the size of message's payload, which is then specified in the message's prefix.Copyright © 2016–2021. All rights reserved.