com.neeve.pkt
Class PktHeader

java.lang.Object
  extended by com.neeve.util.UtlListElement
      extended by com.neeve.pkt.PktSerializable
          extended by com.neeve.pkt.PktHeader
All Implemented Interfaces:
com.neeve.io.IOElasticBuffer.Initializer, com.neeve.io.IOElasticBuffer.Sizer

public final class PktHeader
extends PktSerializable
implements com.neeve.io.IOElasticBuffer.Initializer

Represents the header portion of a packet.

A packet consists of a header, body and tags. This class represents the header portion of the packet. The header consists of a fixed portion and a variable portion. The variable portion is in the form of subheaders.

The packet header is a versioned entity. The header version defines the format of the header i.e. what fields comprise the header and their relative locations when serialized. A crucial aspect of header versioning is that a version N header will always be a subset of a version M header where N < M i.e. all fields in version N of a header will be present and in the same position as fields in version M of the header. i.e. a header never shrinks or moves fields around. With time, the header can only grow. See the setter/getter method documentation for information on which header version the fields that they affect belong to.

Threading:
Packet headers are not safe for concurrent access by multiple threads.

Nested Class Summary
 
Nested classes/interfaces inherited from class com.neeve.pkt.PktSerializable
PktSerializable.DeserializeContext, PktSerializable.SerializeContext
 
Field Summary
static int MAGIC
           
static int MAGIC_SIZE
           
static short MAX_HTL
           
static int STATIC_HEADER_LENGTH
           
 
Fields inherited from class com.neeve.util.UtlListElement
count, head, next, prev
 
Method Summary
 PktSubheaderFMC activateFMCSubheader(boolean reset)
          Activate the fabric multicast subheader.
 PktSubheaderFUC activateFUCSubheader(boolean reset)
          Activate the fabric unicast subheader.
 PktSubheaderODS activateODSSubheader(boolean reset)
          Activate the ODS subheader.
 PktSubheaderRR activateRRSubheader(boolean reset)
          Activate the request-reply subheader.
 PktSubheaderSMA activateSMASubheader(boolean reset)
          Activate the SMA subheader.
static void clearMagic(ByteBuffer buffer, int offset)
          Clear the magic number from a serialized header
static void clearMagic(PktBuffer buffer, int offset)
          Clear the magic number from a serialized header
static PktHeader create(PktBody body, Properties props)
          Create a packet header
 void deactivateFMCSubheader()
          Deactivate the fabric multicast subheader.
 void deactivateFUCSubheader()
          Deactivate the fabric unicast subheader.
 void deactivateODSSubheader()
          Deactivate the ODS subheader.
 void deactivateRRSubheader()
          Deactivate the request-reply subheader.
 void deactivateSMASubheader()
          Deactivate the SMA subheader.
 int deserialize(ByteBuffer buf, int bufOffset)
          Deserialize a packet header from a byte buffer
 int deserialize(com.neeve.io.IOBuffer iobuf, int iobufOffset, boolean wrap)
          Deserialize a packet header from an IO buffer
 void deserialize(PktSerializable.DeserializeContext context, int headerSerializedLength, Tracer tracer)
          Implementation of PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer).
 PktBody getBody()
          Get the body associated with this header
 int getBodyType()
          Get the packet body type (V1 Header Field).
static int getBodyType(ByteBuffer buffer, int offset)
          Get the body type from a serialized header.
static int getBodyType(PktBuffer buffer, int offset)
          Get the body type from a serialized header.
 PktBuffer getBuffer()
          Get the internal header buffer.
 short getClazz()
          Get the packet class (V1 Header Field).
 int getDest()
          Get the packet destination fabric address (V1 Header Field).
 short getDestPort()
          Get the packet destination port (V1 Header Field).
 int getFlow()
          Get the packet flow (V1 Header Field).
 PktSubheaderFMC getFMCSubheader()
          Get the packet fabric multicast subheader.
 PktSubheaderFUC getFUCSubheader()
          Get the packet fabric unicast subheader.
 short getHtl()
          Get the packet 'hops to live' (V1 Header Field).
 int getInitialBufferLength()
          Implementation of IOElasticBuffer.Sizer.getInitialBufferLength()
