public final class PortMessageHandler extends UniqueMessageHandler<Port>
Modifier and Type | Field and Description |
---|---|
static int |
PORT_ID |
Constructor and Description |
---|
PortMessageHandler() |
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,
Port message,
ByteBuffer buffer)
Encode the payload of a message (excluding message prefix -- see
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE )
and write it into the provided buffer. |
getSupportedTypes, readMessageType
decode, encode
public static final int PORT_ID
public int doDecode(DecodingContext context, ByteBufferView buffer)
BaseMessageHandler
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE
)
and place it into the provided context.doDecode
in class BaseMessageHandler<Port>
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, Port message, ByteBuffer buffer)
BaseMessageHandler
StandardBittorrentProtocol.MESSAGE_PREFIX_SIZE
)
and write it into the provided buffer.doEncode
in class BaseMessageHandler<Port>
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.