ANTS v2.0 API

ants.core
Class Xdr

java.lang.Object
  |
  +--ants.core.Xdr

public final class Xdr
extends java.lang.Object

An Xdr instance encapsulates an external, byte-oriented data structure (an "External Data Representation".) Xdr's can include Strings, byte arrays, booleans, bytes, shorts, ints, longs, TypeIDs. Elements must encoded/decoded serially to/from the Xdr.

Xdr's may be hierarchical. That is an xdr may subdivide its buffer space into child buffers.

Xdr's will allocate a byte[] when constructed, or alternatively they can use a given byte[], a ByteArray, another Xdr (parenting), or a Core Buffer.

These methods are declared final so that they can be inlined with optimization.

Author:
David Wetherall

Field Summary
static int BOOLEAN
          The length of a boolean in an xdr.
static int BYTE
          The length of a byte in an xdr.
static int INT
          The length of a int in an xdr.
static int LONG
          The length of a long in an xdr.
static int SHORT
          The length of a short in an xdr.
static int TYPEID
          The length of a typeid in an xdr.
 
Constructor Summary
Xdr(byte[] buf)
          Create a new xdr using the given buffer.
Xdr(byte[] buf, int offset)
          Create a new xdr using the given portion of the given buffer.
Xdr(byte[] buf, int offset, int len)
          Create a new xdr using the given portion of the given buffer.
Xdr(ByteArray buf, int offset)
          Create a new xdr using the buffer in the given ByteArray.
Xdr(ByteArray buf, int offset, int len)
          Create a new xdr using the buffer in the given ByteArray.
Xdr(int len)
          Create a new xdr with a buffer of len bytes for encoding.
 
Method Summary
 boolean BOOLEAN()
           
 byte BYTE()
           
 ByteArray BYTEARRAY()
           
static int BYTEARRAY(ByteArray x)
          Return the number of bytes required to encode a ByteArray in the xdr.
 void BYTES(byte[] x, int start, int length)
           
 int INT()
           
 int length()
          Return the size of the buffer used by this xdr.
 long LONG()
           
 void PUT(boolean x)
          Encode the given boolean into this xdr.
 void PUT(byte x)
           
 void PUT(byte[] x, int start, int length)
           
 void PUT(ByteArray x)
           
 void PUT(int x)
           
 void PUT(long x)
           
 void PUT(short x)
           
 void PUT(java.lang.String x)
           
 void PUT(TypeID t)
           
 short SHORT()
           
 void skip(int count)
           
 java.lang.String STRING()
           
static int STRING(java.lang.String x)
          Return the number of bytes required t encode x in the xdr.
 TypeID TYPEID()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN

public static final int BOOLEAN
The length of a boolean in an xdr.

BYTE

public static final int BYTE
The length of a byte in an xdr.

SHORT

public static final int SHORT
The length of a short in an xdr.

INT

public static final int INT
The length of a int in an xdr.

LONG

public static final int LONG
The length of a long in an xdr.

TYPEID

public static final int TYPEID
The length of a typeid in an xdr.
Constructor Detail

Xdr

public Xdr(int len)
Create a new xdr with a buffer of len bytes for encoding.
Parameters:
len - the size of the buffer to create.

Xdr

public Xdr(byte[] buf)
Create a new xdr using the given buffer. Does NOT copy the given buf.

XXX probably shouldn't be public.

Parameters:
buf - the buffer to use.

Xdr

public Xdr(ByteArray buf,
           int offset)
Create a new xdr using the buffer in the given ByteArray.
Parameters:
buf - the ByteArray to steal the byte[] from
offset - offset to start at in the ByteArray

Xdr

public Xdr(ByteArray buf,
           int offset,
           int len)
    throws java.lang.IndexOutOfBoundsException
Create a new xdr using the buffer in the given ByteArray.
Parameters:
buf - the ByteArray to steal the byte[] from
offset - offset to start at in the ByteArray
len - length of ByteArray to use

Xdr

public Xdr(byte[] buf,
           int offset)
Create a new xdr using the given portion of the given buffer.
Parameters:
buf - the buffer to use.
offset - only encode in the portion of the buffer starting at offset.

Xdr

public Xdr(byte[] buf,
           int offset,
           int len)
    throws java.lang.IndexOutOfBoundsException
Create a new xdr using the given portion of the given buffer.
Parameters:
buf - the buffer to use.
offset - only encode in the portion of the buffer starting at offset.
len - only encode using len bytes of the buffer.
Method Detail

STRING

public static final int STRING(java.lang.String x)
Return the number of bytes required t encode x in the xdr. Does not actually encode the string. Handles null strings just fine.

The string had best be less than 256 characters long.

The string had best be in ASCII. (Or some other one-to-one encoding of characters into bytes.)

Parameters:
x - the string to check
Returns:
the number of bytes required in the xdr

BYTEARRAY

public static final int BYTEARRAY(ByteArray x)
Return the number of bytes required to encode a ByteArray in the xdr. Does not actually encode the ByteArray. Handles null just fine.

The ByteArray must be less than 65,535 bytes.

Parameters:
x - the ByteArray to check
Returns:
the number of bytes required in the xdr.

length

public final int length()
Return the size of the buffer used by this xdr.
Returns:
the size of the buffer used by this xdr.

PUT

public final void PUT(boolean x)
Encode the given boolean into this xdr. There must be sufficient space in this xdr preallocated.

PUT

public final void PUT(byte x)

PUT

public final void PUT(short x)

PUT

public final void PUT(int x)

PUT

public final void PUT(long x)

PUT

public final void PUT(TypeID t)

PUT

public final void PUT(java.lang.String x)

PUT

public final void PUT(ByteArray x)

PUT

public final void PUT(byte[] x,
                      int start,
                      int length)

BOOLEAN

public final boolean BOOLEAN()

BYTE

public final byte BYTE()

SHORT

public final short SHORT()

INT

public final int INT()

LONG

public final long LONG()

TYPEID

public final TypeID TYPEID()

STRING

public final java.lang.String STRING()

BYTEARRAY

public final ByteArray BYTEARRAY()

BYTES

public final void BYTES(byte[] x,
                        int start,
                        int length)

skip

public final void skip(int count)

ANTS v2.0 API

This documentation is Copyright (C) 1998-2001 The University of Utah and the University of Washington. All Rights Reserved. See the individual source files for distribution terms.
Documentation, software, and mailing lists for ANTS v2.0 can be found at the Janos Project: http://www.cs.utah.edu/flux/janos/