To String
As of version 3.3.0, you can use the to_string() method on embedded devices. This function is meant for debugging purposes to give the programmer insights into the values in a given message. The function is not enabled by default. To enable using the to string function do the following:
- Build with C++17 enabled.
- Define the build flag
MSG_TO_STRING.
Next, you can call the to_string function with a string_view parameter. This is a struct holding a pointer to the character array and its size.
constexpr uint32_t N = 1024;
char str[N];
::EmbeddedProto::string_view str_view = { str, N };
::EmbeddedProto::string_view str_left = msg.to_string(str_view);An example of the text generated and stored in the array is shown below:
{
"u": 1.000000,
"nested_a": {
"x": [
1,
2,
3
],
"y": 1.000000,
"z": 1
},
"v": 1
}The message could be incomplete if there are not enough characters in the array. The to_string function returns a string_view struct with the characters left in the array.
