1*c8d645caSAndroid Build Coastguard WorkerNanopb - Protocol Buffers for Embedded Systems 2*c8d645caSAndroid Build Coastguard Worker============================================== 3*c8d645caSAndroid Build Coastguard Worker 4*c8d645caSAndroid Build Coastguard Worker[](https://travis-ci.org/nanopb/nanopb) 5*c8d645caSAndroid Build Coastguard Worker 6*c8d645caSAndroid Build Coastguard WorkerNanopb is a small code-size Protocol Buffers implementation in ansi C. It is 7*c8d645caSAndroid Build Coastguard Workerespecially suitable for use in microcontrollers, but fits any memory 8*c8d645caSAndroid Build Coastguard Workerrestricted system. 9*c8d645caSAndroid Build Coastguard Worker 10*c8d645caSAndroid Build Coastguard Worker* **Homepage:** https://jpa.kapsi.fi/nanopb/ 11*c8d645caSAndroid Build Coastguard Worker* **Documentation:** https://jpa.kapsi.fi/nanopb/docs/ 12*c8d645caSAndroid Build Coastguard Worker* **Downloads:** https://jpa.kapsi.fi/nanopb/download/ 13*c8d645caSAndroid Build Coastguard Worker* **Forum:** https://groups.google.com/forum/#!forum/nanopb 14*c8d645caSAndroid Build Coastguard Worker 15*c8d645caSAndroid Build Coastguard Worker 16*c8d645caSAndroid Build Coastguard Worker 17*c8d645caSAndroid Build Coastguard WorkerUsing the nanopb library 18*c8d645caSAndroid Build Coastguard Worker------------------------ 19*c8d645caSAndroid Build Coastguard WorkerTo use the nanopb library, you need to do two things: 20*c8d645caSAndroid Build Coastguard Worker 21*c8d645caSAndroid Build Coastguard Worker1. Compile your .proto files for nanopb, using `protoc`. 22*c8d645caSAndroid Build Coastguard Worker2. Include *pb_encode.c*, *pb_decode.c* and *pb_common.c* in your project. 23*c8d645caSAndroid Build Coastguard Worker 24*c8d645caSAndroid Build Coastguard WorkerThe easiest way to get started is to study the project in "examples/simple". 25*c8d645caSAndroid Build Coastguard WorkerIt contains a Makefile, which should work directly under most Linux systems. 26*c8d645caSAndroid Build Coastguard WorkerHowever, for any other kind of build system, see the manual steps in 27*c8d645caSAndroid Build Coastguard WorkerREADME.txt in that folder. 28*c8d645caSAndroid Build Coastguard Worker 29*c8d645caSAndroid Build Coastguard Worker 30*c8d645caSAndroid Build Coastguard Worker 31*c8d645caSAndroid Build Coastguard WorkerUsing the Protocol Buffers compiler (protoc) 32*c8d645caSAndroid Build Coastguard Worker-------------------------------------------- 33*c8d645caSAndroid Build Coastguard WorkerThe nanopb generator is implemented as a plugin for the Google's own `protoc` 34*c8d645caSAndroid Build Coastguard Workercompiler. This has the advantage that there is no need to reimplement the 35*c8d645caSAndroid Build Coastguard Workerbasic parsing of .proto files. However, it does mean that you need the 36*c8d645caSAndroid Build Coastguard WorkerGoogle's protobuf library in order to run the generator. 37*c8d645caSAndroid Build Coastguard Worker 38*c8d645caSAndroid Build Coastguard WorkerIf you have downloaded a binary package for nanopb (either Windows, Linux or 39*c8d645caSAndroid Build Coastguard WorkerMac OS X version), the `protoc` binary is included in the 'generator-bin' 40*c8d645caSAndroid Build Coastguard Workerfolder. In this case, you are ready to go. Simply run this command: 41*c8d645caSAndroid Build Coastguard Worker 42*c8d645caSAndroid Build Coastguard Worker generator-bin/protoc --nanopb_out=. myprotocol.proto 43*c8d645caSAndroid Build Coastguard Worker 44*c8d645caSAndroid Build Coastguard WorkerHowever, if you are using a git checkout or a plain source distribution, you 45*c8d645caSAndroid Build Coastguard Workerneed to provide your own version of `protoc` and the Google's protobuf library. 46*c8d645caSAndroid Build Coastguard WorkerOn Linux, the necessary packages are `protobuf-compiler` and `python-protobuf`. 47*c8d645caSAndroid Build Coastguard WorkerOn Windows, you can either build Google's protobuf library from source or use 48*c8d645caSAndroid Build Coastguard Workerone of the binary distributions of it. In either case, if you use a separate 49*c8d645caSAndroid Build Coastguard Worker`protoc`, you need to manually give the path to nanopb generator: 50*c8d645caSAndroid Build Coastguard Worker 51*c8d645caSAndroid Build Coastguard Worker protoc --plugin=protoc-gen-nanopb=nanopb/generator/protoc-gen-nanopb ... 52*c8d645caSAndroid Build Coastguard Worker 53*c8d645caSAndroid Build Coastguard Worker 54*c8d645caSAndroid Build Coastguard Worker 55*c8d645caSAndroid Build Coastguard WorkerRunning the tests 56*c8d645caSAndroid Build Coastguard Worker----------------- 57*c8d645caSAndroid Build Coastguard WorkerIf you want to perform further development of the nanopb core, or to verify 58*c8d645caSAndroid Build Coastguard Workerits functionality using your compiler and platform, you'll want to run the 59*c8d645caSAndroid Build Coastguard Workertest suite. The build rules for the test suite are implemented using Scons, 60*c8d645caSAndroid Build Coastguard Workerso you need to have that installed (ex: `sudo apt install scons` on Ubuntu). To run the tests: 61*c8d645caSAndroid Build Coastguard Worker 62*c8d645caSAndroid Build Coastguard Worker cd tests 63*c8d645caSAndroid Build Coastguard Worker scons 64*c8d645caSAndroid Build Coastguard Worker 65*c8d645caSAndroid Build Coastguard WorkerThis will show the progress of various test cases. If the output does not 66*c8d645caSAndroid Build Coastguard Workerend in an error, the test cases were successful. 67*c8d645caSAndroid Build Coastguard Worker 68*c8d645caSAndroid Build Coastguard WorkerNote: Mac OS X by default aliases 'clang' as 'gcc', while not actually 69*c8d645caSAndroid Build Coastguard Workersupporting the same command line options as gcc does. To run tests on 70*c8d645caSAndroid Build Coastguard WorkerMac OS X, use: "scons CC=clang CXX=clang". Same way can be used to run 71*c8d645caSAndroid Build Coastguard Workertests with different compilers on any platform. 72