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:
PktBuffer.Initializer
Direct Known Subclasses:
PktBodyFixed, PktBodyVariable, PktSubheader

public abstract class PktBody
extends PktSerializable
implements PktBuffer.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(PktSerializable.DeserializeContext context, int bodySerializedLength, Tracer tracer)
          Implementation of PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
 PktBuffer getBuffer()
          Get the backing buffer
 int getSerializedLength()
          Implementation of PktSerializable.getSerializedLength()
 int getType()
          Get the body type
 void initializeBuffer()
          Implementation of PktBuffer.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.
 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)


deserialize

public final void deserialize(PktSerializable.DeserializeContext context,
                              int bodySerializedLength,
                              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.
bodySerializedLength - 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

initializeBuffer

public void initializeBuffer()
Implementation of PktBuffer.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 PktBuffer.Initializer


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