{"id":16239864,"url":"https://github.com/nopnop2002/esp-idf-protocol-buffer","last_synced_at":"2025-03-19T16:31:39.760Z","repository":{"id":62398337,"uuid":"502224166","full_name":"nopnop2002/esp-idf-protocol-buffer","owner":"nopnop2002","description":"Example of Google Protocol Buffers Serialize and Deserialize with ESP-IDF","archived":false,"fork":false,"pushed_at":"2023-08-26T06:28:38.000Z","size":9,"stargazers_count":36,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T19:53:13.615Z","etag":null,"topics":["esp-idf","esp32","protobuf"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nopnop2002.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-11T01:44:05.000Z","updated_at":"2025-02-11T11:29:53.000Z","dependencies_parsed_at":"2024-10-27T21:23:34.366Z","dependency_job_id":"fac53f2e-fe04-426a-a47b-c23ea9712c05","html_url":"https://github.com/nopnop2002/esp-idf-protocol-buffer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nopnop2002%2Fesp-idf-protocol-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nopnop2002%2Fesp-idf-protocol-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nopnop2002%2Fesp-idf-protocol-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nopnop2002%2Fesp-idf-protocol-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nopnop2002","download_url":"https://codeload.github.com/nopnop2002/esp-idf-protocol-buffer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244006260,"owners_count":20382441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp-idf","esp32","protobuf"],"created_at":"2024-10-10T13:45:26.130Z","updated_at":"2025-03-19T16:31:38.219Z","avatar_url":"https://github.com/nopnop2002.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esp-idf-protocol-buffer\nExample of Google Protocol Buffers Serialize and Deserialize with ESP-IDF.   \n\nIn MQTT for IoT devices, JSON is used as the serialization format of the message.   \nHowever, for low-performance hardware, JSON parsing in C is a heavy load.   \nSo when I was looking for a good serialized format that could be implemented in C, I found protobuf.\n\nESP-IDF includes [this](https://developers.google.com/protocol-buffers/) Google Protocol Buffers library.   \nYou can use Protocol Buffers components as standard.   \nBut there is no example code in ESP-IDF.   \n\nI ported from [this](https://github.com/protobuf-c/protobuf-c/wiki/Examples).\n\n\n# Software requirements\nesp-idf v4.4/v5.x.   \n\n# Installation\n```\ngit clone https://github.com/nopnop2002/esp-idf-protocol-buffer\ncd esp-idf-protocol-buffer\nidf.py flash monitor\n```\n\n- Serialize\n```\nI (328) MAIN: Writing 4 serialized bytes\nI (338) MAIN: 0x3ffaff78   08 0a 10 02                                       |....|\n```\n- DeSerialize\n```\nI (338) MAIN: deserialize: a=10\nI (348) MAIN: deserialize: b=2\n```\n\n\n\n# How to use Protocol Buffers\n\n### Install protobuf-c-compiler and c-library in ubuntu\n```\n$ sudo apt install protobuf-c-compiler libprotobuf-c-dev\n$ protoc-c --version\nprotobuf-c 1.3.3\nlibprotoc 3.6.1\n```\n\n### Make message define file\n```\n$ cat amessage.proto\nsyntax = \"proto2\";\n\nmessage AMessage {\n  required int32 a=1;\n  optional int32 b=2;\n}\n```\n\n### Compile message define file\nprotoc-c generates header files and source code.   \n```\n$ protoc-c --c_out=. amessage.proto\n\n$ ls amessage.*\namessage.pb-c.c  amessage.pb-c.h  amessage.proto\n```\n\n### Copy header files and source code to your project\n```\n$ cp amessage.pb-c.* /your_project/main/\n```\n\n### Include header files to your source\n```\n#include \"amessage.pb-c.h\"\n```\n\n### Add source file to your CMakeLists.txt\n```\nset(component_srcs main.c amessage.pb-c.c)\n```\n\n\n\n# About proto3 description format   \n___proto3 is not supported.___   \nAn error occurs while building the firmware.\n```\n../main/main.c:23:12: error: 'AMessage' {aka 'struct _AMessage'} has no member named 'has_b'\n   23 |         msg.has_b = 1;\n      |            ^\n../main/main.c:41:17: error: 'AMessage' {aka 'struct _AMessage'} has no member named 'has_b'\n   41 |         if (msg2-\u003ehas_b) // handle optional field\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnopnop2002%2Fesp-idf-protocol-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnopnop2002%2Fesp-idf-protocol-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnopnop2002%2Fesp-idf-protocol-buffer/lists"}