static short getLatestVersion()
          Get the latest header version.
 int getLength()
          Get the packet length (V1 Header Field).
 boolean getNoBuffering()
          Get the 'no buffering' flag (V1 Header Field).
 short getNumSubheaders()
          Get the number of attached subheaders (V1 Header Field).
 PktSubheaderODS getODSSubheader()
          Get the packet ODS subheader.
 boolean getReplyExpected()
          Get the 'reply expected' flag (V1 Header Field).
 PktSubheaderRR getRRSubheader()
          Get the request-reply subheader.
 int getSerializedLength()
          Implementation of PktSerializable.getSerializedLength() This method returns the serialized length of the static header plus the serialized length of all attached subheaders.
 PktSubheaderSMA getSMASubheader()
          Get the packet SMA subheader.
 int getSrc()
          Get the packet source fabric address (V1 Header Field).
 short getSrcPort()
          Get the packet source port (V1 Header Field).
 int getStaticSerializedLength()
          Get the serialized length of the only the static portion of the header.
 short getVersion()
          Get the header format version (V1 Header Field).
static boolean hasMagic(ByteBuffer buffer, int offset)
          Check if a serialized buffer is start of a packet
 void initializeBuffer()
          Implementation of IOElasticBuffer.Initializer.initializeBuffer()
static int preDeserialize(ByteBuffer buf, int bufOffset, int length)
          Parse and return length of a serialized packet in a byte buffer
static int preDeserialize(com.neeve.io.IOBuffer iobuf, int iobufOffset, int length)
          Parse and return length of a serialized packet in an IO buffer
static boolean preDeserialize(PktSerializable.DeserializeContext context)
          Perform pre-deserialization checks.
 void reset()
          Reset the contents of a packet header.
static void restoreClearedMagic(ByteBuffer buffer, int offset)
          Restore the magic number cleared from a serialized header using clearMagic(java.nio.ByteBuffer, int)
static void restoreClearedMagic(PktBuffer buffer, int offset)
          Restore the magic number cleared from a serialized header using clearMagic(java.nio.ByteBuffer, int)
 int serialize(byte[] array, int arrayOffset)
          Serialize a packet header to a byte array
 int serialize(ByteBuffer buf)
          Serialize a packet header to a byte buffer
 int serialize(ByteBuffer buf, int bufOffset)
          Serialize a packet header to a byte buffer
 int serialize(com.neeve.io.IOBuffer iobuf, int iobufOffset)
          Serialize a packet header to an IO buffer
 int serialize(com.neeve.io.IOElasticBuffer iobuf, int iobufOffset)
          Serialize a packet header to an elastic IO buffer
 int serialize(long address, int addressOffset)
          Serialize a packet header to a native memory region
 void serialize(PktSerializable.SerializeContext context, Tracer tracer)
          Implementation of PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer).
 void setClazz(short clazz)
          Set the packet class (V1 Header Field).
 void setDeserializationPolicy(int policy)
          Implementation of PktSerializable.setDeserializationPolicy(int).
 void setDest(int addr)
          Set the packet destination fabric address (V1 Header Field).
 void setDestPort(short port)
          Set the packet destination port (V1 Header Field).
 void setFlow(int flow)
          Set the packet flow (V1 Header Field).
 void setHtl(short htl)
          Set the packet 'hops to live' (V1 Header Field).
 void setNoBuffering(boolean val)
          Set the 'no buffering' flag (V1 Header Field).
 void setReplyExpected(boolean val)
          Set the 'reply expected' flag (V1 Header Field).
 void setSerializationPolicy(int policy)
          Implementation of PktSerializable.setSerializationPolicy(int).
 void setSrc(int addr)
          Set the packet source fabric address (V1 Header Field).
 void setSrcPort(short port)
          Set the packet source port(V1 Header Field).
 String toString()
          Return a string representation of the object.
 
Methods inherited from class com.neeve.pkt.PktSerializable
deserialize, getDeserializationPolicy, getSerializationPolicy, isValidDeserializationPolicy, isValidSerializationPolicy, serialize
 
Methods inherited from class com.neeve.util.UtlListElement
count, insertAfter, insertBefore, isLinked, next, previous, unlink, wipe
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATIC_HEADER_LENGTH

public static final int STATIC_HEADER_LENGTH
See Also:
Constant Field Values

MAGIC_SIZE

