Class RpcPacketPreamble
java.lang.Object
com.perforce.p4java.impl.mapbased.rpc.packet.RpcPacketPreamble
The five byte preamble appended to every text packet payload.
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSize in bytes of the preamble checksum.static final intThe size in bytes of the standard text packet RPC packet preamble. -
Method Summary
Modifier and TypeMethodDescriptionstatic RpcPacketPreambleconstructPreamble(int payloadLength) Calculate and construct a suitable preamble for the passed-in payload buffer length.static RpcPacketPreambleconstructPreamble(ByteBuffer payload) Calculate and construct a suitable preamble for the passed-in payload buffer.intReturn the payload size (in bytes) specified by this preamble.booleanmarshal()Return a ByteBuffer representing the marshaled version of this preamble.byte[]static RpcPacketPreambleretrievePreamble(byte[] bytes) Retrieve the preamble from raw bytes.static RpcPacketPreambleretrievePreamble(ByteBuffer payload) Retrieve a preamble from the passed-in payload byte buffer.
-
Field Details
-
RPC_PREAMBLE_CHKSUM_SIZE
public static final int RPC_PREAMBLE_CHKSUM_SIZESize in bytes of the preamble checksum. This is a very fundamental value; changing it will probably cause total destruction within P4Java...- See Also:
-
RPC_PREAMBLE_SIZE
public static final int RPC_PREAMBLE_SIZEThe size in bytes of the standard text packet RPC packet preamble.- See Also:
-
-
Method Details
-
constructPreamble
Calculate and construct a suitable preamble for the passed-in payload buffer. Does not affect the incoming buffer at all (i.e. marks and limits, etc. are unaffected). Assumes the payload starts at buffer byte position zero and uses the buffer's limit as the length.- Parameters:
payload- non-null byte buffer representing the payload- Returns:
- new RpcPacketPreamble for the payload
-
constructPreamble
Calculate and construct a suitable preamble for the passed-in payload buffer length.- Parameters:
payloadLength- payloadLength- Returns:
- RpcPacketPreamble
-
retrievePreamble
Retrieve a preamble from the passed-in payload byte buffer. Will move the byte buffer pointer accordingly.- Parameters:
payload- non-null payload- Returns:
- new RpcPacketPreamble as retrieved from the payload buffer.
-
retrievePreamble
Retrieve the preamble from raw bytes. Most sanity checking is done in the RpcPacketPreamble constructor.- Parameters:
bytes- bytes- Returns:
- RpcPacketPreamble
-
getPayloadSize
public int getPayloadSize()Return the payload size (in bytes) specified by this preamble.- Returns:
- the associated payload size in bytes.
-
isValidChecksum
public boolean isValidChecksum()- Returns:
- true iff the simple checksum checks out.
-
marshal
Return a ByteBuffer representing the marshaled version of this preamble. Buffer will need to be flipped before sending...- Returns:
- non-null ByteBuffer ready for sending
-
marshalAsBytes
public byte[] marshalAsBytes()
-