serializer Struct Reference
[Serialization API]

Serializes and deserializes messagess to and from bytestreams. More...

#include <serialization.h>

List of all members.

Public Attributes

size_t(* size )(Message *message)
 Estimate the serialized size of a given message.
size_t(* serialize_to )(void *dest, Message *message, size_t limit)
 Serialize the given message to the provided destination.
Message *(* deserialize_from )(void *src, size_t size)
 Deserialize the given message from the given memory location.
void(* free )(Message *message)
 Deallocate memory used by a deserialized message.


Detailed Description

Serializes and deserializes messagess to and from bytestreams.

While not scrictly necessary for passing messages between components running in the same process, most inter-process or network protocols require data to encapsulated in a bytestream. Messaging implementations are given a Serializer instance so they might package their messages as appropriate.

Definition at line 32 of file serialization.h.


Member Data Documentation

Message*(* serializer::deserialize_from)(void *src, size_t size)

Deserialize the given message from the given memory location.

A given Serializer can only be expected to deserialize messages that it has serialized itself. Failure to deserialize a message will result in NULL being returned. The size parameter is expected to be the exact size of the serialized message. An estimate as provided by Serializer#size() is not acceptable and may cause an error.

When message content is not used any more, it should be deallocated via Serializer#free()

Parameters:
src Memory location of serialized message bytes
size Exact size of the serialized message.
Returns:
Allocated and populated message.

void(* serializer::free)(Message *message)

Deallocate memory used by a deserialized message.

Can only deallocate messages produced via Serializer#deserialize_from() by the same Serializer.

Parameters:
message Message to deallocate/free.

size_t(* serializer::serialize_to)(void *dest, Message *message, size_t limit)

Serialize the given message to the provided destination.

The destination memory is expected to already be allocated, and at least limit bytes long. If the serialized message cannot fit within the provivded space, the serialization process will abort with a 0 result value. Some or all of dest will be written. If successful, will return the exact number of bytes written.

Parameters:
dest Destination memory location to write the serialization.
message Message to serialize.
limit Size of the provided memory location.
Returns:
Number of bytes written, or 0 if there is not enough space.

size_t(* serializer::size)(Message *message)

Estimate the serialized size of a given message.

Returned value must be at least as large as the number of bytes required to store a serialized instance of the given message. Implementations may elect to overestimate the size for performance reasons. This method is useful in allocating space for a serialized message.

Parameters:
message Message for which to calculate the serialized size.
Returns:
Size in bytes required to store a serialized representation of the given message.


The documentation for this struct was generated from the following file:
Generated on Thu Sep 27 11:11:48 2012 for VetSim by  doxygen 1.4.7