public static final int MAGIC_SIZE
See Also:
Constant Field Values

MAGIC

public static final int MAGIC
See Also:
Constant Field Values

MAX_HTL

public static final short MAX_HTL
See Also:
Constant Field Values
Method Detail

create

public static PktHeader create(PktBody body,
                               Properties props)
Create a packet header

Parameters:
body - The associated body
props - Property set to use in the creation of the packet header. Currently, the header does not support any creation or operational properties. This is present for future compatibility.
Returns:
Returns the created packet header

This method creates a packet header. The created header has all header elements initialized to their default values. The type and length elements are initialized as 0 upon return from this method. The type element is initialized when a packet body is associated with the header. The length field is initialized when the header is serialized. or initialized through deserialization.

Note that this method creates a standalone header that is not associated with a packet body. A public user should only use this method in case that is what is desired i.e. a standalone header with no associated body. To create a packet header asociated with a body, the user should not use this method directly. The PktFactory packet creation methods should be used which create and associate packet headers and bodies.

Threading:
This method is safe for concurrent access by multiple threads

preDeserialize

public static final int preDeserialize(ByteBuffer buf,
                                       int bufOffset,
                                       int length)
Parse and return length of a serialized packet in a byte buffer

Parameters:
buf - The buffer containing the packet
bufOffset - The offset into the buffer where the packet starts
length - The number of valid bytes starting from the offset
Returns:
Returns the length of the serialized packet. Returns -1 if the length cannot be determined

This method parses the supplied buffer and attempts to return the length of the serialized packet starting at the supplied offset. It only considers the supplied length. If the supplied length is not enough to determine the serialized length, then this method returns 0. Otherwise, it checks the integrity of the packet by validating the magic and version and then returns the length of the packet. Note that the returned length may be more than the supplied length in which case the full packet is not present in the buffer.

Throws:
EPktCorruptException - Thrown if a valid packet does not start at the specified offset in he buffer
EPktVersionInvalidException - Thrown in case the buffer contains a serialized packet with an invalid header format version
Threading:
This method is safe for concurrent access by multiple threads

preDeserialize

public static final int preDeserialize(com.neeve.io.IOBuffer iobuf,
                                       int iobufOffset,
                                       int length)
Parse and return length of a serialized packet in an IO buffer

Parameters:
iobuf - The buffer containing the packet
iobufOffset - The offset into the buffer where the packet starts
length - The number of valid bytes starting from the offset
Returns:
Returns the length of the serialized packet. Returns -1 if the length cannot be determined

This method parses the supplied buffer and attempts to return the length of the serialized packet starting at the supplied offset. It only considers the supplied length. If the supplied length is not enough to determine the serialized length, then this method returns 0. Otherwise, it checks the integrity of the packet by validating the magic and version and then returns the length of the packet. Note that the returned length may be more than the supplied length in which case the full packet is not present in the buffer.

Throws:
EPktCorruptException - Thrown if a valid packet does not start at the specified offset in he buffer
EPktVersionInvalidException - Thrown in case the buffer contains a serialized packet with an invalid header format version
Threading:
This method is safe for concurrent access by multiple threads

preDeserialize

public static final boolean preDeserialize(PktSerializable.DeserializeContext context)
                                    throws EPktCorruptException,
                                           EPktVersionInvalidException
Perform pre-deserialization checks.

Parameters:
context - The context to use for the predeserialization process. See PktSerializable.DeserializeContext for more information.
Returns:
Returns whether the buffer contains a full serialized packet.

This method validates that the remaining data in the provided byte buffer contains a valid and full serialized packet. If not valid, a EPktCorruptException is thrown. If valid but the header format version is incorrect, a EPktVersionInvalidException is thrown. If valid but not complete, the method returns false and provides information in the context parameter as to how much additional data is needed to oomplete the packet. If the byte buffer contains a valid and complete packet, the context parameter is unchanged.

This method does not actually initialize the header from the provided buffer. It just serves as a deserialization prologue to check the integrity of the header and whether enough data is present to deserialize a complete packet. The markers of the provided buffer are not modified by this method. The user should call this method and, in case this method returns successfully, instantiate a packet header and initialize it using the deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer) method.

