public class RpcPacketField
extends java.lang.Object
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().
Modifier and Type | Field and 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 and Description |
---|
RpcPacketField(java.lang.String name,
java.lang.Object value)
Construct a packet field from the passed-n name / value pair.
|
Modifier and Type | Method and 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.nio.ByteBuffer 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 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) |
public static final java.lang.String TRACE_PREFIX
public static final int NUM_ELEMENTS
public static final int NAME_FIELD
public static final int VALUE_FIELD
public RpcPacketField(java.lang.String name, java.lang.Object value)
name
- possibly-null namevalue
- possibly-null valuepublic static java.lang.Object[] retrievePacketField(java.nio.ByteBuffer buf, boolean isUnicodeServer, java.nio.charset.Charset charset)
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.
buf
- bufisUnicodeServer
- isUnicodeServercharset
- charsetpublic static java.lang.Object[] retrievePacketField(java.nio.ByteBuffer buf, boolean isUnicodeServer, java.nio.charset.Charset charset, RpcPacketFieldRule fieldRule)
buf
- bufisUnicodeServer
- isUnicodeServercharset
- charsetfieldRule
- fieldRulepublic java.lang.String getName()
public void setName(java.lang.String name)
public java.lang.Object getValue()
public void setValue(java.lang.Object value)
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
buf
- bufname
- namevalue
- valuecharset
- charsetjava.io.UnsupportedEncodingException
- on errorjava.nio.BufferOverflowException
- on errorpublic 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
buf
- bufname
- namevalue
- valuecharset
- charsetjava.io.UnsupportedEncodingException
- on errorjava.nio.BufferOverflowException
- on errorpublic static void marshal(java.nio.ByteBuffer buf, java.lang.String name, byte[] value) throws java.nio.BufferOverflowException
buf
- bufname
- namevalue
- valuejava.nio.BufferOverflowException
- on errorpublic static void marshal(java.nio.ByteBuffer buf, java.lang.String name, java.nio.ByteBuffer value) throws java.nio.BufferOverflowException
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.
buf
- bufname
- namevalue
- valuejava.nio.BufferOverflowException
- on errorpublic static void marshal(byte[] buf, java.lang.String name, byte[] value) throws java.nio.BufferOverflowException
java.nio.BufferOverflowException