com.neeve.sma
Interface MessageSerializer


public interface MessageSerializer

Represents a serializer for an SMA message encoding type.

This interface represents an SMA message serializer. It is used by the SMA runtime to serialize messages that are not natively transportable by the provider through which the messages are being transported. There exists a unique serializer per message encoding type in the system.

Threading:
The SMA runtime assumes that serializers are not safe for concurrent access by multiple threads.

Method Summary
 Object deserialize(ByteBuffer buffer, Tracer tracer)
          Deserialize (contruct) and SMA message from a serialized byte array.
 int getSerializedLength(Object message)
          Get the length of a serialized message.
 void serialize(Object message, com.neeve.io.IOBuffer buffer, Tracer tracer)
          Serialize an SMA message to a byte buffer.
 

Method Detail

getSerializedLength

int getSerializedLength(Object message)
Get the length of a serialized message.

Threading:
The SMA runtime assumes treats this method as not safe for concurrent access by multiple threads. Therefore, it ensures that two of its threads are never concurrently invoking this method. However, the message class implementer is free to introduce thread safety mechanisms into the class implementation.

This method is invoked by the SMA runtime to estimate the length of a serialized SMA message. The returned length is used to construct a byte buffer for use with the serialize(java.lang.Object, com.neeve.io.IOBuffer, com.neeve.trace.Tracer) method. This method is only used to estimate an upper bound for the number of butes needs for buffer creation. The number of bytes actually transported is equal by the number of bytes actually serialized by the serialize(java.lang.Object, com.neeve.io.IOBuffer, com.neeve.trace.Tracer) method. Therefore, the method implementation can return a rough estimate as long as the estimate is assured to be higher than the actual serialized size.


serialize

void serialize(Object message,
               com.neeve.io.IOBuffer buffer,
               Tracer tracer)
Serialize an SMA message to a byte buffer.

Parameters:
message - The message to serialize.
buffer - The buffer into which to serialize the message.
tracer - Tracer used to output serialization related trace. Can be null in which case no trace is output.
Threading:
The SMA runtime assumes treats this method as not safe for concurrent access by multiple threads. Therefore, it ensures that two of its threads are never concurrently invoking this method. However, the message class implementer is free to introduce thread safety mechanisms into the class implementation.

This method is invoked by the SMA runtime to serialize an SMA message to a byte buffer. The method implementation should serialize the message to the buffer starting at the position marker. Upon return from this method, the position marker should be set to the end of the serialized message. Other markers should not be modified by the method.


deserialize

Object deserialize(ByteBuffer buffer,
                   Tracer tracer)
Deserialize (contruct) and SMA message from a serialized byte array.

Parameters:
buffer - The buffer from which to deserialize the message.
tracer - Tracer used to output deserialization related trace. Can be null in which case no trace is output.
Threading:
The SMA runtime assumes treats this method as not safe for concurrent access by multiple threads. Therefore, it ensures that two of its threads are never concurrently invoking this method. However, the message class implementer is free to introduce thread safety mechanisms into the class implementation.

This method is invoked by the SMA runtime to de-serialize an SMA message from a byte buffer. The method implementation should deserialize the message from the buffer starting at the position marker. Upon return from this method, the position marker should be set to the end of the serialized message. Other markers should not be modified by the method.



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