Throws:
EPktCorruptException - Thrown if the provided byte buffer does not contain a valid serialized packet.
EPktVersionInvalidException - Thrown in case the serialized buffer contains an invalid header format version
Threading:
This method is safe for concurrent access by multiple threads

clearMagic

public static final void clearMagic(ByteBuffer buffer,
                                    int offset)
Clear the magic number from a serialized header


clearMagic

public static final void clearMagic(PktBuffer buffer,
                                    int offset)
Clear the magic number from a serialized header


restoreClearedMagic

public static final void restoreClearedMagic(ByteBuffer buffer,
                                             int offset)
Restore the magic number cleared from a serialized header using clearMagic(java.nio.ByteBuffer, int)


restoreClearedMagic

public static final void restoreClearedMagic(PktBuffer buffer,
                                             int offset)
Restore the magic number cleared from a serialized header using clearMagic(java.nio.ByteBuffer, int)


hasMagic

public static final boolean hasMagic(ByteBuffer buffer,
                                     int offset)
Check if a serialized buffer is start of a packet


getLatestVersion

public static final short getLatestVersion()
Get the latest header version.

This method returns the latest header version i.e. the version used when headers are created explicitly i.e. not through deserialization

Threading:
This method is safe for concurrent access by multiple threads

getVersion

public final short getVersion()
Get the header format version (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

getLength

public final int getLength()
Get the packet length (V1 Header Field).

This method returns the packet length set in the packet header. This field is set by the serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) method and can be used by the user after a call to serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) to check the length of the serialized packet. Note that although this field contains the length of the full packet, the serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) method does not serialize the attached body (if present). That is the responsibility of the user.

Threading:
This method is not safe for concurrent access by multiple threads

setSrc

public final void setSrc(int addr)
Set the packet source fabric address (V1 Header Field).

Parameters:
addr - The fabric address to set
Threading:
This method is not safe for concurrent access by multiple threads

getSrc

