Package org.apache.hadoop.oncrpc
Class XDR
java.lang.Object
org.apache.hadoop.oncrpc.XDR
Utility class for building XDR messages based on RFC 4506.
Key points of the format:
- Primitives are stored in big-endian order (i.e., the default byte order of ByteBuffer).
- Booleans are stored as an integer.
- Each field in the message is always aligned by 4.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuffer()static intfragmentSize(byte[] mark) byte[]getBytes()static booleanisLastFragment(byte[] mark) booleanbyte[]readFixedOpaque(int size) longintreadInt()byte[]intsize()static booleanverifyLength(XDR xdr, int len) check if the rest of data has more than len bytes.voidwriteBoolean(boolean v) voidwriteFixedOpaque(byte[] src) voidwriteFixedOpaque(byte[] src, int length) voidwriteInt(int v) voidwriteLongAsHyper(long v) static io.netty.buffer.ByteBufwriteMessageTcp(XDR request, boolean last) Write an XDR message to a TCP ChannelBuffer.static io.netty.buffer.ByteBufwriteMessageUdp(XDR response) Write an XDR message to a UDP ChannelBuffer.voidvoidwriteVariableOpaque(byte[] src)
-
Constructor Details
-
XDR
public XDR(int initialCapacity) Construct a new XDR message buffer.- Parameters:
initialCapacity- the initial capacity of the buffer.
-
XDR
public XDR() -
XDR
-
XDR
public XDR(byte[] src) Wraps a byte array as a read-only XDR message. There's no copy involved, thus it is the client's responsibility to ensure that the byte array remains unmodified when using the XDR object.- Parameters:
src- the byte array to be wrapped.
-
-
Method Details
-
asReadOnlyWrap
-
buffer
-
size
public int size() -
readInt
public int readInt() -
writeInt
public void writeInt(int v) -
readBoolean
public boolean readBoolean() -
writeBoolean
public void writeBoolean(boolean v) -
readHyper
public long readHyper() -
writeLongAsHyper
public void writeLongAsHyper(long v) -
readFixedOpaque
public byte[] readFixedOpaque(int size) -
writeFixedOpaque
public void writeFixedOpaque(byte[] src, int length) -
writeFixedOpaque
public void writeFixedOpaque(byte[] src) -
readVariableOpaque
public byte[] readVariableOpaque() -
writeVariableOpaque
public void writeVariableOpaque(byte[] src) -
readString
-
writeString
-
verifyLength
check if the rest of data has more than len bytes.- Parameters:
xdr- XDR messagelen- minimum remaining length- Returns:
- specify remaining length is enough or not
-
writeMessageTcp
Write an XDR message to a TCP ChannelBuffer.- Parameters:
request- XDR requestlast- specifies last request or not- Returns:
- TCP buffer
-
writeMessageUdp
Write an XDR message to a UDP ChannelBuffer.- Parameters:
response- XDR response- Returns:
- UDP buffer
-
fragmentSize
public static int fragmentSize(byte[] mark) -
isLastFragment
public static boolean isLastFragment(byte[] mark) -
getBytes
@VisibleForTesting public byte[] getBytes()
-