java.net
Class ANEPOption

java.lang.Object
  |
  +--java.net.ANEPOption
All Implemented Interfaces:
ANEPOptionType

public class ANEPOption
extends java.lang.Object
implements ANEPOptionType

This class allow to create an ANEP options, this class is used to send options as well as to receive them.

When receiving option, you need to specified the length of data you expect to receive, if there is less data the length will be changed, if there is more the data will be truncated.

Due to constraint inside the anep option, the length of the payload could be greater that the number of bytes effecively put in it due to 32 bits alignment, so you can seem to receive MORE DATA that what you have send.

For information here is the structure of an ANEP option as it is send in the ANEP Packet (the length is expressed in 32bit words):

   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |FLG|       Option Type         |         Option Length         |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                               .                               |
  ~               Option Payload (Option Value)                   ~
  |                               .                               |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 


Field Summary
static int FLAG_DISCARD
          Flag to say if an unknown option should result in ignoring the option or discarding the whole packet.
static int FLAG_PRIVATE
          Flag to mark an option has private to the packet type.
static int MAX_LENGTH
          Maximal payload size for the option.
static int MAX_TYPE
          Maximal value that an ANEP option type can have.
static int USE_DEFAULT_FLAGS
          This is the default flags used when not specified
 
Fields inherited from interface java.net.ANEPOptionType
CHECKSUM, DSTID, NNAUTH, SRCID
 
Constructor Summary
ANEPOption(int type, byte[] payload, int offset, int length)
          Create an ANEP option which could be used when sending/receiving ANEP Packet.
ANEPOption(int type, int flags, byte[] payload, int offset, int length)
          Create an ANEP option which could be used when sending/receiving ANEP Packet.
 
Method Summary
 byte[] getData()
          Get the payload of this option.
 int getFlags()
          Get the flags of this option.
 int getLength()
          Get the length of the payload.
 int getOffset()
          Returns the offset of the data to be sent or the offset of the data received.
 int getType()
          Get the type of this option.
 boolean isReceived()
          Returns a boolean to indicate if this option has been received whithin the ANEP packet.
 void setData(byte[] payload, int offset, int length)
          Set the data buffer for this option.
 void setFlags(int flags)
          Set the flag for this option.
 void setLength(int length)
          Set the length of the payload to send.
 void setType(int type)
          Set the type of the option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAG_PRIVATE

public static final int FLAG_PRIVATE
Flag to mark an option has private to the packet type. (ie: this option will only be interpreted by the application)

FLAG_DISCARD

public static final int FLAG_DISCARD
Flag to say if an unknown option should result in ignoring the option or discarding the whole packet.

USE_DEFAULT_FLAGS

public static final int USE_DEFAULT_FLAGS
This is the default flags used when not specified

MAX_TYPE

public static final int MAX_TYPE
Maximal value that an ANEP option type can have.

MAX_LENGTH

public static final int MAX_LENGTH
Maximal payload size for the option. But this doesn't imply you will be able to send a packet if the option has such a size, due to constraint on the lower layer transport.
Constructor Detail

ANEPOption

public ANEPOption(int type,
                  int flags,
                  byte[] payload,
                  int offset,
                  int length)
Create an ANEP option which could be used when sending/receiving ANEP Packet. The offset combined with the length should not exced the size of the payload buffer (payload.length).
Parameters:
type - type of the option
flags - option flags
payload - option payload
offset - offset for the payload
length - length for the payload
See Also:
FLAG_PRIVATE, FLAG_DISCARD, ANEPOptionType

ANEPOption

public ANEPOption(int type,
                  byte[] payload,
                  int offset,
                  int length)
Create an ANEP option which could be used when sending/receiving ANEP Packet. The offset combined with the length should not exced the size of the payload buffer (payload.length).
Parameters:
type - type of the option
payload - option payload
offset - offset for the payload
length - length for the payload
See Also:
FLAG_PRIVATE, FLAG_DISCARD, ANEPOptionType
Method Detail

setType

public void setType(int type)
Set the type of the option.
Parameters:
type - type of the option
See Also:
ANEPOptionType

setFlags

public void setFlags(int flags)
Set the flag for this option. (the two supported flags are FLAG_DISCARD and FLAG_PRIVATE).
Parameters:
flags - flags of the option
See Also:
FLAG_PRIVATE, FLAG_DISCARD

setData

public void setData(byte[] payload,
                    int offset,
                    int length)
Set the data buffer for this option. This sets the payload, length and offset of the option. The offset combined with the length should not exced the size of the payload buffer (payload.length).

If the payload is null, the offset and length are automatically set to 0.

Parameters:
payload - option payload
offset - offset for the payload
length - lenght for the payload
See Also:
ANEPPacket, getData(), getOffset(), getLength()

getType

public int getType()
Get the type of this option. The value is not necessarily the one set with setType, has it could have changed after having received an ANEP packet.
Returns:
the option type

getFlags

public int getFlags()
Get the flags of this option. The value is not necessarily the one set with setFlags, has it could have changed after having received an ANEP packet.
Returns:
flags value

getData

public byte[] getData()
Get the payload of this option. The value is not necessarily the one set with setData, has it could have changed after having received an ANEP packet.
Returns:
the option payload

getLength

public int getLength()
Get the length of the payload. The value is not necessarily the one set with setData, has it could have changed after having received an ANEP packet.
Returns:
payload length

setLength

public void setLength(int length)
Set the length of the payload to send.
Parameters:
length - length of the payload to send.
Throws:
java.lang.IllegalArgumentException - if the length is out of range or if there was no payload buffer previously associated.

getOffset

public int getOffset()
Returns the offset of the data to be sent or the offset of the data received.
Returns:
the offset of the data to be sent or the offset of the data received.

isReceived

public boolean isReceived()
Returns a boolean to indicate if this option has been received whithin the ANEP packet. It's return value is only meaningful after having succesfully received an ANEP packet.
Returns:
the state of the option (received or not)