com.neeve.pkt
Class PktBody

java.lang.Object
  extended by com.neeve.util.UtlListElement
      extended by com.neeve.pkt.PktSerializable
          extended by com.neeve.pkt.PktBody
All Implemented Interfaces:
com.neeve.io.IOElasticBuffer.Initializer, com.neeve.io.IOElasticBuffer.Sizer
Direct Known Subclasses:
PktBodyFixed, PktBodyVariable, PktSubheader

public abstract class PktBody
extends PktSerializable
implements com.neeve.io.IOElasticBuffer.Initializer

Base class for all packet bodies.

Threading:
Packet bodies 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
 
Fields inherited from class com.neeve.util.UtlListElement
count, head, next, prev
 
Method Summary
 void deserialize(byte[] array, int arrayOffset, int length)
          Deserialize a packet body from a byte array
 void deserialize(ByteBuffer buf, int length)
          Deserialize a packet body from a byte buffer
 void deserialize(ByteBuffer buf, int bufOffset, int length)
          Deserialize a packet body from a byte buffer
 void deserialize(com.neeve.io.IOBuffer iobuf, int iobufOffset, int length, boolean wrap)
          Deserialize a packet body from an IO buffer
 void deserialize(com.neeve.io.IOElasticBuffer iobuf, int iobufOffset, int length)
          Deserialize a packet body from an elastic IO buffer
 void deserialize(long address, int addressOffset, int length)
          Deserialize a packet body from a native memory region
 void deserialize(PktSerializable.DeserializeContext context, int length, Tracer tracer)
          Implementation of PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
 String dump(String prefix)
          Dump the contents of a packet body
 PktBuffer getBuffer()
          Get the backing buffer
 int getInitialBufferLength()
          Implementation of IOElasticBuffer.Sizer.getInitialBufferLength()
 int getSerializedLength()
          Implementation of PktSerializable.getSerializedLength()
 int getType()
          Get the body type
 void initializeBuffer()
          Implementation of IOElasticBuffer.Initializer.initializeBuffer() The default implementation of this method is no-op.
 boolean isNative()
          Get if the body is backed by a native or heap buffer
 void reset()
          Reset the body contents This method resets the contents of a packet body.
 int serialize(byte[] array, int arrayOffset)
          Serialize a packet body to a byte array
 int serialize(ByteBuffer buf)
          Serialize a packet body to a byte buffer
 int serialize(ByteBuffer buf, int bufOffset)
          Serialize a packet body to a byte buffer
 int serialize(com.neeve.io.IOBuffer iobuf, int iobufOffset)
          Serialize a packet body to an IO buffer
 int serialize(com.neeve.io.IOElasticBuffer iobuf, int iobufOffset)
          Serialize a packet body to an elastic IO buffer
 int serialize(long address, int addressOffset)
          Serialize a packet body 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) This method serializes the packet body into the buffer list in the specified serialization context.
 
Methods inherited from class com.neeve.pkt.PktSerializable
deserialize, getDeserializationPolicy, getSerializationPolicy, isValidDeserializationPolicy, isValidSerializationPolicy, serialize, setDeserializationPolicy, setSerializationPolicy
 
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, toString, wait, wait, wait
 

Method Detail

getType

public final int getType()
Get the body type


isNative

public final boolean isNative()
Get if the body is backed by a native or heap buffer


getBuffer

public final PktBuffer getBuffer()
Get the backing buffer


reset

public final void reset()
Reset the body contents

This method resets the contents of a packet body. Upon return from this method, the contents of the body are the same as a freshly created body of the same type.

This method retains its references (if any) to its enclosing packet and associated packet header.

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


getSerializedLength

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

Specified by:
getSerializedLength in class PktSerializable

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 body 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.

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 body 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 body by copying the contents of the packet body'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 body's contents. The caller can invoke getSerializedLength() to get the length of the body'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 body 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 body needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

