Class XDR

java.lang.Object
org.apache.hadoop.oncrpc.XDR

public final class XDR extends Object
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.
  • 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

      public XDR(ByteBuffer buf, XDR.State state)
    • 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

      public XDR asReadOnlyWrap()
    • buffer

      public ByteBuffer 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

      public String readString()
    • writeString

      public void writeString(String s)
    • verifyLength

      public static boolean verifyLength(XDR xdr, int len)
      check if the rest of data has more than len bytes.
      Parameters:
      xdr - XDR message
      len - minimum remaining length
      Returns:
      specify remaining length is enough or not
    • writeMessageTcp

      public static io.netty.buffer.ByteBuf writeMessageTcp(XDR request, boolean last)
      Write an XDR message to a TCP ChannelBuffer.
      Parameters:
      request - XDR request
      last - specifies last request or not
      Returns:
      TCP buffer
    • writeMessageUdp

      public static io.netty.buffer.ByteBuf writeMessageUdp(XDR response)
      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()