Class RpcPacketField
java.lang.Object
com.perforce.p4java.impl.mapbased.rpc.packet.RpcPacketField
Describes a value / name packet pair as marshaled
on to or off the RPC wire between Perforce clients and servers.
Format on wire (from C++ API source), in bytes:
var<00><l1><l2><l3><l4>value<00>
where either or both var and value can be empty (null), and where value can be interpreted as text (utf-8 or ascii, depending on settings) binary bytes, and where the four byte value length spec does not include the terminating null byte, and is encoded as per RpcPacket.encodeInt4().
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intWhich element will contain (or not) the field's name.static final intHow many elements in each packet field.static final Stringstatic final intWhich element will contain (or not) the field's value. -
Constructor Summary
ConstructorsConstructorDescriptionRpcPacketField(String name, Object value) Construct a packet field from the passed-n name / value pair. -
Method Summary
Modifier and TypeMethodDescriptiongetName()getValue()static voidstatic voidmarshal(ByteBuffer buf, String name, byte[] value) Marshal the passed-in packet fields onto a ByteBuffer.static voidmarshal(ByteBuffer buf, String name, StringBuffer value, Charset charset) Marshal the passed-in packet fields onto a ByteBuffer.static voidmarshal(ByteBuffer buf, String name, String value, Charset charset) Marshal the passed-in packet fields onto a ByteBuffer.static voidmarshal(ByteBuffer buf, String name, ByteBuffer value) Marshal the passed-in packet fields onto a ByteBuffer.static Object[]retrievePacketField(ByteBuffer buf, boolean isUnicodeServer, Charset charset) Attempt to pick off a name / value field pair from the passed-in byte buffer.static Object[]retrievePacketField(ByteBuffer buf, boolean isUnicodeServer, Charset charset, RpcPacketFieldRule fieldRule) Attempt to pick off a name / value field pair from the passed-in byte buffer with an optional rule to handle the RPC packet fields.static Object[]retrievePacketField(ByteBuffer buf, boolean isUnicodeServer, Charset charset, RpcPacketFieldRule fieldRule, Map<Object, byte[]> rawTextValues) Attempt to pick off a name / value field pair from the passed-in byte buffer with an optional rule to handle the RPC packet fields, recording the bytes of any text value that the charset cannot represent.voidvoid
-
Field Details
-
TRACE_PREFIX
- See Also:
-
NUM_ELEMENTS
public static final int NUM_ELEMENTSHow many elements in each packet field. Changing this will probably cause havoc.- See Also:
-
NAME_FIELD
public static final int NAME_FIELDWhich element will contain (or not) the field's name.- See Also:
-
VALUE_FIELD
public static final int VALUE_FIELDWhich element will contain (or not) the field's value.- See Also:
-
-
Constructor Details
-
RpcPacketField
Construct a packet field from the passed-n name / value pair.- Parameters:
name- possibly-null namevalue- possibly-null value
-
-
Method Details
-
retrievePacketField
public static Object[] retrievePacketField(ByteBuffer buf, boolean isUnicodeServer, Charset charset) Attempt to pick off a name / value field pair from the passed-in byte buffer. Will always return a two-element object array, but either or both of the objects may be null. Element zero is always the name (and will always be text (a string) if it's not null; element one is the corresponding value, and (if it's not null) will be a byte array whose interpretation must be done by the caller in the light of what's expected in context -- it might represent a normal string or it might actually be binary bytes.Updates the buffer's position accordingly. Have to be careful to use charsets with bytes and strings properly here and in the caller to keep internationalization and localization straight.
- Parameters:
buf- bufisUnicodeServer- isUnicodeServercharset- charset- Returns:
- packet fields
-
retrievePacketField
public static Object[] retrievePacketField(ByteBuffer buf, boolean isUnicodeServer, Charset charset, RpcPacketFieldRule fieldRule) Attempt to pick off a name / value field pair from the passed-in byte buffer with an optional rule to handle the RPC packet fields.- Parameters:
buf- bufisUnicodeServer- isUnicodeServercharset- charsetfieldRule- fieldRule- Returns:
- packet fields
-
retrievePacketField
public static Object[] retrievePacketField(ByteBuffer buf, boolean isUnicodeServer, Charset charset, RpcPacketFieldRule fieldRule, Map<Object, byte[]> rawTextValues) Attempt to pick off a name / value field pair from the passed-in byte buffer with an optional rule to handle the RPC packet fields, recording the bytes of any text value that the charset cannot represent.- Parameters:
buf- bufisUnicodeServer- isUnicodeServercharset- charsetfieldRule- fieldRulerawTextValues- if not null, receives the bytes the server sent for each text value that does not encode back to the same bytes, keyed by the decoded String- Returns:
- packet fields
-
getName
-
setName
-
getValue
-
setValue
-
marshal
public static void marshal(ByteBuffer buf, String name, String value, Charset charset) throws BufferOverflowException, UnsupportedEncodingException Marshal the passed-in packet fields onto a ByteBuffer. Affects the buffer's position, etc., accordingly.- Parameters:
buf- bufname- namevalue- valuecharset- charset- Throws:
UnsupportedEncodingException- on errorBufferOverflowException- on error
-
marshal
public static void marshal(ByteBuffer buf, String name, StringBuffer value, Charset charset) throws BufferOverflowException, UnsupportedEncodingException Marshal the passed-in packet fields onto a ByteBuffer. Affects the buffer's position, etc., accordingly.- Parameters:
buf- bufname- namevalue- valuecharset- charset- Throws:
UnsupportedEncodingException- on errorBufferOverflowException- on error
-
marshal
public static void marshal(ByteBuffer buf, String name, byte[] value) throws BufferOverflowException Marshal the passed-in packet fields onto a ByteBuffer. Affects the buffer's position, etc., accordingly.- Parameters:
buf- bufname- namevalue- value- Throws:
BufferOverflowException- on error
-
marshal
public static void marshal(ByteBuffer buf, String name, ByteBuffer value) throws BufferOverflowException Marshal the passed-in packet fields onto a ByteBuffer. Affects the buffer's position, etc., accordingly. Since this one uses special ByteBuffer to ByteBuffer methods, it gets its own version rather than using the byte[] method.Note: incoming value ByteBuffer must have been flipped ready for sending; value's position will be updated by this method, so if the buffer is to be reused, you must flip or reset (or whatever) it yourself.
- Parameters:
buf- bufname- namevalue- value- Throws:
BufferOverflowException- on error
-
marshal
- Throws:
BufferOverflowException
-