17ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenNanopb is a small code-size Protocol Buffers implementation in ansi C. It is 27ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenespecially suitable for use in microcontrollers, but fits any memory 37ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenrestricted system. 47ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 57ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenHomepage: http://kapsi.fi/~jpa/nanopb/ 67ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 77ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 87ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 97ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 107ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenUsing the nanopb library 117ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen======================== 127ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenTo use the nanopb library, you need to do two things: 137ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 147ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen1) Compile your .proto files for nanopb, using protoc. 157ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen2) Include pb_encode.c and pb_decode.c in your project. 167ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 177ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenThe easiest way to get started is to study the project in "examples/simple". 187ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenIt contains a Makefile, which should work directly under most Linux systems. 197ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenHowever, for any other kind of build system, see the manual steps in 207ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenREADME.txt in that folder. 217ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 227ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 237ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 247ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenUsing the Protocol Buffers compiler (protoc) 257ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen============================================ 267ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenThe nanopb generator is implemented as a plugin for the Google's own protoc 277ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohencompiler. This has the advantage that there is no need to reimplement the 287ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenbasic parsing of .proto files. However, it does mean that you need the 297ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenGoogle's protobuf library in order to run the generator. 307ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 317ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenIf you have downloaded a binary package for nanopb (either Windows, Linux or 327ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenMac OS X version), the 'protoc' binary is included in the 'generator-bin' 337ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenfolder. In this case, you are ready to go. Simply run this command: 347ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 357ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen generator-bin/protoc --nanopb_out=. myprotocol.proto 367ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 377ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenHowever, if you are using a git checkout or a plain source distribution, you 387ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenneed to provide your own version of protoc and the Google's protobuf library. 397ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenOn Linux, the necessary packages are protobuf-compiler and python-protobuf. 407ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenOn Windows, you can either build Google's protobuf library from source or use 417ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenone of the binary distributions of it. In either case, if you use a separate 427ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenprotoc, you need to manually give the path to nanopb generator: 437ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 447ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen protoc --plugin=protoc-gen-nanopb=nanopb/generator/protoc-gen-nanopb ... 457ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 467ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 477ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 487ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenRunning the tests 497ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen================= 507ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenIf you want to perform further development of the nanopb core, or to verify 517ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenits functionality using your compiler and platform, you'll want to run the 527ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohentest suite. The build rules for the test suite are implemented using Scons, 537ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenso you need to have that installed. To run the tests: 547ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 557ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen cd tests 567ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen scons 577ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 587ef855e462b9a18b7d330e4b40f350164a6ad9daEtan CohenThis will show the progress of various test cases. If the output does not 597ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohenend in an error, the test cases were successful. 607ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 617ef855e462b9a18b7d330e4b40f350164a6ad9daEtan Cohen 62