+0
Daily
5,614
stars
1,061
forks
119
watchers
373
prs
845
issues
2
releases
README
Nanopb - Protocol Buffers for Embedded Systems
==============================================
!Latest change
!Weekly build
Nanopb is a small code-size Protocol Buffers implementation in ansi C. It is
especially suitable for use in microcontrollers, but fits any memory
restricted system.
Homepage: https://jpa.kapsi.fi/nanopb/
Git repository: https://github.com/nanopb/nanopb/
Documentation: https://jpa.kapsi.fi/nanopb/docs/
Forum: https://groups.google.com/forum/!forum/nanopb
Stable version downloads: https://jpa.kapsi.fi/nanopb/download/
Pre-release binary packages: https://github.com/nanopb/nanopb/actions/workflows/binary_packages.yml
Using the nanopb library
------------------------
To use the nanopb library, you need to do two things:
1. Compile your .proto files for nanopb, using protoc.
2. Include pb_encode.c, pb_decode.c and pb_common.c in your project.
The easiest way to get started is to study the project in "examples/simple".
It contains a Makefile, which should work directly under most Linux systems.
However, for any other kind of build system, see the manual steps in
README.txt in that folder.
Generating the headers
----------------------
Protocol Buffers messages are defined in a .proto file, which follows a standard
format that is compatible with all Protocol Buffers libraries. To use it with nanopb,
you need to generate .pb.c and .pb.h files from it:
python generator/nanopb_generator.py myprotocol.proto For source checkout
generator-bin/nanopb_generator myprotocol.proto For binary package
(Note: For instructions for nanopb-0.3.9.x and older, see the documentation
of that particular version here)
The binary packages for Windows, Linux and Mac OS X should contain all necessary
dependencies, including Python, python-protobuf library and protoc. If you are
using a git checkout or a plain source distribution, you will need to install
Python separately. Once you have Python, you can install the other dependencies
with pip install --upgrade protobuf grpcio-tools.
You can further customize the header generation by creating an .options file.
See documentation for details.
Running the tests
-----------------
If you want to perform further development of the nanopb core, or to verify
its functionality using your compiler and platform, you'll want to run the
test suite. The build rules for the test suite are implemented using Scons,
so you need to have that installed (ex: sudo apt install scons or pip install scons).
To run the tests:
cd tests
scons
This will show the progress of various test cases. If the output does not
end in an error, the test cases were successful.
Note: Mac OS X by default aliases 'clang' as 'gcc', while not actually
supporting the same command line options as gcc does. To run tests on
Mac OS X, use: scons CC=clang CXX=clang++. Same way can be used to run
tests with different compilers on any platform.
For embedded platforms, there is currently support for running the testTop issues
#1066Review of Nanopb 1.x API plans21 comments · 2025-03-05#775custom 'realloc' with a context18 comments · 2022-04-21#900Support for Editions14 comments · 2023-09-15#707Add support to define options using precompiler symbols14 comments · 2021-09-30#878Option to always encode proto3 fields, even if they have their default value10 comments · 2023-06-22#173Protobuf structure shallow copy10 comments · 2015-10-07#481CMake support of NANOPB_GENERATE_CPP function is broken or incomplete9 comments · 2020-01-15#543Self-tests failure on some architectures8 comments · 2020-06-21
Latest release
Nanopb 0.4.9.2 nanopb-0.4.9.2 2026-08-25Fix callback and oneof calling attacker-controlled ptr (GHSA-p24j-vqcp-x988) Fix callback for message inside oneof not getting called (1061) Fix setting of package name in .options file (1131) Add minimal support for protobuf editions (900) Fix comment parsing in options string literals (1175) Add PB_MESSAGE_NESTING_MAX option for limiting recursion depth (GHSA-9w99-4pfq-6396) Bazel, CMake and platformio build system improvements