{"id":17294955,"url":"https://github.com/hayesgm/protobuf-ex","last_synced_at":"2025-07-31T04:31:36.846Z","repository":{"id":57537437,"uuid":"143488185","full_name":"hayesgm/protobuf-ex","owner":"hayesgm","description":"Elixir Protobufs Implementation (Based on https://github.com/tony612/protobuf-elixir)","archived":false,"fork":false,"pushed_at":"2019-05-20T20:51:01.000Z","size":178,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-17T17:49:38.916Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/hayesgm.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}},"created_at":"2018-08-04T01:32:20.000Z","updated_at":"2023-07-28T06:57:33.000Z","dependencies_parsed_at":"2022-09-04T13:50:55.312Z","dependency_job_id":null,"html_url":"https://github.com/hayesgm/protobuf-ex","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/hayesgm%2Fprotobuf-ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayesgm%2Fprotobuf-ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayesgm%2Fprotobuf-ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayesgm%2Fprotobuf-ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hayesgm","download_url":"https://codeload.github.com/hayesgm/protobuf-ex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228215139,"owners_count":17886347,"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":[],"created_at":"2024-10-15T11:08:56.805Z","updated_at":"2024-12-05T01:11:18.474Z","avatar_url":"https://github.com/hayesgm.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# protobuf-ex\n\n[![Hex.pm](https://img.shields.io/hexpm/v/protobuf-ex.svg)](https://hex.pm/packages/protobuf-ex)\n\nA pure Elixir implementation of [Google Protobuf](https://developers.google.com/protocol-buffers/)\n\n## Why this instead of exprotobuf(gpb)?\n\nIt has some must-have and other cool features like:\n\n1. A protoc [plugin](https://developers.google.com/protocol-buffers/docs/cpptutorial#compiling-your-protocol-buffers) to generate Elixir code just like what other official libs do, which is powerful and reliable.\n2. Generate **simple and explicit** code with the power of Macro. (see [test/support/test_msg.ex](https://github.com/hayesgm/protobuf-ex/blob/master/test/support/test_msg.ex))\n3. Plugins support.\n4. Use **structs** for messages instead of Erlang records.\n5. Support Typespec in generated code.\n\n## Installation\n\nThe package can be installed\nby adding `protobuf` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:protobuf_ex, \"~\u003e 0.6.1\"}]\nend\n```\n\n## Features\n\n* [x] Define messages with DSL\n* [x] Decode basic messages\n* [x] Skip unknown fields\n* [x] Decode embedded messages\n* [x] Decode packed and repeated fields\n* [x] Encode messages\n* [x] protoc plugin\n* [x] map\n* [x] Support default values\n* [x] Validate values\n* [x] Generate typespecs\n* [x] Plugins\n* [ ] oneof\n\n## Usage\n\n### Generate Elixir code\n\n1. Install `protoc`(cpp) [here](https://developers.google.com/protocol-buffers/docs/downloads)\n2. Install protoc plugin `protoc-gen-elixir` for Elixir. NOTE: You have to make sure `protoc-gen-elixir`(this name is important) is in your PATH.\n```\n$ mix escript.install hex protobuf_ex\n```\n3. Generate Elixir code using protoc\n```\n$ protoc --elixir_out=./lib helloword.proto\n```\n4. Files `helloworld.pb.ex` will be generated, like:\n\n```elixir\ndefmodule Helloworld.HelloRequest do\n  use Protobuf, syntax: :proto3\n\n  @type t :: %__MODULE__{\n    name: String.t\n  }\n  defstruct [:name]\n\n  field :name, 1, type: :string\nend\n\ndefmodule Helloworld.HelloReply do\n  use Protobuf, syntax: :proto3\n\n  @type t :: %__MODULE__{\n    message: String.t\n  }\n  defstruct [:message]\n\n  field :message, 1, type: :string\nend\n```\n\n### Encode and decode in your code\n\n```elixir\nstruct = Foo.new(a: 3.2, c: Foo.Bar.new())\nencoded = Foo.encode(struct)\nstruct = Foo.decode(encoded)\n```\n\nNote:\n- You should use `YourModule.new` instead of using the struct directly because default values will be set for all fields.\n- Default values will be set by default in `decode`, which can be changed by `:use_default` option.\n- Validation is done in `encode`. An error will be raised if the struct is invalid(like type is not matched).\n\n### Tips for protoc\n\n- Custom protoc-gen-elixir name or path using `--plugin`\n```\n$ protoc --elixir_out=./lib --plugin=./protoc-gen-elixir *.proto\n```\n- Pass `-I` argument if you import other protobuf files\n```\n$ protoc -I protos --elixir_out=./lib protos/hello.proto\n```\n\n## Acknowledgements\n\nMany thanks to Tony Han's [protobuf-elixir](https://github.com/tony612/protobuf-elixir), [gpb](https://github.com/tomas-abrahamsson/gpb) and\n[golang/protobuf](https://github.com/golang/protobuf) as good examples of\nwriting Protobuf decoder/encoder. This code is maintained as a fork of protobuf-elixir until we can reconcile plugin support.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayesgm%2Fprotobuf-ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhayesgm%2Fprotobuf-ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayesgm%2Fprotobuf-ex/lists"}