#include <serialization.h>
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. |
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.
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()
src | Memory location of serialized message bytes | |
size | Exact size of the serialized 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.
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.
dest | Destination memory location to write the serialization. | |
message | Message to serialize. | |
limit | Size of the provided memory location. |
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.
message | Message for which to calculate the serialized size. |