public class RpcPacketPreamble
extends java.lang.Object
The format (as divined from the C++ API) is designed to provide a very simple sanity check checksum and encode the length in bytes of the accompanying RPC payload:
byte[1] = ( payload_length / 0x1 ) % 0x100; byte[2] = ( payload_length / 0x100 ) % 0x100; byte[3] = ( payload_length / 0x10000 ) % 0x100; byte[4] = ( payload_length / 0x1000000 ) % 0x100; byte[0] = byte[1] ^ byte[2] ^ byte[3] ^ byte[4];This can generally only be calculated after the other packet elements have been serialized, which is irritating but not too annoying.
Modifier and Type | Field and Description |
---|---|
static int |
RPC_PREAMBLE_CHKSUM_SIZE
Size in bytes of the preamble checksum.
|
static int |
RPC_PREAMBLE_SIZE
The size in bytes of the standard text packet RPC packet preamble.
|
Modifier and Type | Method and Description |
---|---|
static RpcPacketPreamble |
constructPreamble(java.nio.ByteBuffer payload)
Calculate and construct a suitable preamble for the passed-in
payload buffer.
|
static RpcPacketPreamble |
constructPreamble(int payloadLength)
Calculate and construct a suitable preamble for the passed-in
payload buffer length.
|
int |
getPayloadSize()
Return the payload size (in bytes) specified by this preamble.
|
boolean |
isValidChecksum() |
java.nio.ByteBuffer |
marshal()
Return a ByteBuffer representing the marshaled version
of this preamble.
|
byte[] |
marshalAsBytes() |
static RpcPacketPreamble |
retrievePreamble(byte[] bytes)
Retrieve the preamble from raw bytes.
|
static RpcPacketPreamble |
retrievePreamble(java.nio.ByteBuffer payload)
Retrieve a preamble from the passed-in payload byte buffer.
|
public static final int RPC_PREAMBLE_CHKSUM_SIZE
public static final int RPC_PREAMBLE_SIZE
public static RpcPacketPreamble constructPreamble(java.nio.ByteBuffer payload)
payload
- non-null byte buffer representing the payloadpublic static RpcPacketPreamble constructPreamble(int payloadLength)
payloadLength
- payloadLengthpublic static RpcPacketPreamble retrievePreamble(java.nio.ByteBuffer payload)
payload
- non-null payloadpublic static RpcPacketPreamble retrievePreamble(byte[] bytes)
bytes
- bytespublic int getPayloadSize()
public boolean isValidChecksum()
public java.nio.ByteBuffer marshal()
public byte[] marshalAsBytes()