Package in Go for parsing Google Protocol Buffers .proto files version 2 + 3
go get -u -v github.com/emicklei/proto
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) {
fmt.Println(m.Name)
}
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.
See proto-contrib for other contributions on top of this package such as protofmt, proto2xsd and proto2gql.
protobuf2map is a small package for inspecting serialized protobuf messages using its .proto
definition.
© 2017, ernestmicklei.com. MIT License. Contributions welcome.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。