com.perforce.p4java.impl.mapbased.rpc.packet
Class RpcPacketField

java.lang.Object
  extended by 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>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
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 String TRACE_PREFIX
           
static int VALUE_FIELD
          Which element will contain (or not) the field's value.
 
Constructor Summary
RpcPacketField(String name, Object value)
          Construct a packet field from the passed-n name / value pair.
 
Method Summary
 String getName()
           
 Object getValue()
           
static void marshal(byte[] buf, String name, byte[] value)
           
static void marshal(ByteBuffer buf, String name, byte[] value)
          Marshal the passed-in packet fields onto a ByteBuffer.
static void marshal(ByteBuffer buf, String name, ByteBuffer value)
          Marshal the passed-in packet fields onto a ByteBuffer.
static void marshal(ByteBuffer buf, String name, StringBuffer value, Charset charset)
          Marshal the passed-in packet fields onto a ByteBuffer.
static void marshal(ByteBuffer buf, String name, String value, Charset charset)
          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.
 void setName(String name)
           
 void setValue(Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE_PREFIX

public static final String TRACE_PREFIX
See Also:
Constant Field Values

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(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 Detail

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.


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.


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.

Throws:
UnsupportedEncodingException
BufferOverflowException

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.

Throws:
UnsupportedEncodingException
BufferOverflowException

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.

Throws:
BufferOverflowException

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.

Throws:
BufferOverflowException

marshal

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


Copyright © 2015 Perforce Software. All Rights Reserved.