Skip to content

Encoding/Decoding Protobuf messages with Nanopb library

License

Notifications You must be signed in to change notification settings

konstantin89/nanopb-poc

Repository files navigation

nanobp-example

Brief

POC of Protobuf encoder and decoder applications implemented with NanoPb.

Dependencies

  • This example should run on Windows machine with MS toolchain installed.
  • CMake

Supported types

  • Number
  • String
  • Array if strings
  • Array of custom structures

Links

Download nanopb library
Nanopb official examples
Nanopb reference
Example: Pack repeated fields with Nanopb library


Compiling the project

  • mkdir build
  • cd build
  • cmake ..
  • Build the generated Visual Studio projects

Generating NanoPB auto generated files

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.


Encoder application

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.


Decoder application

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

About

Encoding/Decoding Protobuf messages with Nanopb library

Topics

Resources

License

Stars

Watchers

Forks