安装工具软件:html
$ sudo apt-get install protoc // 把proto生成.pb文件 $ sudo apt-get install python // 利用官方提供的python脚本把pb文件生成可使用的c和h文件
最好使用linux
下vi
编译器编写proto
文件,在其它编译环境下(如win
)编译的proto
文件在转换成c/h
文件时可能会报错,缘由是编码格式的问题,有些编辑环境会在文件的开头有一个特殊的字符,致使不能识别。python
产生代码:linux
$ protoc -o message.pb message.proto $ python nanopb/generator/nanopb_generator.py message.pb
执行nanopb_generator.py
脚本时,出现以下错误:工具
*** Could not import the Google protobuf Python libraries *** *** Try installing package 'python-protobuf' or similar. *** ************************************************************* Traceback (most recent call last): File "generator/nanopb_generator.py", line 21, in <module> import google.protobuf.text_format as text_format ModuleNotFoundError: No module named 'google'
nanopb protobuf学习笔记
Nanopb - protocol buffers with small code size
在嵌入式设备中使用protobuf
在嵌入式设备中使用protobuf
Protobuf 安装与nanopb简单实例
nanopb分析和使用说明学习