public abstract class Packet extends BasicPacket
Modifier and Type | Field and Description |
---|---|
protected int |
channel
The channel at which this packet will be sent or was received,
or -1 when this is not known
|
CODE_MASK, encodedBody, encodingBuffer, length
Constructor and Description |
---|
Packet() |
Modifier and Type | Method and Description |
---|---|
BasicPacket |
decode(ByteBuffer buffer)
Fills this package from a byte buffer positioned at the first
byte of the package
|
Packet |
encode(ByteBuffer buffer,
int channel)
Encodes this package onto the given buffer at the current
position.
|
int |
getChannel()
Get the channel id of the packet.
|
boolean |
hasChannelId()
Informs that this packets needs a channel ID.
|
protected void |
patchChannelId(ByteBuffer buf,
int channelId)
Only for use with encodingBuffer magic.
|
void |
setChannel(int channel) |
String |
toString() |
allocateAndEncode, codeDecodedHook, decodeAndDecompressBody, decodeBody, encode, encodeAndCompressBody, encodeBody, getCode, getLength, getTimestamp, grantEncodingBuffer, grantEncodingBuffer, isEncoded, setCompressionLimit, setCompressionType, setEncodedBody, setTimestamp
protected int channel
public BasicPacket decode(ByteBuffer buffer)
decode
in class BasicPacket
UnsupportedOperationException
- if not implemented in the subclasspublic final Packet encode(ByteBuffer buffer, int channel) throws BufferTooSmallException
Encodes this package onto the given buffer at the current position. The position of the buffer after encoding is the byte following the last encoded byte.
This method will ensure that everything is written provided sufficient capacity regardless of the buffer limit. When returning, the limit is at the end of the package (qual to the position).
encode
in class BasicPacket
UnsupportedOperationException
- if not implemented in the subclassBufferTooSmallException
public int getChannel()
The channel can be thought of as a way to pair up requests and responses in the FS4 protocol: A response always belongs to to a channel and it is the clients responsibility to not re-use channel ids within the same connection.
Summary: This "channel" means "session id"
public void setChannel(int channel)
public boolean hasChannelId()
hasChannelId
in class BasicPacket
protected void patchChannelId(ByteBuffer buf, int channelId)
patchChannelId
in class BasicPacket
public String toString()
toString
in class BasicPacket
Copyright © 2018. All rights reserved.