Class RpcPacketField


  • public class RpcPacketField
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static int NAME_FIELD
      Which element will contain (or not) the field's name.
      static int NUM_ELEMENTS
      How many elements in each packet field.
      static java.lang.String TRACE_PREFIX  
      static int VALUE_FIELD
      Which element will contain (or not) the field's value.
    • Constructor Summary

      Constructors 
      Constructor Description
      RpcPacketField​(java.lang.String name, java.lang.Object value)
      Construct a packet field from the passed-n name / value pair.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getName()  
      java.lang.Object getValue()  
      static void marshal​(byte[] buf, java.lang.String name, byte[] value)  
      static void marshal​(java.nio.ByteBuffer buf, java.lang.String name, byte[] value)
      Marshal the passed-in packet fields onto a ByteBuffer.
      static void marshal​(java.nio.ByteBuffer buf, java.lang.String name, java.lang.StringBuffer value, java.nio.charset.Charset charset)
      Marshal the passed-in packet fields onto a ByteBuffer.
      static void marshal​(java.nio.ByteBuffer buf, java.lang.String name, java.lang.String value, java.nio.charset.Charset charset)
      Marshal the passed-in packet fields onto a ByteBuffer.
      static void marshal​(java.nio.ByteBuffer buf, java.lang.String name, java.nio.ByteBuffer value)
      Marshal the passed-in packet fields onto a ByteBuffer.
      static java.lang.Object[] retrievePacketField​(java.nio.ByteBuffer buf, boolean isUnicodeServer, java.nio.charset.Charset charset)
      Attempt to pick off a name / value field pair from the passed-in byte buffer.
      static java.lang.Object[] retrievePacketField​(java.nio.ByteBuffer buf, boolean isUnicodeServer, java.nio.charset.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.
      void setName​(java.lang.String name)  
      void setValue​(java.lang.Object value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NUM_ELEMENTS

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

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

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

      • RpcPacketField

        public RpcPacketField​(java.lang.String name,
                              java.lang.Object value)
        Construct a packet field from the passed-n name / value pair.
        Parameters:
        name - possibly-null name
        value - possibly-null value
    • Method Detail

      • retrievePacketField

        public static java.lang.Object[] retrievePacketField​(java.nio.ByteBuffer buf,
                                                             boolean isUnicodeServer,
                                                             java.nio.charset.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 java.lang.Object[] retrievePacketField​(java.nio.ByteBuffer buf,
                                                             boolean isUnicodeServer,
                                                             java.nio.charset.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
      • getName

        public java.lang.String getName()
      • setName

        public void setName​(java.lang.String name)
      • getValue

        public java.lang.Object getValue()
      • setValue

        public void setValue​(java.lang.Object value)
      • marshal

        public static void marshal​(java.nio.ByteBuffer buf,
                                   java.lang.String name,
                                   java.lang.String value,
                                   java.nio.charset.Charset charset)
                            throws java.nio.BufferOverflowException,
                                   java.io.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:
        java.io.UnsupportedEncodingException - on error
        java.nio.BufferOverflowException - on error
      • marshal

        public static void marshal​(java.nio.ByteBuffer buf,
                                   java.lang.String name,
                                   java.lang.StringBuffer value,
                                   java.nio.charset.Charset charset)
                            throws java.nio.BufferOverflowException,
                                   java.io.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:
        java.io.UnsupportedEncodingException - on error
        java.nio.BufferOverflowException - on error
      • marshal

        public static void marshal​(java.nio.ByteBuffer buf,
                                   java.lang.String name,
                                   byte[] value)
                            throws java.nio.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:
        java.nio.BufferOverflowException - on error
      • marshal

        public static void marshal​(java.nio.ByteBuffer buf,
                                   java.lang.String name,
                                   java.nio.ByteBuffer value)
                            throws java.nio.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:
        java.nio.BufferOverflowException - on error
      • marshal

        public static void marshal​(byte[] buf,
                                   java.lang.String name,
                                   byte[] value)
                            throws java.nio.BufferOverflowException
        Throws:
        java.nio.BufferOverflowException