{"id":13611884,"url":"https://github.com/travisstaloch/protobuf-zig","last_synced_at":"2025-06-23T08:36:30.042Z","repository":{"id":155683584,"uuid":"589883461","full_name":"travisstaloch/protobuf-zig","owner":"travisstaloch","description":"A protocol buffers implementation in zig","archived":false,"fork":false,"pushed_at":"2024-11-04T22:14:56.000Z","size":509,"stargazers_count":48,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T18:54:34.012Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","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/travisstaloch.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":"2023-01-17T06:57:46.000Z","updated_at":"2025-01-14T15:52:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"40945b14-d571-4359-a725-ce1865fa441f","html_url":"https://github.com/travisstaloch/protobuf-zig","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fprotobuf-zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fprotobuf-zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fprotobuf-zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fprotobuf-zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/travisstaloch","download_url":"https://codeload.github.com/travisstaloch/protobuf-zig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858143,"owners_count":20359253,"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-08-01T19:02:17.165Z","updated_at":"2025-03-17T09:30:31.454Z","avatar_url":"https://github.com/travisstaloch.png","language":"Zig","funding_links":[],"categories":["Zig","Language Essentials"],"sub_categories":["File Format Processing"],"readme":":warning: This project is in its early early stages. expect bugs and missing features. :warning:\n\n# About\nA tool for generating zig code capable of de/serializing to the protocol buffer wire format.  Depends on [protoc](https://developers.google.com/protocol-buffers/docs/downloads) to parse .proto files.  \n\n# Status\n- [x] zig code generation\n  - [ ] recursive message types don't work yet [#1](../../issues/1). see [examples/recursive.proto](examples/recursive.proto)\n- [x] deserialization from wire format\n  - [ ] merging messages not yet implemented - 6 conformance failures\n- [x] serialization to wire format\n- [x] initial serialization to json format - 9 conformance failures\n- [w] conformance testing results: 1489/408/15 success/skip/fail.  the 408 skipped are in these categories:\n  - [ ] json input\n  - [ ] text format output\n  - [ ] jspb format output\n\n# Usage\n\n* download the [`protoc` compiler](https://protobuf.dev/downloads/)\n* make sure `protoc` is in your PATH\n\nNote: this project has been tested against\n```console\n$ protoc --version\nlibprotoc 21.5\n```\n\n\n### Build\n```console\nzig build\n```\n\n### Run tests. \nnote: some of these depend on `protoc` being available.\n```console\nzig build test\n```\n\n### Generate .zig files from .proto files\n```console\n$ zig build run -- -I examples/ examples/person.proto examples/only_enum.proto\n# writes generated content to ./gen/ by default.  \n# use --zig_out=/gen-path to specify different directory.\n```\n\nNote: all arguments after -- are forwarded to `protoc`. \n\nThis is equivalent to:\n```console\n$ zig build\n$ protoc --plugin=zig-out/bin/protoc-gen-zig --zig_out=gen -I examples/ examples/person.proto examples/only_enum.proto\n```\n\nEither of the above generate the following files in gen/:\n```console\n$ ls gen\nonly_enum.pb.zig  person.pb.zig\n```\n\n### Use the generated code\n  * see below for an example `zig test` command\n  * see [build.zig](build.zig) for a packaging example\n```zig\ntest \"readme\" {\n    // Note - the package 'protobuf' below is src/lib.zig.  this package must\n    // include itself. it can be provided in build.zig or on the command line\n    // as shown below.    \n    const std = @import(\"std\");\n    const pb = @import(\"protobuf\");\n    const Person = @import(\"generated\").person.Person;\n\n    // serialize to a writer\n    const alloc = std.testing.allocator; // could be any zig std.mem.Allocator\n    var zero = Person.initFields(.{\n        .id = 1,\n        .name = pb.extern_types.String.init(\"zero\"),\n        .kind = .NONE,\n    });\n    zero.set(.id, 0);\n    var buf = std.ArrayList(u8).init(alloc);\n    defer buf.deinit();\n    try pb.protobuf.serialize(\u0026zero.base, buf.writer());\n\n    // deserialize from a buffer\n    var ctx = pb.protobuf.context(buf.items, alloc);\n    const message = try ctx.deserialize(\u0026Person.descriptor);\n    defer message.deinit(alloc);\n    var zero_copy = try message.as(Person);\n\n    // test that they're equal\n    try std.testing.expect(zero_copy.has(.id));\n    try std.testing.expectEqual(zero.id, zero_copy.id);\n    try std.testing.expect(zero_copy.has(.name));\n    try std.testing.expectEqualStrings(zero.name.slice(), zero_copy.name.slice());\n    try std.testing.expect(zero_copy.has(.kind));\n    try std.testing.expectEqual(zero.kind, zero_copy.kind);\n\n    // serialize to json\n    // const stderr = std.io.getStdErr().writer();\n    const stderr = std.io.null_writer;\n    try pb.json.serialize(\u0026zero.base, stderr, .{\n        .pretty_print = .{ .indent_size = 2 },\n    });\n    _ = try stderr.write(\"\\n\");\n    // prints\n    //{\n    //  \"name\": \"zero\",\n    //  \"id\": 0,\n    //  \"kind\": \"NONE\"\n    //}\n}\n```\n\n```console\n$ zig test src/tests.zig --mod protobuf:protobuf:src/lib.zig --mod generated:protobuf:zig-cache/protobuf-zig/lib.zig --deps protobuf,generated\n```\n\n# Resources\n### inspired by\n* https://github.com/protobuf-c/protobuf-c\n* https://github.com/mlugg/zigpb","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravisstaloch%2Fprotobuf-zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftravisstaloch%2Fprotobuf-zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravisstaloch%2Fprotobuf-zig/lists"}