{"id":16686353,"url":"https://github.com/yoheimuta/go-protoparser","last_synced_at":"2025-04-14T00:59:02.334Z","repository":{"id":39969497,"uuid":"141877235","full_name":"yoheimuta/go-protoparser","owner":"yoheimuta","description":"Yet another Go package which parses a Protocol Buffer file (proto2+proto3)","archived":false,"fork":false,"pushed_at":"2025-01-29T11:07:15.000Z","size":413,"stargazers_count":194,"open_issues_count":7,"forks_count":22,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-14T00:58:55.902Z","etag":null,"topics":["formatter","golang","golang-package","parser","proto2","proto3","protobuf","protobuf-parser","protocol-buffers"],"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/yoheimuta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-07-22T08:04:39.000Z","updated_at":"2025-04-08T14:21:35.000Z","dependencies_parsed_at":"2024-02-17T08:23:53.630Z","dependency_job_id":"64e39772-f121-4c25-ac8d-b5b8712f8a5f","html_url":"https://github.com/yoheimuta/go-protoparser","commit_stats":{"total_commits":237,"total_committers":14,"mean_commits":"16.928571428571427","dds":"0.14345991561181437","last_synced_commit":"840b016ab5f75d49d9aa39f3802edc0ee4feb78b"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-protoparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-protoparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-protoparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-protoparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoheimuta","download_url":"https://codeload.github.com/yoheimuta/go-protoparser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804790,"owners_count":21164132,"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":["formatter","golang","golang-package","parser","proto2","proto3","protobuf","protobuf-parser","protocol-buffers"],"created_at":"2024-10-12T15:05:32.282Z","updated_at":"2025-04-14T00:59:02.311Z","avatar_url":"https://github.com/yoheimuta.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-protoparser [![GoDoc](https://godoc.org/github.com/yoheimuta/go-protoparser/v4?status.svg)](https://pkg.go.dev/github.com/yoheimuta/go-protoparser/v4)[![CircleCI](https://circleci.com/gh/yoheimuta/go-protoparser/tree/master.svg?style=svg)](https://circleci.com/gh/yoheimuta/go-protoparser/tree/master)[![Go Report Card](https://goreportcard.com/badge/github.com/yoheimuta/go-protoparser/v4)](https://goreportcard.com/report/github.com/yoheimuta/go-protoparser/v4)[![Release](http://img.shields.io/github/release/yoheimuta/go-protoparser.svg?style=flat)](https://github.com/yoheimuta/go-protoparser/releases/latest)[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/yoheimuta/go-protoparser/blob/master/LICENSE.md)\n\ngo-protoparser is a yet another Go package which parses a Protocol Buffer file (editions+proto2+proto3).\n\n- Conforms to the exactly [official spec](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec).\n- Undergone rigorous testing. The parser can parses all examples of the official spec well.\n- Easy to use the parser. You can just call the [Parse function](https://godoc.org/github.com/yoheimuta/go-protoparser/v4#Parse) and receive the [Proto struct](https://godoc.org/github.com/yoheimuta/go-protoparser/v4/parser#Proto).\n  - If you don't care about the order of body elements, consider to use the [unordered.Proto struct](https://godoc.org/github.com/yoheimuta/go-protoparser/v4/interpret/unordered#Proto).\n  - Or if you want to use the visitor pattern, use the [Visitor struct](https://godoc.org/github.com/yoheimuta/go-protoparser/v4/parser#Visitor).\n\n### Installation\n\n```\nGO111MODULE=on go get github.com/yoheimuta/go-protoparser/v4\n```\n\n### Example\n\nA Protocol Buffer file versioned 3 which is [an example of the official reference](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file).\n\n```proto\nsyntax = \"proto3\";\n// An example of the official reference\n// See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file\npackage examplepb;\nimport public \"other.proto\";\noption java_package = \"com.example.foo\";\nenum EnumAllowingAlias {\n    option allow_alias = true;\n    UNKNOWN = 0;\n    STARTED = 1;\n    RUNNING = 2 [(custom_option) = \"this is a \"\n                                   \"string on two lines\"\n                ];\n}\nmessage outer {\n    option (my_option).a = true;\n    message inner {   // Level 2\n      int64 ival = 1;\n    }\n    repeated inner inner_message = 2;\n    EnumAllowingAlias enum_field =3;\n    map\u003cint32, string\u003e my_map = 4;\n}\nservice HelloService {\n  rpc SayHello (HelloRequest) returns (HelloResponse) {};\n}\n```\n\nThe Parsed result is a Go typed struct. The below output is encoded to JSON for simplicity.\n\n```json\n{\n  \"Syntax\": {\n    \"ProtobufVersion\": \"proto3\",\n    \"ProtobufVersionQuote\": \"\\\"proto3\\\"\",\n    \"Comments\": null,\n    \"InlineComment\": null,\n    \"Meta\": {\n      \"Pos\": {\n        \"Filename\": \"simple.proto\",\n        \"Offset\": 0,\n        \"Line\": 1,\n        \"Column\": 1\n      },\n      \"LastPos\": {\n        \"Filename\": \"\",\n        \"Offset\": 0,\n        \"Line\": 0,\n        \"Column\": 0\n      }\n    }\n  },\n  \"ProtoBody\": [\n    {\n      \"Name\": \"examplepb\",\n      \"Comments\": [\n        {\n          \"Raw\": \"// An example of the official reference\",\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 19,\n              \"Line\": 2,\n              \"Column\": 1\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"Raw\": \"// See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file\",\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 59,\n              \"Line\": 3,\n              \"Column\": 1\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        }\n      ],\n      \"InlineComment\": null,\n      \"Meta\": {\n        \"Pos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 151,\n          \"Line\": 4,\n          \"Column\": 1\n        },\n        \"LastPos\": {\n          \"Filename\": \"\",\n          \"Offset\": 0,\n          \"Line\": 0,\n          \"Column\": 0\n        }\n      }\n    },\n    {\n      \"Modifier\": 1,\n      \"Location\": \"\\\"other.proto\\\"\",\n      \"Comments\": null,\n      \"InlineComment\": null,\n      \"Meta\": {\n        \"Pos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 170,\n          \"Line\": 5,\n          \"Column\": 1\n        },\n        \"LastPos\": {\n          \"Filename\": \"\",\n          \"Offset\": 0,\n          \"Line\": 0,\n          \"Column\": 0\n        }\n      }\n    },\n    {\n      \"OptionName\": \"java_package\",\n      \"Constant\": \"\\\"com.example.foo\\\"\",\n      \"Comments\": null,\n      \"InlineComment\": null,\n      \"Meta\": {\n        \"Pos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 199,\n          \"Line\": 6,\n          \"Column\": 1\n        },\n        \"LastPos\": {\n          \"Filename\": \"\",\n          \"Offset\": 0,\n          \"Line\": 0,\n          \"Column\": 0\n        }\n      }\n    },\n    {\n      \"EnumName\": \"EnumAllowingAlias\",\n      \"EnumBody\": [\n        {\n          \"OptionName\": \"allow_alias\",\n          \"Constant\": \"true\",\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 269,\n              \"Line\": 8,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"Ident\": \"UNKNOWN\",\n          \"Number\": \"0\",\n          \"EnumValueOptions\": null,\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 300,\n              \"Line\": 9,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"Ident\": \"STARTED\",\n          \"Number\": \"1\",\n          \"EnumValueOptions\": null,\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 317,\n              \"Line\": 10,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"Ident\": \"RUNNING\",\n          \"Number\": \"2\",\n          \"EnumValueOptions\": [\n            {\n              \"OptionName\": \"(custom_option)\",\n              \"Constant\": \"\\\"this is a string on two lines\\\"\"\n            }\n          ],\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 334,\n              \"Line\": 11,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        }\n      ],\n      \"Comments\": null,\n      \"InlineComment\": null,\n      \"InlineCommentBehindLeftCurly\": null,\n      \"Meta\": {\n        \"Pos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 240,\n          \"Line\": 7,\n          \"Column\": 1\n        },\n        \"LastPos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 454,\n          \"Line\": 14,\n          \"Column\": 1\n        }\n      }\n    },\n    {\n      \"MessageName\": \"outer\",\n      \"MessageBody\": [\n        {\n          \"OptionName\": \"(my_option).a\",\n          \"Constant\": \"true\",\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 476,\n              \"Line\": 16,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"MessageName\": \"inner\",\n          \"MessageBody\": [\n            {\n              \"IsRepeated\": false,\n              \"IsRequired\": false,\n              \"IsOptional\": false,\n              \"Type\": \"int64\",\n              \"FieldName\": \"ival\",\n              \"FieldNumber\": \"1\",\n              \"FieldOptions\": null,\n              \"Comments\": null,\n              \"InlineComment\": null,\n              \"Meta\": {\n                \"Pos\": {\n                  \"Filename\": \"simple.proto\",\n                  \"Offset\": 544,\n                  \"Line\": 18,\n                  \"Column\": 7\n                },\n                \"LastPos\": {\n                  \"Filename\": \"\",\n                  \"Offset\": 0,\n                  \"Line\": 0,\n                  \"Column\": 0\n                }\n              }\n            }\n          ],\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"InlineCommentBehindLeftCurly\": {\n            \"Raw\": \"// Level 2\",\n            \"Meta\": {\n              \"Pos\": {\n                \"Filename\": \"simple.proto\",\n                \"Offset\": 527,\n                \"Line\": 17,\n                \"Column\": 23\n              },\n              \"LastPos\": {\n                \"Filename\": \"\",\n                \"Offset\": 0,\n                \"Line\": 0,\n                \"Column\": 0\n              }\n            }\n          },\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 509,\n              \"Line\": 17,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 564,\n              \"Line\": 19,\n              \"Column\": 5\n            }\n          }\n        },\n        {\n          \"IsRepeated\": true,\n          \"IsRequired\": false,\n          \"IsOptional\": false,\n          \"Type\": \"inner\",\n          \"FieldName\": \"inner_message\",\n          \"FieldNumber\": \"2\",\n          \"FieldOptions\": null,\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 570,\n              \"Line\": 20,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"IsRepeated\": false,\n          \"IsRequired\": false,\n          \"IsOptional\": false,\n          \"Type\": \"EnumAllowingAlias\",\n          \"FieldName\": \"enum_field\",\n          \"FieldNumber\": \"3\",\n          \"FieldOptions\": null,\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 608,\n              \"Line\": 21,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        },\n        {\n          \"KeyType\": \"int32\",\n          \"Type\": \"string\",\n          \"MapName\": \"my_map\",\n          \"FieldNumber\": \"4\",\n          \"FieldOptions\": null,\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 645,\n              \"Line\": 22,\n              \"Column\": 5\n            },\n            \"LastPos\": {\n              \"Filename\": \"\",\n              \"Offset\": 0,\n              \"Line\": 0,\n              \"Column\": 0\n            }\n          }\n        }\n      ],\n      \"Comments\": null,\n      \"InlineComment\": null,\n      \"InlineCommentBehindLeftCurly\": null,\n      \"Meta\": {\n        \"Pos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 456,\n          \"Line\": 15,\n          \"Column\": 1\n        },\n        \"LastPos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 676,\n          \"Line\": 23,\n          \"Column\": 1\n        }\n      }\n    },\n    {\n      \"ServiceName\": \"HelloService\",\n      \"ServiceBody\": [\n        {\n          \"RPCName\": \"SayHello\",\n          \"RPCRequest\": {\n            \"IsStream\": false,\n            \"MessageType\": \"HelloRequest\",\n            \"Meta\": {\n              \"Pos\": {\n                \"Filename\": \"simple.proto\",\n                \"Offset\": 716,\n                \"Line\": 25,\n                \"Column\": 16\n              },\n              \"LastPos\": {\n                \"Filename\": \"\",\n                \"Offset\": 0,\n                \"Line\": 0,\n                \"Column\": 0\n              }\n            }\n          },\n          \"RPCResponse\": {\n            \"IsStream\": false,\n            \"MessageType\": \"HelloResponse\",\n            \"Meta\": {\n              \"Pos\": {\n                \"Filename\": \"simple.proto\",\n                \"Offset\": 739,\n                \"Line\": 25,\n                \"Column\": 39\n              },\n              \"LastPos\": {\n                \"Filename\": \"\",\n                \"Offset\": 0,\n                \"Line\": 0,\n                \"Column\": 0\n              }\n            }\n          },\n          \"Options\": null,\n          \"Comments\": null,\n          \"InlineComment\": null,\n          \"Meta\": {\n            \"Pos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 703,\n              \"Line\": 25,\n              \"Column\": 3\n            },\n            \"LastPos\": {\n              \"Filename\": \"simple.proto\",\n              \"Offset\": 757,\n              \"Line\": 25,\n              \"Column\": 57\n            }\n          }\n        }\n      ],\n      \"Comments\": null,\n      \"InlineComment\": null,\n      \"InlineCommentBehindLeftCurly\": null,\n      \"Meta\": {\n        \"Pos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 678,\n          \"Line\": 24,\n          \"Column\": 1\n        },\n        \"LastPos\": {\n          \"Filename\": \"simple.proto\",\n          \"Offset\": 759,\n          \"Line\": 26,\n          \"Column\": 1\n        }\n      }\n    }\n  ],\n  \"Meta\": {\n    \"Filename\": \"simple.proto\"\n  }\n}\n```\n\n### Usage\n\nSee also `_example/dump`.\n\n```go\nfunc run() int {\n\tflag.Parse()\n\n\treader, err := os.Open(*proto)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to open %s, err %v\\n\", *proto, err)\n\t\treturn 1\n\t}\n\tdefer reader.Close()\n\n\tgot, err := protoparser.Parse(reader)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to parse, err %v\\n\", err)\n\t\treturn 1\n\t}\n\n\tgotJSON, err := json.MarshalIndent(got, \"\", \"  \")\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to marshal, err %v\\n\", err)\n\t}\n\tfmt.Print(string(gotJSON))\n\treturn 0\n}\n\nfunc main() {\n\tos.Exit(run())\n}\n```\n\n### Users\n\n- [protolint](https://github.com/yoheimuta/protolint)\n- [Known importers](https://pkg.go.dev/github.com/yoheimuta/go-protoparser/v4?tab=importedby)\n\n### Motivation\n\nThere exists the similar protobuf parser packages in Go.\n\nBut I could not find the parser which just return a parsing result well-typed value.\nA parser which supports a visitor pattern is useful to implement like linter, but it may be difficult to use.\nIt can be sufficient for most parsing situations to just return a parsing result well-typed value.\nThis is easier to use.\n\n### Contributing\n\n- Fork it\n- Create your feature branch: git checkout -b your-new-feature\n- Commit changes: git commit -m 'Add your feature'\n- Pass all tests\n- Push to the branch: git push origin your-new-feature\n- Submit a pull request\n\n### License\n\nThe MIT License (MIT)\n\n### Acknowledgement\n\nThank you to the proto package: https://github.com/emicklei/proto\n\nI referred to the package for the good proven design, interface and some source code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoheimuta%2Fgo-protoparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoheimuta%2Fgo-protoparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoheimuta%2Fgo-protoparser/lists"}