Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emicklei/proto
parser for Google ProtocolBuffers definition
https://github.com/emicklei/proto
formatter golang-package parser proto2 proto3 protobuf protobuf-parser protocol-buffers
Last synced: 20 days ago
JSON representation
parser for Google ProtocolBuffers definition
- Host: GitHub
- URL: https://github.com/emicklei/proto
- Owner: emicklei
- License: mit
- Created: 2017-01-26T21:30:48.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T12:33:59.000Z (9 months ago)
- Last Synced: 2024-10-04T06:52:32.771Z (about 1 month ago)
- Topics: formatter, golang-package, parser, proto2, proto3, protobuf, protobuf-parser, protocol-buffers
- Language: Go
- Homepage:
- Size: 1.32 MB
- Stars: 586
- Watchers: 12
- Forks: 65
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-list - proto
README
# proto
[![Go Report Card](https://goreportcard.com/badge/github.com/emicklei/proto)](https://goreportcard.com/report/github.com/emicklei/proto)
[![GoDoc](https://pkg.go.dev/badge/github.com/emicklei/proto)](https://pkg.go.dev/github.com/emicklei/proto)
[![codecov](https://codecov.io/gh/emicklei/proto/branch/master/graph/badge.svg)](https://codecov.io/gh/emicklei/proto)Package in Go for parsing Google Protocol Buffers [.proto files version 2 + 3](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec)
### install
go get -u -v github.com/emicklei/proto
### usage
package main
import (
"fmt"
"os""github.com/emicklei/proto"
)func main() {
reader, _ := os.Open("test.proto")
defer reader.Close()parser := proto.NewParser(reader)
definition, _ := parser.Parse()proto.Walk(definition,
proto.WithService(handleService),
proto.WithMessage(handleMessage))
}func handleService(s *proto.Service) {
fmt.Println(s.Name)
}func handleMessage(m *proto.Message) {
lister := new(optionLister)
for _, each := range m.Elements {
each.Accept(lister)
}
fmt.Println(m.Name)
}type optionLister struct {
proto.NoopVisitor
}func (l optionLister) VisitOption(o *proto.Option) {
fmt.Println(o.Name)
}### validation
Current parser implementation is not completely validating `.proto` definitions.
In many but not all cases, the parser will report syntax errors when reading unexpected charaters or tokens.
Use some linting tools (e.g. https://github.com/uber/prototool) or `protoc` for full validation.### contributions
See [proto-contrib](https://github.com/emicklei/proto-contrib) for other contributions on top of this package such as protofmt, proto2xsd and proto2gql.
[protobuf2map](https://github.com/emicklei/protobuf2map) is a small package for inspecting serialized protobuf messages using its `.proto` definition.© 2017-2022, [ernestmicklei.com](http://ernestmicklei.com). MIT License. Contributions welcome.