https://github.com/rogchap/protoparser
A Protocol Buffer proto file parser for Go
https://github.com/rogchap/protoparser
Last synced: 4 months ago
JSON representation
A Protocol Buffer proto file parser for Go
- Host: GitHub
- URL: https://github.com/rogchap/protoparser
- Owner: rogchap
- Created: 2020-03-04T03:02:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-09T00:19:29.000Z (over 5 years ago)
- Last Synced: 2025-02-16T05:38:27.885Z (4 months ago)
- Language: Go
- Size: 21.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Proto Parser - a Protocol Buffer proto file parser for Go
**NOTE: This is a new project that is WIP, and is not ready for production use**
## Motivation
There are a few parsers that are already available:
* https://github.com/emicklei/proto
* https://github.com/yoheimuta/go-protoparserHowever, both these parsers have there own defined AST and APIs for managing proto files. The aim of protoparser is to
provide a parser that uses the standard [`descriptorpb.FileDescriptorProto`](https://pkg.go.dev/google.golang.org/protobuf/types/descriptorpb?tab=doc#FileDescriptorProto) as the AST and provide a very basic API.These makes it easier to use the standard protocol buffer tooling for Go (especially APIv2)
For example using the `protodesc` package for converting `FileDescriptorProto` messages to
`protoreflect.FileDescriptor` values. See
[google.golang.org/protobuf](https://pkg.go.dev/google.golang.org/protobuf?tab=overview) for details.## Design Spec
The parser should follow the [Protocol Buffers Version 3 Language
Specification](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec)## Usage
```go
package mainimport (
"fmt""rogchap.com/protoparser"
)func main() {
src := `
syntax = "proto3";
package foo.bar;message Foo {
string name = 1;
}
message Bar {
string id = 1;
Foo foo = 2;
}
`// Parse the source
fd, err := protoparser.ParseFile("", src)
if err != nil {
fmt.Println(err)
return
}// Print the all the messages and their fields
for _, m := fd.MessageType {
fmt.Println(m.Name)
for _, f := m.Field {
fmt.Println(" - "+f.Name)
}
fmt.Println()
}
}