RhpAddress evStartSerialize(struct RiCEvent* const ev, const RhpAddress
buffer, RhpPositive bufferSize, RhpPositive* resultBufferSize);
return value - pointer to the serialized event
ev - pointer of the event to be serialized
buffer - a local buffer that can be used for storing the serialized event (the user can allocate their own buffer instead)
bufferSize - the size in bytes of the parameter buffer
resultBufferSize - pointer for storing the size of the returned serialized event
RiCEvent* evStartUnserialize(RhpAddress const serializedBuffer, RhpPositive serializedBufferSize);
return value - pointer to the unserialized event
serializedBuffer - pointer to the serialized buffer
serializedBufferSize - the size of the parameter serializedBuffer
The example refers to the event evStart, which is defined as follows:
struct evStart {
RiCEvent ric_event;
/*** User explicit entries ***/
char* msg;
};
RhpAddress evStartSerialize(struct RiCEvent* const ev, const RhpAddress
buffer, RhpPositive bufferSize, RhpPositive* resultBufferSize)
{
evStart* castedEv = (evStart*)ev;
RhpPositive msgLength = strlen(castedEv->msg);
/* Testing the size of the message parameter against the size of local
buffer */
if (bufferSize <= msgLength)
{
/* buffer too small - serialization is aborted */
return NULL;
}
/* copy the message string + the null terminating */
memcpy(buffer, castedEv->msg, msgLength + 1);
*resultBufferSize = msgLength + 1;
return buffer;
}
The following function uses a local buffer called receivedBuffer to store the string of the event evStart which was passed as a parameter.
RiCEvent* evStartUnserialize(RhpAddress const serializedBuffer,
RhpPositive serializedBufferSize) {
/* copy the message to a local buffer */
memcpy(receivedBuffer, serializedBuffer, serializedBufferSize);
return (RiCEvent*)RiC_Create_evStart(receivedBuffer);
}