This method serialized the contents of a packet body by copying the contents of the packet body'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 body's contents. The caller can invoke getSerializedLength() to get the length of the body'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 body 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 body needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

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


serialize

public final int serialize(com.neeve.io.IOBuffer iobuf,
                           int iobufOffset)
Serialize a packet body 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 body needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

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


serialize

public final int serialize(com.neeve.io.IOElasticBuffer iobuf,
                           int iobufOffset)
Serialize a packet body 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 body needs to be serialized (copied)
Returns:
length The number of bytes serialized (copied)

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


serialize

public final int serialize(long address,
                           int addressOffset)
Serialize a packet body 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 body should be serialized to.
Returns:
length The number of bytes serialized (copied)

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


deserialize

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

Specified by:
deserialize in class PktSerializable
Parameters:
context - The context to be used by the deserialization process. See PktSerializable.DeserializeContext for more information.
length - 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 void deserialize(ByteBuffer buf,
                              int length)
Deserialize a packet body from a byte buffer

Parameters:
buf - The byte buffer to deserialize from
length - The length of the body's serialized contents

This method deserializes the contents of a packet body by copying contents from a byte buffer to the packet body's buffer. This method copies the content starting from the source buffer's position to its limit. It does not change any of the markers of the source byte buffer


deserialize

public final void deserialize(ByteBuffer buf,
                              int bufOffset,
                              int length)
Deserialize a packet body 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 body begins.
length - The length of the body's serialized contents

This method deserializes the contents of a packet body by copying contents from a byte buffer to the packet body'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


deserialize

public final void deserialize(byte[] array,
                              int arrayOffset,
                              int length)
                       throws EPktDeserializeException
Deserialize a packet body from a byte array

Parameters:
array - The byte array to deserialize from
arrayOffset - The offset into the array where the serialized contents of the packet body begins.
length - The length of the body's serialized contents

This method deserializes the contents of a packet body by copying contents from a byte array to the packet body's buffer.

Throws:
EPktDeserializeException

deserialize

public final void deserialize(com.neeve.io.IOBuffer iobuf,
                              int iobufOffset,
                              int length,
                              boolean wrap)
                       throws EPktDeserializeException
Deserialize a packet body 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 body begins.
length - The length of the body's serialized contents
wrap - Indicates whether the deserialization process should copy the contents of the IO buffer to the packet body or wrap the packet body's buffer around the supplied IO buffer

This method deserializes the contents of a packet body by wrapping or copying contents of an IO buffer to the packet body's buffer.

Throws:
EPktDeserializeException

deserialize

public final void deserialize(com.neeve.io.IOElasticBuffer iobuf,
                              int iobufOffset,
                              int length)
                       throws EPktDeserializeException
Deserialize a packet body from an elastic IO buffer

Parameters:
iobuf - The IO buffer to deserialize from
iobufOffset - The offset into the IO buffer where the serialized contents of the packet body begins.
length - The length of the body's serialized contents

This method deserializes the contents of a packet body by copying contents from an elastic IO buffer to the packet body's buffer.

Throws:
EPktDeserializeException

deserialize

public final void deserialize(long address,
                              int addressOffset,
                              int length)
                       throws EPktDeserializeException
Deserialize a packet body from a native memory region

Parameters:
address - The address of the native memory region to deserialize from
addressOffset - The offset into the memory region where the serialized contents of the packet body begins.
length - The length of the body's serialized contents

This method deserializes the contents of a packet body by copying contents from a native (off heap) memory region to the packet body's buffer.

Throws:
EPktDeserializeException

dump

public final String dump(String prefix)
Dump the contents of a packet body


getInitialBufferLength

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

Specified by:
getInitialBufferLength in interface com.neeve.io.IOElasticBuffer.Sizer
Returns:
Returns length of the backing buffer if the body was intiatiated from fork or length returned by doGetInitialBufferLength() if not instantiated from fork.

initializeBuffer

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

The default implementation of this method is no-op. The concrete body implementation should override and implement this method if it needs to do buffer initialization.

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


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