public final int getSrc()
Get the packet source fabric address (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setDest

public final void setDest(int addr)
Set the packet destination fabric address (V1 Header Field).

Parameters:
addr - The fabric address to set
Threading:
This method is not safe for concurrent access by multiple threads

getDest

public final int getDest()
Get the packet destination fabric address (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setSrcPort

public final void setSrcPort(short port)
Set the packet source port(V1 Header Field).

Parameters:
port - The port to set
Threading:
This method is not safe for concurrent access by multiple threads

getSrcPort

public final short getSrcPort()
Get the packet source port (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setDestPort

public final void setDestPort(short port)
Set the packet destination port (V1 Header Field).

Parameters:
port - The port to set
Threading:
This method is not safe for concurrent access by multiple threads

getDestPort

public final short getDestPort()
Get the packet destination port (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setFlow

public final void setFlow(int flow)
Set the packet flow (V1 Header Field).

Parameters:
flow - The packet flow to set
Threading:
This method is not safe for concurrent access by multiple threads

getFlow

public final int getFlow()
Get the packet flow (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setNoBuffering

public final void setNoBuffering(boolean val)
Set the 'no buffering' flag (V1 Header Field).

This method is used to specify that the packet should be delivered to the intended destination with as little latency as possible. This flag is used by intermediate network links as a directive to not buffer the packet but to flush it through the network ASAP.

Threading:
This method is not safe for concurrent access by multiple threads

getNoBuffering

public final boolean getNoBuffering()
Get the 'no buffering' flag (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setReplyExpected

public final void setReplyExpected(boolean val)
Set the 'reply expected' flag (V1 Header Field).

This method is used to specify that the packet is the request in a request-reply exchange.

Threading:
This method is not safe for concurrent access by multiple threads

getReplyExpected

public final boolean getReplyExpected()
Get the 'reply expected' flag (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setHtl

public final void setHtl(short htl)
Set the packet 'hops to live' (V1 Header Field).

Parameters:
htl - The htl to set. Although the type of this parameter is short, it is encoded on the wire as a single byte. Thus, only the lower byte is used from this parameter. The reason for this is that we want to treat htl as an 'unsigned byte'
Threading:
This method is not safe for concurrent access by multiple threads

getHtl

public final short getHtl()
Get the packet 'hops to live' (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

setClazz

public final void setClazz(short clazz)
Set the packet class (V1 Header Field).

Parameters:
clazz - The packet class to set. Although the type of this parameter is short, it is encoded on the wire as a single byte. Thus, only the lower byte is used from this parameter. The reason for this is that we want to treat clazz as an 'unsigned byte'
Threading:
This method is not safe for concurrent access by multiple threads

getClazz

public final short getClazz()
Get the packet class (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

getBodyType

public final int getBodyType()
Get the packet body type (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

getBodyType

public static final int getBodyType(PktBuffer buffer,
                                    int offset)
Get the body type from a serialized header.

This method returns the body type encoded in a serialized packet header. If the header was serialized without an attached body, then the type field will be zero in the serialized header.

The body type field is only guaranteed to be set during header serialization time into the serialization buffer which may be different from the header buffer depending on the serialization policy used. Thus, even if the body is set in a header, it is not guaranteed that the header buffer will contain the serialized body type prior to serialization or even after serialization in case the header was copied into a separate buffer during serialization. Therefore, this method is only reliable for use to get the body type from a serialized header.

Threading:
This method is not safe for concurrent access by multiple threads

getBodyType

public static final int getBodyType(ByteBuffer buffer,
                                    int offset)
Get the body type from a serialized header.

See Also:
getBodyType(PktBuffer, int)

getNumSubheaders

public final short getNumSubheaders()
Get the number of attached subheaders (V1 Header Field).

Threading:
This method is not safe for concurrent access by multiple threads

getBuffer

public final PktBuffer getBuffer()
Get the internal header buffer.

Returns:
The header buffer

This method returns the internal buffer used to store elements of the static portion of the header. Each subheader maintains its own buffer. The user must not modify the contents of this buffer. Use the header element setter/getter methods to modify the contents of the buffer.

Threading:
This method is not safe for concurrent access by multiple threads

activateRRSubheader

public final PktSubheaderRR activateRRSubheader(boolean reset)
Activate the request-reply subheader.

Parameters:
reset - Indicates whether the subheader should be reset after activation. This flag is only present for those situations where the user deactivates a subheader and then reactivates for use but only partially re-populates the header after re-activation.
Threading:
This method is not safe for concurrent access by multiple threads

It is safe to activate an already active sub-header.


deactivateRRSubheader

public final void deactivateRRSubheader()
Deactivate the request-reply subheader.

Threading:
This method is not safe for concurrent access by multiple threads

It is safe to deactivate an already inactive sub-header.


getRRSubheader

public final PktSubheaderRR getRRSubheader()
Get the request-reply subheader.

Returns:
Returns the packet's request-reply subheader. A return value of null indicates that no request-reply subheader is presently set in the packet header
Threading:
This method is not safe for concurrent access by multiple threads

activateFMCSubheader

public final PktSubheaderFMC activateFMCSubheader(boolean reset)
Activate the fabric multicast subheader.

Parameters:
reset - Indicates whether the subheader should be reset after activation. This flag is only present for those situations where the user deactivates a subheader and then reactivates for use but only partially re-populates the header after re-activation.
Threading:
This method is not safe for concurrent access by multiple threads

It is safe to activate an already active sub-header.


deactivateFMCSubheader

public final void deactivateFMCSubheader()
Deactivate the fabric multicast subheader.

Threading:
This method is not safe for concurrent access by multiple threads

It is safe to deactivate an already inactive sub-header.


getFMCSubheader

public final PktSubheaderFMC getFMCSubheader()
Get the packet fabric multicast subheader.

Returns:
Returns the packet's fabric multicast subheader. A return value of null indicates that no fabric multicast subheader is presently set in the packet header
Threading:
This method is not safe for concurrent access by multiple threads

activateFUCSubheader

public final PktSubheaderFUC activateFUCSubheader(boolean reset)
Activate the fabric unicast subheader.

Parameters:
reset - Indicates whether the subheader should be reset after activation. This flag is only present for those situations where the user deactivates a subheader and then reactivates for use but only partially re-populates the header after re-activation.
Threading:
This method is not safe for concurrent access by multiple threads

It is safe to activate an already active sub-header.


deactivateFUCSubheader

public final void deactivateFUCSubheader()
Deactivate the fabric unicast subheader.

Threading:
This method is not safe for concurrent access by multiple threads

It is safe to deactivate an already inactive sub-header.


getFUCSubheader

public final PktSubheaderFUC getFUCSubheader()
Get the packet fabric unicast subheader.

Returns:
Returns the packet's fabric unicast (FUC) subheader. A return value of null indicates that no FUC subheader is presently set in the packet header
Threading:
This method is not safe for concurrent access by multiple threads

activateSMASubheader

public final PktSubheaderSMA activateSMASubheader(boolean reset)
Activate the SMA subheader.

Parameters:
reset - Indicates whether the subheader should be reset after activation. This flag is only present for those situations where the user deactivates a subheader and then reactivates for use but only partially re-populates the header after re-activation.
Threading:
This method is not safe for concurrent access by multiple threads

It is safe to activate an already active sub-header.


deactivateSMASubheader

public final void deactivateSMASubheader()
Deactivate the SMA subheader.

Threading:
This method is not safe for concurrent access by multiple threads

It is safe to deactivate an already inactive sub-header.


getSMASubheader

public final PktSubheaderSMA getSMASubheader()
Get the packet SMA subheader.

Returns:
Returns the packet's SMA subheader. A return value of null indicates that no SMA subheader is presently set in the packet header
Threading:
This method is not safe for concurrent access by multiple threads

activateODSSubheader

public final PktSubheaderODS activateODSSubheader(boolean reset)
Activate the ODS subheader.

Parameters:
reset - Indicates whether the subheader should be reset after activation. This flag is only present for those situations where the user deactivates a subheader and then reactivates for use but only partially re-populates the header after re-activation.
Threading:
This method is not safe for concurrent access by multiple threads

It is safe to activate an already active sub-header.


deactivateODSSubheader

public final void deactivateODSSubheader()
Deactivate the ODS subheader.

Threading:
This method is not safe for concurrent access by multiple threads

It is safe to deactivate an already inactive sub-header.


getODSSubheader

public final PktSubheaderODS getODSSubheader()
Get the packet ODS subheader.

Returns:
Returns the packet's ODS subheader. A return value of null indicates that no ODS subheader is presently set in the packet header
Threading:
This method is not safe for concurrent access by multiple threads

getBody

public final PktBody getBody()
Get the body associated with this header


reset

public final void reset()
Reset the contents of a packet header.

This method resets the contents of a header. Upon return from this method, the contents of the header are the same as a freshly created header of the latest header version.

This method retains its reference to it container packet (if any).

This method is intended for use with object pools through which packet header objects can be recycled rather than created fresh every time.


setSerializationPolicy

public final void setSerializationPolicy(int policy)
Implementation of PktSerializable.setSerializationPolicy(int).

Overrides:
setSerializationPolicy in class PktSerializable
Parameters:
policy - The serialization policy to use for this entity. The following are the permissible serialization policies:
PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_ATTACH
PktConstants.SERIALIZE_POLICY_HEADER_ATTACH_BODY_ATTACH

serialize

public final void serialize(PktSerializable.SerializeContext context,
                            Tracer tracer)
                     throws EPktSerializeException
Implementation of PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer).

This method serializes the packet header into the buffer list in the specified serialization context. This method invokes PktSerializable.resolveSerializationPolicy(int) using the policy in the specified context to resolve the serialization policy to use. The default serialization policy set in this entity is determined using the configuration information for the type of the packet being serialized.

The user should note that this method only serializes the packet header. The user is responsible for serializing the packet body separately.

Specified by:
serialize in class PktSerializable
Parameters:
context - The context to be used by the serialization process. See PktSerializable.SerializeContext for more information.
tracer - Tracer used to output serialization related trace. Can be null in which case no trace is output.
Throws:
EPktSerializeException - Thrown in case an error is encountered during the serialization process.

This method serializes a serialiable entity into a byte array presented as a set of byte buffers. As input, this method accepts a serialization context that, among other fields, contains a list of buffers of type {link java.nio.ByteBuffer} into which the entity is to serialize itself. The serialization operation is policy driven and the policy determines whether the header is copied into space remaining in the provided buffers or whether the internal entity buffers are just appended to the provided buffer list. In case the decision is made to copy the serialized data into the provided buffers, the data is always copied into the last buffer in the list. In case the last buffer does not contain enough remaining space to accomodate all the serialized data, this method will allocate and append a new buffer that will be of the same type and capacity as the last buffer in the provided list. Read the documentation of the policy constants to understand which policies cause the header to be copied as opposed to appended (the policy constant names are also self descriptive)


serialize

public final int serialize(ByteBuffer buf)
Serialize a packet header to a byte buffer

Parameters:
buf - The byte buffer to serialize to
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet header by copying the contents of the packet header's buffer to a byte buffer. This method copies the contents to the target buffer starting at the target buffer's position. This method does not change any of the markers of the target byte buffer.

Note:Since this method does not change any markers of the target buffer, the caller needs to ensure the buffer limit is set correctly to accommodate the header's contents. The caller can invoke getSerializedLength() to get the length of the header's contents and use that to set the target buffer's limit before invoking this method.

serialize

public final int serialize(ByteBuffer buf,
                           int bufOffset)
Serialize a packet header to a byte buffer

Parameters:
buf - The byte buffer to serialize to
bufOffset - The offset into the buffer where the serialized contents of the packet header needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet header by copying the contents of the packet header's buffer to a byte buffer. This method copies the contents to the target buffer starting at the supplied buffer offset. This method does not change any of the markers of the target byte buffer.

Note:Since this method does not change any markers of the target buffer, the caller needs to ensure the buffer limit is set correctly to accommodate the header's contents. The caller can invoke getSerializedLength() to get the length of the header's contents and use that to set the target buffer's limit before invoking this method.

serialize

public final int serialize(byte[] array,
                           int arrayOffset)
Serialize a packet header to a byte array

Parameters:
array - The byte array to serialize to
arrayOffset - The offset into the array where the serialized contents of the packet header needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet header by copying the contents of the packet header's buffer to a byte array.


serialize

public final int serialize(com.neeve.io.IOBuffer iobuf,
                           int iobufOffset)
Serialize a packet header to an IO buffer

Parameters:
iobuf - The IO buffer to serialize to
iobufOffset - The offset into the IO buffer where the serialized contents of the packet header needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet header by copying the contents of the packet header's buffer to a IO buffer.


serialize

public final int serialize(com.neeve.io.IOElasticBuffer iobuf,
                           int iobufOffset)
Serialize a packet header to an elastic IO buffer

Parameters:
iobuf - The IO buffer to serialize to
iobufOffset - The offset into the IO buffer where the serialized contents of the packet header needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet header by copying the contents of the packet header's buffer to an elastic IO buffer.


serialize

public final int serialize(long address,
                           int addressOffset)
Serialize a packet header to a native memory region

Parameters:
address - The address of the native memory region to serialize to
addressOffset - The offset into the memory region where the serialized contents of the packet header should be serialized to.
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet header by copying the contents of the packet header's buffer to a native memory region.


setDeserializationPolicy

public final void setDeserializationPolicy(int policy)
Implementation of PktSerializable.setDeserializationPolicy(int).

Overrides:
setDeserializationPolicy in class PktSerializable
Parameters:
policy - The deserialization policy to use for this entity. The following are the permissible serialization policies:
PktConstants.DESERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.DESERIALIZE_POLICY_HEADER_COPY_BODY_SLICE
PktConstants.DESERIALIZE_POLICY_HEADER_SLICE_BODY_SLICE

deserialize

public final void deserialize(PktSerializable.DeserializeContext context,
                              int headerSerializedLength,
                              Tracer tracer)
                       throws EPktDeserializeException
Implementation of PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer).

This method does not does not check for packet integrity or whether the buffer contains a full packet header or not. The user should call preDeserialize(java.nio.ByteBuffer, int, int) before invoking this method to check for packet integrity and whether the buffer contains a full packet before calling this method. This method should only be subsequently called in case the preDeserialize(java.nio.ByteBuffer, int, int) method returns successfully i.e. the serialized packet has correct integrity and the full packet is contained in the buffer. Calling this method using a corrupt or incomplete buffer has undefined results.

This method invokes PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer) using the policy in the specified context to reolve the deserialization policy to use. The default deserialization policy set in this entity is determined using the configuration information for the type of the packet being deserialized.

Specified by:
deserialize in class PktSerializable
Parameters:
context - The context to be used by the deserialization process. See PktSerializable.DeserializeContext for more information.
headerSerializedLength - This parameter is present for entities whose serialized form does not contain the serialized length of the entity. For such entities, the caller needs to pass in the serialized length to the entity during deserialize time. For other entities, this value will be ignored and should be set to -1 (some entities that pull the length from the serialized form may indeed validate that the passed in value is -1)
tracer - Tracer used to output deserialization related trace. Can be null in which case no trace is output.
Throws:
EPktDeserializeException - Thrown in case an error is encountered during the deserialization process.

This method initializes a serializable entity from a byte buffer. As input, this method accepts a deserialization context that contains, in addition to other fields, a ByteBuffer from where the entity is to be initialized. It is assumed that the caller has validated (using some other means) that the buffer contains enough data to initialize the entity. Upon successful return, the context is updated with information relating to the deserialization e.g. how many bytes were consumed from the buffer to initialize the entity and whether a reference to the buffer is being retained by the entity subsequent to returning from this method. Refer to the context documentation for detailed information on how and when the fields are updated.

Before returning from this method, the implementation must replace the buffer in the context with a sliced version of the provided buffer so that the next entity in the deserialization chain can operate out of the buffer provided to it using absolute indices i.e. relative to the beginning of the buffer rather than relative to the current buffer position.


deserialize

public final int deserialize(ByteBuffer buf,
                             int bufOffset)
Deserialize a packet header from a byte buffer

Parameters:
buf - The byte buffer to deserialize from
bufOffset - The offset into the buffer where the serialized contents of the packet header begins.
Returns:
returns the serialized length of the header

This method deserializes the contents of a packet header by copying contents from a byte buffer to the packet header's buffer. This method copies the content starting from the supplied offset. It does not change any of the markers of the source byte buffer

This method does not does not check for packet integrity or whether the buffer contains a full packet header or not. The user should call preDeserialize(java.nio.ByteBuffer, int, int) before invoking this method to check for packet integrity and whether the buffer contains a full packet before calling this method. This method should only be subsequently called in case the preDeserialize(java.nio.ByteBuffer, int, int) method returns successfully i.e. the serialized packet has correct integrity and the full packet is contained in the buffer. Calling this method using a corrupt or incomplete buffer has undefined results.


deserialize

public final int deserialize(com.neeve.io.IOBuffer iobuf,
                             int iobufOffset,
                             boolean wrap)
Deserialize a packet header from an IO buffer

Parameters:
iobuf - The IO buffer to deserialize from
iobufOffset - The offset into the IO buffer where the serialized contents of the packet header begins.
wrap - Indicates whether the deserialization process should copy the contents of the IO buffer to the packet header or wrap the packet header and subheader's buffers around the supplied IO buffer
Returns:
returns the serialized length of the header

This method deserializes the contents of a packet header by wrapping or copying contents from a byte buffer to the packet header's buffer.

This method does not does not check for packet integrity or whether the IO buffer contains a full packet header or not. The user should call preDeserialize(java.nio.ByteBuffer, int, int) before invoking this method to check for packet integrity and whether the buffer contains a full packet before calling this method. This method should only be subsequently called in case the preDeserialize(java.nio.ByteBuffer, int, int) method returns successfully i.e. the serialized packet has correct integrity and the full packet is contained in the buffer. Calling this method using a corrupt or incomplete buffer has undefined results.


getStaticSerializedLength

public final int getStaticSerializedLength()
Get the serialized length of the only the static portion of the header.

This method returns the serialized length of only the static portion of the header. This length is governed by the header version. /P>


getSerializedLength

public final int getSerializedLength()
Implementation of PktSerializable.getSerializedLength()

This method returns the serialized length of the static header plus the serialized length of all attached subheaders.

Specified by:
getSerializedLength in class PktSerializable

getInitialBufferLength

public final int getInitialBufferLength()
Implementation of IOElasticBuffer.Sizer.getInitialBufferLength()

Specified by:
getInitialBufferLength in interface com.neeve.io.IOElasticBuffer.Sizer

initializeBuffer

public final void initializeBuffer()
Implementation of IOElasticBuffer.Initializer.initializeBuffer()

Specified by:
initializeBuffer in interface com.neeve.io.IOElasticBuffer.Initializer

toString

public final String toString()
Return a string representation of the object.

Overrides:
toString in class Object
Threading:
This method is safe for concurrent access by multiple threads


Copyright © 2016 Neeve Research, LLC. All Rights Reserved.