The data in your message has been set and is ready to be transmitted over your communication line. So how do you serialize the message?

Each message object has a function serialize() derived from one of its 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. Strings are not suitable for embedded implementations. The standard std::string used dynamic memory allocation, which we are trying to avoid.

The interface class WriteBufferInterface is the alternative to using std::string. The object is referenced to the message serialize() function, where it is used to store the output of the serialization. But as the name suggests, it is an interface. The actual implementation which you use is the WriteBufferFixedSize template class. Specify the number of bytes allocated in the class via the template parameter.

Prior to version 3.2.0, it was up to the user of this library to write an implementation of the WriteBufferInterface specific to their situation. Implementations could 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.