1Nanopb - Protocol Buffers for Embedded Systems 2============================================== 3 4![Latest change](https://github.com/nanopb/nanopb/actions/workflows/trigger_on_code_change.yml/badge.svg) 5![Weekly build](https://github.com/nanopb/nanopb/actions/workflows/trigger_on_schedule.yml/badge.svg) 6 7Nanopb is a small code-size Protocol Buffers implementation in ansi C. It is 8especially suitable for use in microcontrollers, but fits any memory 9restricted system. 10 11* **Homepage:** https://jpa.kapsi.fi/nanopb/ 12* **Git repository:** https://github.com/nanopb/nanopb/ 13* **Documentation:** https://jpa.kapsi.fi/nanopb/docs/ 14* **Forum:** https://groups.google.com/forum/#!forum/nanopb 15* **Stable version downloads:** https://jpa.kapsi.fi/nanopb/download/ 16* **Pre-release binary packages:** https://github.com/nanopb/nanopb/actions/workflows/binary_packages.yml 17 18 19Using the nanopb library 20------------------------ 21To use the nanopb library, you need to do two things: 22 231. Compile your .proto files for nanopb, using `protoc`. 242. Include *pb_encode.c*, *pb_decode.c* and *pb_common.c* in your project. 25 26The easiest way to get started is to study the project in "examples/simple". 27It contains a Makefile, which should work directly under most Linux systems. 28However, for any other kind of build system, see the manual steps in 29README.txt in that folder. 30 31 32Generating the headers 33---------------------- 34Protocol Buffers messages are defined in a `.proto` file, which follows a standard 35format that is compatible with all Protocol Buffers libraries. To use it with nanopb, 36you need to generate `.pb.c` and `.pb.h` files from it: 37 38 python generator/nanopb_generator.py myprotocol.proto # For source checkout 39 generator-bin/nanopb_generator myprotocol.proto # For binary package 40 41(Note: For instructions for nanopb-0.3.9.x and older, see the documentation 42of that particular version [here](https://github.com/nanopb/nanopb/blob/maintenance_0.3/README.md)) 43 44The binary packages for Windows, Linux and Mac OS X should contain all necessary 45dependencies, including Python, python-protobuf library and protoc. If you are 46using a git checkout or a plain source distribution, you will need to install 47Python separately. Once you have Python, you can install the other dependencies 48with `pip install --upgrade protobuf grpcio-tools`. 49 50You can further customize the header generation by creating an `.options` file. 51See [documentation](https://jpa.kapsi.fi/nanopb/docs/concepts.html#modifying-generator-behaviour) for details. 52 53 54Running the tests 55----------------- 56If you want to perform further development of the nanopb core, or to verify 57its functionality using your compiler and platform, you'll want to run the 58test suite. The build rules for the test suite are implemented using Scons, 59so you need to have that installed (ex: `sudo apt install scons` or `pip install scons`). 60To run the tests: 61 62 cd tests 63 scons 64 65This will show the progress of various test cases. If the output does not 66end in an error, the test cases were successful. 67 68Note: Mac OS X by default aliases 'clang' as 'gcc', while not actually 69supporting the same command line options as gcc does. To run tests on 70Mac OS X, use: `scons CC=clang CXX=clang`. Same way can be used to run 71tests with different compilers on any platform. 72 73For embedded platforms, there is currently support for running the tests 74on STM32 discovery board and [simavr](https://github.com/buserror/simavr) 75AVR simulator. Use `scons PLATFORM=STM32` and `scons PLATFORM=AVR` to run 76these tests. 77 78 79Build systems and integration 80----------------------------- 81Nanopb C code itself is designed to be portable and easy to build 82on any platform. Often the bigger hurdle is running the generator which 83takes in the `.proto` files and outputs `.pb.c` definitions. 84 85There exist build rules for several systems: 86 87* **Makefiles**: `extra/nanopb.mk`, see `examples/simple` 88* **CMake**: `extra/FindNanopb.cmake`, see `examples/cmake` 89* **SCons**: `tests/site_scons` (generator only) 90* **Bazel**: `BUILD` in source root 91* **Conan**: `conanfile.py` in source root 92* **PlatformIO**: https://platformio.org/lib/show/431/Nanopb 93* **PyPI/pip**: https://pypi.org/project/nanopb/ 94* **vcpkg**: https://vcpkg.info/port/nanopb 95 96And also integration to platform interfaces: 97 98* **Arduino**: http://platformio.org/lib/show/1385/nanopb-arduino 99 100