com.neeve.pkt
Class PktSerializable.SerializeContext

java.lang.Object
  extended by com.neeve.pkt.PktSerializable.SerializeContext
Enclosing class:
PktSerializable

public static final class PktSerializable.SerializeContext
extends Object

Contains context used in the serialization of an entity.

An instance of this class is passed to the PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) method and contains information related to the serialization process. Basically, the class stores the following pieces of information. The buffers field is an IN-OUT field and contains a buffer list to where the entity is serialized. The serialization process either copies serialized data to the last buffer in the list and/or appends new buffers to the list depending on the space remaining in the last buffer and the serialization policy specifie. The policy field contains the serialization policy to be used by the entity. This is an IN-OUT field allowing an entity to modify the serialization policy to be used by subsequent entities serialized using the same context.

It should be noted that this context does not convey the status of the serialization. See PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) on how the status is communicated back to the user.

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

Method Summary
 PktSerializable.SerializeContext addBuffer(PktIOBuffer ioBuffer)
          Add a serialization buffer
 PktSerializable.SerializeContext compactBuffers()
          Compact buffers post draining
static PktSerializable.SerializeContext create()
          Create a serialize context
 PktSerializable.SerializeContext dropBuffers()
          Wipe the buffer list clean (without dispose)
 PktSerializable.SerializeContext flipBuffers()
          Flip buffers for draining
 PktIOBuffer getBuffer(int index)
          Get a serialization buffer
 int getBufferCount()
          Get the number of buffers used..
 PktIOBuffer[] getBuffers()
          Get the serialization buffer list.
 ByteBuffer getByteBuffer(int index)
          Get a serialization byte buffer
 ByteBuffer getByteBufferForCopy(int serializedDataLength)
          Gets the next buffer to copy serialize to
 ByteBuffer[] getByteBuffers()
          Get the serialization byte buffer list.
 int getPolicy()
          Get the serialization policy to be used.
 long getRemaining()
          Get remaining bytes to write
 PktSerializable.SerializeContext resizeBuffer(int index, int newSize)
          Resize a particular buffer
 PktSerializable.SerializeContext setBufferCount(int val)
          Set current buffer count
 PktSerializable.SerializeContext setPolicy(int policy)
          Set the serialization policy to be used.
 void trace(Tracer tracer, String prefix)
          Trace contents for debugging purposes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static PktSerializable.SerializeContext create()
Create a serialize context


getBuffers

public final PktIOBuffer[] getBuffers()
Get the serialization buffer list.

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

getBuffer

public final PktIOBuffer getBuffer(int index)
Get a serialization buffer

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

getByteBuffers

public final ByteBuffer[] getByteBuffers()
Get the serialization byte buffer list.

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

getByteBuffer

public final ByteBuffer getByteBuffer(int index)
Get a serialization byte buffer

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

getBufferCount

public final int getBufferCount()
Get the number of buffers used..

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

addBuffer

public final PktSerializable.SerializeContext addBuffer(PktIOBuffer ioBuffer)
Add a serialization buffer


getByteBufferForCopy

public final ByteBuffer getByteBufferForCopy(int serializedDataLength)
Gets the next buffer to copy serialize to

Parameters:
serializedDataLength - The length of the data being copied.
Threading:
This method is not safe for concurrent access by multiple threads

resizeBuffer

public final PktSerializable.SerializeContext resizeBuffer(int index,
                                                           int newSize)
Resize a particular buffer


flipBuffers

public final PktSerializable.SerializeContext flipBuffers()
Flip buffers for draining


compactBuffers

public final PktSerializable.SerializeContext compactBuffers()
Compact buffers post draining


getRemaining

public final long getRemaining()
Get remaining bytes to write


setBufferCount

public final PktSerializable.SerializeContext setBufferCount(int val)
Set current buffer count


dropBuffers

public final PktSerializable.SerializeContext dropBuffers()
Wipe the buffer list clean (without dispose)


setPolicy

public final PktSerializable.SerializeContext setPolicy(int policy)
Set the serialization policy to be used.

Returns:
Returns this object for invocation chaining.
Throws:
IllegalArgumentException - Thrown in case the specified policy is invalid.

The following are the permissible serialization policies:
PktConstants.SERIALIZE_POLICY_DEFAULT
PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_ATTACH
PktConstants.SERIALIZE_POLICY_HEADER_ATTACH_BODY_ATTACH

See Also:
getPolicy()
Threading:
This method is not safe for concurrent access by multiple threads

getPolicy

public final int getPolicy()
Get the serialization policy to be used.

This method returns the serialization policy to be used by the deserialization process. This field is an IN-OUT field and therefore the user should not retain any reference to the policy outside of this context. The entity is free to change this field before returning from the serialization process.

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

trace

public final void trace(Tracer tracer,
                        String prefix)
Trace contents for debugging purposes



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