Class RpcPacketField

java.lang.Object
com.perforce.p4java.impl.mapbased.rpc.packet.RpcPacketField

public class RpcPacketField extends Object
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 Details

    • TRACE_PREFIX

      public static final String TRACE_PREFIX
      See Also:
    • NUM_ELEMENTS

      public static final int NUM_ELEMENTS
      How many elements in each packet field. Changing this will probably cause havoc.
      See Also:
    • NAME_FIELD

      public static final int NAME_FIELD
      Which element will contain (or not) the field's name.
      See Also:
    • VALUE_FIELD

      public static final int VALUE_FIELD
      Which element will contain (or not) the field's value.
      See Also:
  • Constructor Details

    • RpcPacketField

      public RpcPacketField(String name, Object value)
      Construct a packet field from the passed-n name / value pair.
      Parameters:
      name - possibly-null name
      value - 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 - buf
      isUnicodeServer - isUnicodeServer
      charset - 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 - buf
      isUnicodeServer - isUnicodeServer
      charset - charset
      fieldRule - 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 - buf
      isUnicodeServer - isUnicodeServer
      charset - charset
      fieldRule - fieldRule
      rawTextValues - 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

      public String getName()
    • setName

      public void setName(String name)
    • getValue

      public Object getValue()
    • setValue

      public void setValue(Object value)
    • 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 - buf
      name - name
      value - value
      charset - charset
      Throws:
      UnsupportedEncodingException - on error
      BufferOverflowException - 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 - buf
      name - name
      value - value
      charset - charset
      Throws:
      UnsupportedEncodingException - on error
      BufferOverflowException - 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 - buf
      name - name
      value - 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 - buf
      name - name
      value - value
      Throws:
      BufferOverflowException - on error
    • marshal

      public static void marshal(byte[] buf, String name, byte[] value) throws BufferOverflowException
      Throws:
      BufferOverflowException