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(com.neeve.io.IOBuffer 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 dropLastBuffer()
          Drop the last buffer (without dispose)
 void dump(String prefix, StringBuilder to)
          Dumps content for diagnostic purposes.
 PktSerializable.SerializeContext flipBuffers()
          Flip buffers for draining
 com.neeve.io.IOBuffer getBuffer(int index)
          Get a serialization buffer
 int getBufferCount()
          Get the number of buffers used..
 long getBuffered()
          Get bytes buffered for write
 com.neeve.io.IOBuffer[] 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
 boolean getSerializeWithoutMagic()
          Gets whether the header will be serialized with or without magic
 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.
 PktSerializable.SerializeContext setSerializeWithoutMagic(boolean val)
          Sets whether or not to serialize with the header magic
 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


setSerializeWithoutMagic

public final PktSerializable.SerializeContext setSerializeWithoutMagic(boolean val)
Sets whether or not to serialize with the header magic

Parameters:
val - A value of true will cause serialization to be done without the header magic

getSerializeWithoutMagic

public final boolean getSerializeWithoutMagic()
Gets whether the header will be serialized with or without magic

Returns:
true if header will be serialized without magic.

getBuffers

public final com.neeve.io.IOBuffer[] getBuffers()
Get the serialization buffer list.

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

getBuffer

public final com.neeve.io.IOBuffer 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(com.neeve.io.IOBuffer 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


getBuffered

public final long getBuffered()
Get bytes buffered for write


getRemaining

public final long getRemaining()
Get remaining bytes to write


setBufferCount

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


dropLastBuffer

public final PktSerializable.SerializeContext dropLastBuffer()
Drop the last buffer (without dispose)


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


dump

public final void dump(String prefix,
                       StringBuilder to)
Dumps content for diagnostic purposes.

This method includes the hex content of the dumped buffers.

Parameters:
prefix - A prefix for each line in the dump.
to - A String builder to which to append.


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