Nanopb is a small code-size Protocol Buffers implementation in ansi C. It isespecially suitable for use in microcontrollers, but fits any memoryrestricted system.
To use the nanopb library, you need to do two things:
protoc
.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 inREADME.txt in that folder.
Protocol Buffers messages are defined in a .proto
file, which follows a standardformat 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 documentationof that particular version here)
The binary packages for Windows, Linux and Mac OS X should contain all necessarydependencies, including Python, python-protobuf library and protoc. If you areusing a git checkout or a plain source distribution, you will need to installPython separately. Once you have Python, you can install the other dependencieswith pip install protobuf grpcio-tools
.
You can further customize the header generation by creating an .options
file.See documentation for details.
If you want to perform further development of the nanopb core, or to verifyits functionality using your compiler and platform, you'll want to run thetest 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 notend in an error, the test cases were successful.
Note: Mac OS X by default aliases 'clang' as 'gcc', while not actuallysupporting the same command line options as gcc does. To run tests onMac OS X, use: scons CC=clang CXX=clang
. Same way can be used to runtests with different compilers on any platform.
For embedded platforms, there is currently support for running the testson STM32 discovery board and simavrAVR simulator. Use scons PLATFORM=STM32
and scons PLATFORM=AVR
to runthese tests.
Nanopb C code itself is designed to be portable and easy to buildon any platform. Often the bigger hurdle is running the generator whichtakes in the .proto
files and outputs .pb.c
definitions.
There exist build rules for several systems:
extra/nanopb.mk
, see examples/simple
extra/FindNanopb.cmake
, see examples/cmake
tests/site_scons
(generator only)BUILD
in source rootconanfile.py
in source rootAnd also integration to platform interfaces:
You can download and install nanopb using the vcpkg dependency manager:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install nanopb
The nanopb port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.
Nanopb:具有小代码量的协议缓冲区 Nanopb是一个ANSI-C库,用于以Google的协议缓冲区格式编码和解码消息,而对RAM和代码空间的要求最低。 它主要适用于32位微控制器。 文档版本 本文档适用于nanopb 0.4.0及更高版本。有关旧版本的文档,请参见此处。 整体结构 对于运行时程序,对于类型声明,始终需要pb.h,对于基本函数,始终需要pb_common.h / c。根据您是否
关于Protocol Buffers Protocol Buffers是Google开发的用于序列化数据的机制,它无关开发语言,无关使用平台,且具有良好的可扩展性。 使用Protocol Buffers,你只需要把你的数据定义为结构化的protocol buffer数据,然后使用编译工具把它编译成特定语言下的代码,调用编译后的代码接口,你就能很方便地将你的结构数据写成数据流(编码),或是将数据流读
1. Introduction 遇到的问题:Could not import the Google protobuf Python libraries 解决办法[1]: pip install --ignore-installed six sudo pip install protobuf 2. examples 2.1 使用protoc工具生成头文件和源文件 使用cmake 直接生成相应的头文
本文主要是通过迁移的思维,记录本人初次使用周立功的Aworks框架进行开发 本文在Aworks上使用nanopb库对string类型使用限制最大长度 1. 定义string消息协议 // A very simple protocol definition, consisting of only // one message. syntax = "proto2"; package com.bst.
整个过程起起伏伏. 1)理解options文件的作用,把repeat和string类型编为定长或定数的类型,max_size,max_count, 2)理解any类型的protobuf3中的含义,type_url及value, 3)理解encode/decode中的callback调用,这个直接入手比较困难,因为是在源码中回调的,可参考源码test文件夹下的alltype测试案例,以及http
本文主要是通过迁移的思维,记录本人初次使用周立功的Aworks框架进行开发 本文在Aworks上使用nanopb库对string类型字段进行封包及解包测试。 参考链接封包及解包原理:https://www.cnblogs.com/silvermagic/p/9087593.html 1. 定义string消息协议 message LaneStatus { bool showLane = 1;
.proto文件编译生成.pb.c和.pb.h的方法 1、编译.proto文件需要使用到下载到本地(以Windows为例)的磁盘中,如D盘,编译时需要使用的nanopb的路径为:D:\nanopb\nanopb-0.3.9.1-windows-x86\generator-bin 2、可以使用命令的方式进行编译proto文件,具体的操作方式请参考网上教程,此处不做解释。 3、使用脚本文件来进行自动编
github下载 https://github.com/nanopb/nanopb 安装python3.6 配置pip下载安装python以来库 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 安装python依赖库 pip install protobuf grpcio-tools 在generat
1 protobuf简介 Protobuf的功能是将是结构化数据转化为二进制流,比如, struct _msg { Int val; }msg; Unsigned char streambuf[256]; Msg A; A.val = 1; Protobuf.encode(streambuf,A); 如上,将结构化数据转为二进制流存到streambuf。使用时,再将二进制充转化为结构化数据,如
第一步 共享文件夹设置 sudo mount -t cifs -o username=wxq //192.168.1.245/share /mnt/myshare #username=wxq //192.168.1.245/share 是WINDOWS下的共享位置 # /mnt/myshare 是linux下的共享位置 12.5.5 build-5234757 vmware 版本 Ub
网址:http://www.voidcn.com/blog/skdev/article/p-5046297.html 转载于:https://www.cnblogs.com/wanhuan/p/5743381.html
什么是Protocol Buffers 简单定义: Protocol Buffer是谷歌推出的,和开发语言无关、平台无关、可扩展的机制,用于序列化结构化数据——像XML,但它更小、更快、更简单。 关键点: 1、跨平台。 2、可扩展。 3、序列化结构化数据。 4、使用简单。 官方网址: Protocol Buffers 支持最常使用的语言 1、C++ 2、C# 3、Java 4、Python 5、…
简介 与Protobuf-c 类似,nanopb 是也是一个轻量的、支持 C 语言的 Protobuf。 nanopb 下载地址: https://jpa.kapsi.fi/nanopb/download/ nanopb文档: https://jpa.kapsi.fi/nanopb/docs/index.html pb_callback_t 其结构定义为 typedef struct pb_cal
本blog记录nanopb使用过程 1. 安装protobuf(略) 2. 安装protobuf for python 库。 进入protobuf-2.5.0/python目录执行: python setup.py build python setup.py test python setup.py install 3.产生代码 protoc -omessage.pb message.proto
Google Protocol Buffer 有各种版本的代码包,Python C/C++、JAVA、C、OBJ-C、.NET等,嵌入式设备中使用的protobuf版本,我们选择的是nanoprobuf。 1)Google Protocol Buffer 的使用和原理 https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.html