nanopb protobuf學習使用

安裝工具軟件:html

$ sudo apt-get install protoc // 把proto生成.pb文件
$ sudo apt-get install python // 利用官方提供的python腳本把pb文件生成可使用的c和h文件

最好使用linuxvi編譯器編寫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分析和使用說明學習

相關文章
相關標籤/搜索