POC of Protobuf encoder and decoder applications implemented with NanoPb.
- This example should run on Windows machine with MS toolchain installed.
- CMake
- Number
- String
- Array if strings
- Array of custom structures
Download nanopb library
Nanopb official examples
Nanopb reference
Example: Pack repeated fields with Nanopb library
- mkdir build
- cd build
- cmake ..
- Build the generated Visual Studio projects
compile_proto.bat
script is used to compile the ExampleMessage.proto
proto
file to C source and header files.
compile_proto.bat
should be run automatically by the Cmake file in the
root of the project.
build/encoder
application creates and example proto message.
Then it encodes it, and writes the encoded message to binary file.
The produced binary file then can be decoded by the decoder app.
build/decoder
application is used to read the encoded message from binary
file, decode it and print the message to std::out.
Example output:
ExampleMessage content
message.number=3
message.str=str
message.str_array[0]=first
message.str_array[1]=second
message.sub_message_array[0]=6, sub_str_1
message.sub_message_array[1]=7, sub_str_2