{"id":22359065,"url":"https://github.com/bwireman/gleam_pb","last_synced_at":"2025-07-30T12:32:18.955Z","repository":{"id":44513469,"uuid":"413150218","full_name":"bwireman/gleam_pb","owner":"bwireman","description":"Protobuf support for Gleam ✨","archived":false,"fork":false,"pushed_at":"2022-09-08T10:04:07.000Z","size":45,"stargazers_count":25,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T07:52:30.261Z","etag":null,"topics":["erlang","gleam","protobuf"],"latest_commit_sha":null,"homepage":"","language":"Go","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/bwireman.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":"2021-10-03T17:35:44.000Z","updated_at":"2025-03-15T19:13:57.000Z","dependencies_parsed_at":"2023-01-18T01:00:47.842Z","dependency_job_id":null,"html_url":"https://github.com/bwireman/gleam_pb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/bwireman/gleam_pb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgleam_pb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgleam_pb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgleam_pb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgleam_pb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwireman","download_url":"https://codeload.github.com/bwireman/gleam_pb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgleam_pb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267867803,"owners_count":24157357,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["erlang","gleam","protobuf"],"created_at":"2024-12-04T15:19:22.573Z","updated_at":"2025-07-30T12:32:18.659Z","avatar_url":"https://github.com/bwireman.png","language":"Go","readme":"# gleam_pb\n\nProtobuf support for Gleam ✨\n\n---\n\ngleam_pb wraps the excellent [gpb](https://github.com/tomas-abrahamsson/gpb) erlang library and generates idiomatic Gleam types 🤘\n\n## Progress\n\n- [X] Gleam Type generation\n  - [X] custom functions that better handle default values\n  - [X] gleam format generated files\n  - [ ] stop including unnecessary imports\n- [X] message encoding\n- [X] message decoding\n- [ ] improve UX\n  - [X] call protoc-erl internally\n  - [X] flag to better handle gpb header includes\n  - [ ] helper functions\n- [ ] grpc\n\n## API\n\n### Generated types\n\ngleam_pb generally follows gpb's type generation, but makes it easier to use from Gleam.\n\n| protobuf | gleam_pb | gpb |\n|---|---|---|\n| double,float | Float | float() |\n| int32, int64, uint32, uint64, sint32, sint64, fixed32, fixed64, sfixed32, sfixed64 | Int | integer() |\n| bool | Bool | true \\| false |\n| enum | Zero Paramater Multi Constructor Type | atom() |\n| message | Option(\\\u003cCustomType\\\u003e) | record \\| undefined |\n| string | String | unicode string |\n| bytes | BitString | binary() |\n| oneof | Option(\\\u003cCustomType\\\u003e) with multiple constructors | {chosen_field, value} |\n| map | unordered list of tuples List(#(Key, Value)) | [{key, value}] |\n\n### Functions\n\ngleam_pb generates functions to make using the types easier\n\n- function to generate the message with protobuf's default values named new_\\\u003ccustom_type\\\u003e() -\u003e \\\u003cCustomType\\\u003e\n\n- functions to encode and decode the messages\n  - encode_\\\u003ccustom_type\\\u003e(m: \\\u003cCustomType\\\u003e) -\u003e BitString\n  - encode_\\\u003ccustom_type\\\u003e(b: BitString) -\u003e \\\u003cCustomType\\\u003e\n\nThere are also several other functions intended for usage by gleam_pb\n\n### Example\n\nThis message\n\n```protobuf\nsyntax = \"proto3\";\n\npackage protos;\n\nmessage Example {\n    \n    message Response {\n        int32 val = 1;\n        string user = 2;\n    }\n\n    enum OptionType {\n        foo = 0;\n        bar = 1;\n        baz = 2;\n    }\n\n    repeated OptionType options = 1;\n\n    oneof ResponseOrError {\n        Response response = 2;\n        string error = 3;\n    }\n}\n```\n\nBecomes\n\n```gleam\nimport gleam/option\nimport gleam/list\nimport gleam/pair\nimport gleam/dynamic\nimport gleam/erlang/atom\nimport gleam_pb\n\n/// protos package types generated by gleam_pb\n/// DO NOT EDIT\npub type OptionType {\n  OptionTypefoo\n  OptionTypebar\n  OptionTypebaz\n}\n\npub type ExampleResponseOrError {\n  ResponseOrErrorresponse(response: option.Option(Response))\n  ResponseOrErrorerror(error: String)\n}\n\npub type Example {\n  Example(\n    options: List(OptionType),\n    response_or_error: option.Option(ExampleResponseOrError),\n  )\n}\n\npub type Response {\n  Response(val: Int, user: String)\n}\n\npub fn new_example() {\n  Example(list.new(), option.None)\n}\n\npub fn new_response() {\n  Response(0, \"\")\n}\n\npub fn encode_example(m: Example) -\u003e BitString {\n  let name = atom.create_from_string(\"protos.Example\")\n\n  extract_example(name, m)\n  |\u003e gleam_pb.encode(name)\n}\n\npub fn decode_example(b: BitString) -\u003e Example {\n  let name = atom.create_from_string(\"protos.Example\")\n  decode_msg_example(b, name)\n  |\u003e reconstruct_example\n}\n\npub fn encode_response(m: Response) -\u003e BitString {\n  let name = atom.create_from_string(\"protos.Example.Response\")\n\n  extract_response(name, m)\n  |\u003e gleam_pb.encode(name)\n}\n\npub fn decode_response(b: BitString) -\u003e Response {\n  let name = atom.create_from_string(\"protos.Example.Response\")\n  decode_msg_response(b, name)\n  |\u003e reconstruct_response\n}\n\n//internal functions continue ...\n```\n\n## Usage\n\ngleam_pb and gpb must be used together to generate working Gleam code.\n\nExample Script\n\n```bash\n# make sure protoc-gen-gleam is in you're path or add it manually using --plugin\nprotoc --plugin=protoc-gen-gleam -I . --gleam_out=\"output_path=./src:./src\" protos/*.proto\n```\n\n### `gleam_pb` Flags\n\n- 'output_path': (Required) specifies the desired output path\n- 'protoc_erl_path': path to gpb's protoc-erl\n- 'gpb_header_include': path to prepend to the header include for gpb. See [Knwon Issues](#known-issues) for more info\n  - if you need a variable include here, remember that [erlang header resolution](https://www.erlang.org/doc/reference_manual/macros.html) is quite clever and can use environment variables\n\n```bash\nprotoc -I . \\\n  --gleam_out=\"gpb_header_include=$ENV/include/,output_path=./src,protoc_erl_path=bin/protoc-erl:./src\" \\\n  protos/*.proto\n```\n\n### Known Issues\n\n#### Includes aren't working?!\n\n```erlang\n% generated in `gleam_gpb.erl`\n-include(\"gpb.hrl\"). % -\u003e update to point to the correct header post Gleam compilation\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwireman%2Fgleam_pb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwireman%2Fgleam_pb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwireman%2Fgleam_pb/lists"}