|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.oncrpc.XDR
public class XDR
Utility class for building XDR messages based on RFC 4506.
This class maintains a buffer into which java types are written as XDR types for building XDR messages. Similarly this class can be used to get java types from an XDR request or response.
Currently only a subset of XDR types defined in RFC 4506 are supported.
Constructor Summary | |
---|---|
XDR()
|
|
XDR(byte[] data)
|
Method Summary | |
---|---|
static byte[] |
append(byte[] bytes,
byte[] bytesToAdd)
|
void |
dump(PrintStream out)
|
static int |
fragmentSize(byte[] mark)
|
byte[] |
getBytes()
|
static byte[] |
getVariableOpque(byte[] data)
|
static boolean |
isLastFragment(byte[] mark)
|
boolean |
readBoolean()
Read an XDR boolean and return as Java primitive boolean. |
byte[] |
readFixedOpaque(int size)
|
long |
readHyper()
Read XDR signed hyper and return as java primitive long. |
int |
readInt()
Read an XDR signed integer and return as Java primitive integer. |
String |
readString()
|
byte[] |
readVariableOpaque()
|
int |
size()
|
void |
skip(int size)
Skip some bytes by moving the cursor |
void |
skipVariableOpaque()
|
static boolean |
verifyLength(XDR xdr,
int len)
check if the rest of data has more than |
void |
writeBoolean(boolean data)
Write Java primitive boolean as an XDR boolean. |
void |
writeFixedOpaque(byte[] data)
Write a Java primitive byte array to XDR fixed-length opaque data. |
void |
writeFixedOpaque(byte[] data,
int length)
|
void |
writeInt(int data)
Write Java primitive integer as XDR signed integer. |
void |
writeLongAsHyper(long data)
Write Java primitive long to an XDR signed long. |
static org.jboss.netty.buffer.ChannelBuffer |
writeMessageTcp(XDR request,
boolean last)
Write an XDR message to a TCP ChannelBuffer |
static org.jboss.netty.buffer.ChannelBuffer |
writeMessageUdp(XDR response)
Write an XDR message to a UDP ChannelBuffer |
void |
writeString(String data)
Write Java String as XDR string. |
void |
writeVariableOpaque(byte[] data)
Write a Java primitive byte array as XDR variable-length opque data. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XDR()
public XDR(byte[] data)
Method Detail |
---|
public int size()
public void skip(int size)
public void writeInt(int data)
An XDR signed integer is a 32-bit datum that encodes an integer in the range [-2147483648,2147483647]. The integer is represented in two's complement notation. The most and least significant bytes are 0 and 3, respectively. Integers are declared as follows: int identifier; (MSB) (LSB) +-------+-------+-------+-------+ |byte 0 |byte 1 |byte 2 |byte 3 | INTEGER +-------+-------+-------+-------+ <------------32 bits------------>
public int readInt()
public void writeBoolean(boolean data)
Booleans are important enough and occur frequently enough to warrant their own explicit type in the standard. Booleans are declared as follows: bool identifier; This is equivalent to: enum { FALSE = 0, TRUE = 1 } identifier;
public boolean readBoolean()
public void writeLongAsHyper(long data)
The standard also defines 64-bit (8-byte) numbers called hyper integers and unsigned hyper integers. Their representations are the obvious extensions of integer and unsigned integer defined above. They are represented in two's complement notation.The most and least significant bytes are 0 and 7, respectively. Their declarations: hyper identifier; unsigned hyper identifier; (MSB) (LSB) +-------+-------+-------+-------+-------+-------+-------+-------+ |byte 0 |byte 1 |byte 2 |byte 3 |byte 4 |byte 5 |byte 6 |byte 7 | +-------+-------+-------+-------+-------+-------+-------+-------+ <----------------------------64 bits----------------------------> HYPER INTEGER UNSIGNED HYPER INTEGER
public long readHyper()
public void writeFixedOpaque(byte[] data)
At times, fixed-length uninterpreted data needs to be passed among machines. This data is called "opaque" and is declared as follows: opaque identifier[n]; where the constant n is the (static) number of bytes necessary to contain the opaque data. If n is not a multiple of four, then the n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count of the opaque object a multiple of four. 0 1 ... +--------+--------+...+--------+--------+...+--------+ | byte 0 | byte 1 |...|byte n-1| 0 |...| 0 | +--------+--------+...+--------+--------+...+--------+ |<-----------n bytes---------->|<------r bytes------>| |<-----------n+r (where (n+r) mod 4 = 0)------------>| FIXED-LENGTH OPAQUE
public void writeFixedOpaque(byte[] data, int length)
public byte[] readFixedOpaque(int size)
public void writeVariableOpaque(byte[] data)
The standard also provides for variable-length (counted) opaque data, defined as a sequence of n (numbered 0 through n-1) arbitrary bytes to be the number n encoded as an unsigned integer (as described below), and followed by the n bytes of the sequence. Byte m of the sequence always precedes byte m+1 of the sequence, and byte 0 of the sequence always follows the sequence's length (count). If n is not a multiple of four, then the n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count a multiple of four. Variable-length opaque data is declared in the following way: opaque identifier; or opaque identifier<>; The constant m denotes an upper bound of the number of bytes that the sequence may contain. If m is not specified, as in the second declaration, it is assumed to be (2**32) - 1, the maximum length. The constant m would normally be found in a protocol specification. For example, a filing protocol may state that the maximum data transfer size is 8192 bytes, as follows: opaque filedata<8192>; 0 1 2 3 4 5 ... +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+ | length n |byte0|byte1|...| n-1 | 0 |...| 0 | +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+ |<-------4 bytes------->|<------n bytes------>|<---r bytes--->| |<----n+r (where (n+r) mod 4 = 0)---->| VARIABLE-LENGTH OPAQUE It is an error to encode a length greater than the maximum described in the specification.
public byte[] readVariableOpaque()
public void skipVariableOpaque()
public void writeString(String data)
The standard defines a string of n (numbered 0 through n-1) ASCII bytes to be the number n encoded as an unsigned integer (as described above), and followed by the n bytes of the string. Byte m of the string always precedes byte m+1 of the string, and byte 0 of the string always follows the string's length. If n is not a multiple of four, then the n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count a multiple of four. Counted byte strings are declared as follows: string object; or string object<>; The constant m denotes an upper bound of the number of bytes that a string may contain. If m is not specified, as in the second declaration, it is assumed to be (2**32) - 1, the maximum length. The constant m would normally be found in a protocol specification. For example, a filing protocol may state that a file name can be no longer than 255 bytes, as follows: string filename<255>; 0 1 2 3 4 5 ... +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+ | length n |byte0|byte1|...| n-1 | 0 |...| 0 | +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+ |<-------4 bytes------->|<------n bytes------>|<---r bytes--->| |<----n+r (where (n+r) mod 4 = 0)---->| STRING It is an error to encode a length greater than the maximum described in the specification.
public String readString()
public void dump(PrintStream out)
public byte[] getBytes()
public static byte[] append(byte[] bytes, byte[] bytesToAdd)
public static byte[] getVariableOpque(byte[] data)
public static int fragmentSize(byte[] mark)
public static boolean isLastFragment(byte[] mark)
public static boolean verifyLength(XDR xdr, int len)
public static org.jboss.netty.buffer.ChannelBuffer writeMessageTcp(XDR request, boolean last)
public static org.jboss.netty.buffer.ChannelBuffer writeMessageUdp(XDR response)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |