The data in your message has been set and it is ready to be transmitted over your communication line. So how you serialize the message?
Each message object has a function
serialize() derived from one of it’s base classes. When calling this function the data in the message is serialized using the Protocol Buffers format. This function is similar to the Protobuf function
SerializeToString() of the C++ implementation.
However there is a difference between the two. Where
SerializeToString()outputs into a
std::string this is not suitable for embedded implementations. The standard string used dynamic memory allocation which is something we are trying to avoid.
This is where the interface class
WriteBufferInterface comes in. This base class is passed to the message
serialzie() function. It is used to store the output of the serialization in. But as the name suggests it is an interface. The library provides no actual implementation for this class.
WriteBufferInterfaceIt is up to the user of this library to write an implementation of WriteBufferInterface specific for their situation.
It is up to the user of this library to write an implementation of
WriteBufferInterface specific for their situation. Implementations could for instance be a simple array or you could write the data directly to a uart bus. The interface is simple and easily implemented. You can find more documentation on the required functions here.