org.jnetstream.packet
Class DataHeader

java.lang.Object
  extended by org.jnetstream.packet.DataHeader
All Implemented Interfaces:
com.slytechs.utils.namespace.Named, java.lang.Iterable<HeaderElement>, Header, HeaderElement

public class DataHeader
extends java.lang.Object
implements Header

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jnetstream.packet.Header
Header.DynamicProperty, Header.StaticProperty
 
Nested classes/interfaces inherited from interface com.slytechs.utils.namespace.Named
com.slytechs.utils.namespace.Named.Util
 
Constructor Summary
DataHeader(com.slytechs.utils.memory.BitBuffer buffer, int length, int offset)
           
 
Method Summary
 Field<?>[] getAllFields()
           
 Header[] getAllHeaders()
           
 com.slytechs.utils.memory.BitBuffer getBuffer()
          Returns buffer containing the header's data.
<T> Field<T>
getField(DataField field)
          Retrieves field's runtime environment.
 DataField getFieldConstant()
           
 int getLength()
          Returns the length of this header in bytes.
 java.lang.String getName()
          Returns the NPL name of this header.
 int getOffset()
          Position or offset from the start of the packet buffer this buffer belongs to.
<T> T
getProperty(Header.DynamicProperty key)
           
<T> T
getProperty(Header.StaticProperty key)
           
<T> T
getProperty(java.lang.String name)
           
 Protocol getProtocol()
           
 java.lang.Class<? extends Header> getType()
           
 boolean isTruncated()
          Tells if this header has been truncated or if all of the headers contents are contained within the packet buffer.
 java.util.Iterator<HeaderElement> iterator()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataHeader

public DataHeader(com.slytechs.utils.memory.BitBuffer buffer,
                  int length,
                  int offset)
Parameters:
buffer -
length -
offset -
Method Detail

getAllFields

public Field<?>[] getAllFields()
Specified by:
getAllFields in interface Header
Returns:

getAllHeaders

public Header[] getAllHeaders()
Specified by:
getAllHeaders in interface Header
Returns:

getBuffer

public com.slytechs.utils.memory.BitBuffer getBuffer()
                                              throws java.io.IOException
Description copied from interface: Header
Returns buffer containing the header's data. The buffer is backed by the packet buffer which contains all of the contents of the packet. The returned buffer position, limit and capacity properties are set to getPosition(), getPosition() + getLength() and getPosition() + getLength() respectively. No new data is allocated and any changes to the returned header buffer are also reflected in the backing packet buffer.

Specified by:
getBuffer in interface Header
Returns:
buffer which contains just the header data and is backed by the underlying packet buffer
Throws:
java.io.IOException

getField

public <T> Field<T> getField(DataField field)
                  throws CodecException,
                         java.io.IOException
Description copied from interface: Header
Retrieves field's runtime environment.

Specified by:
getField in interface Header
Type Parameters:
T - value type of the field
Returns:
the runtime evironment of the field
Throws:
CodecException
java.io.IOException

getLength

public int getLength()
Description copied from interface: Header
Returns the length of this header in bytes.

Specified by:
getLength in interface Header
Returns:
number of octets this header occupies

getName

public java.lang.String getName()
Description copied from interface: Header
Returns the NPL name of this header.

Specified by:
getName in interface com.slytechs.utils.namespace.Named
Specified by:
getName in interface Header
Returns:
name of this header

getOffset

public int getOffset()
Description copied from interface: Header
Position or offset from the start of the packet buffer this buffer belongs to.

Specified by:
getOffset in interface Header
Returns:
0-based offset of the start of this header in octets from the beginning of the packet buffer

getProperty

public <T> T getProperty(Header.StaticProperty key)
Specified by:
getProperty in interface Header
Returns:

getProperty

public <T> T getProperty(Header.DynamicProperty key)
Specified by:
getProperty in interface Header
Returns:

getProperty

public <T> T getProperty(java.lang.String name)
Specified by:
getProperty in interface Header
Returns:

getProtocol

public Protocol getProtocol()
Specified by:
getProtocol in interface Header
Returns:

getType

public java.lang.Class<? extends Header> getType()
Specified by:
getType in interface Header
Returns:

isTruncated

public boolean isTruncated()
                    throws java.io.IOException
Description copied from interface: Header
Tells if this header has been truncated or if all of the headers contents are contained within the packet buffer. Only what is considered as header content is included in this check as defined by the underlying NPL definition. Any data past the header content is not included in this check.

Specified by:
isTruncated in interface Header
Returns:
true if header contents have been truncated and entire header could not be decoded, otherwise false
Throws:
java.io.IOException

getFieldConstant

public DataField getFieldConstant()
Specified by:
getFieldConstant in interface HeaderElement
Returns:

iterator

public java.util.Iterator<HeaderElement> iterator()
Specified by:
iterator in interface java.lang.Iterable<HeaderElement>