Skip to content
parser for Google ProtocolBuffers definition
Go Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Fix Travis build (#105) Mar 6, 2019
.travis.yml Fix Travis build (#105) Mar 6, 2019
CHANGES.md
LICENSE pkg rename Jan 28, 2017
Makefile Fix Travis build (#105) Mar 6, 2019
README.md fixes issues reported by mpvl #107, #109 (#110) May 8, 2019
comment.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
comment_test.go add test to parse comment inside option array value, issue #116 (#117) Aug 28, 2019
enum.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
enum_test.go
extensions.go add Parent field to all Visitee (#68) Mar 8, 2018
extensions_test.go Remove most String methods and change String to SourceRepresentation … Dec 7, 2017
field.go fix issue #92 allow leading dot in type name (#93) Sep 25, 2018
field_test.go add test for issue and first fix, issue #111 (#112) May 31, 2019
go.mod Fix Travis build (#105) Mar 6, 2019
group.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
group_test.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
import.go fixes issues reported by mpvl #107, #109 (#110) May 8, 2019
import_test.go replacing scanner. branch is broken Nov 26, 2017
message.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
message_test.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
oneof.go make Oneof implement Documented (#120) Oct 1, 2019
oneof_test.go make Oneof implement Documented (#120) Oct 1, 2019
option.go add test to parse comment inside option array value, issue #116 (#117) Aug 28, 2019
option_test.go handle unset QuoteRune for SourceRepresentation, issue #113 (#114) Jun 6, 2019
package.go Enable parsing package names with a reserved prefix (#90) Jun 14, 2018
package_test.go Enable parsing package names with a reserved prefix (#90) Jun 14, 2018
parent_accessor.go add Parent field to all Visitee (#68) Mar 8, 2018
parent_test.go add Parent field to all Visitee (#68) Mar 8, 2018
parser.go fixes problem due to potential change in scanner error message go113 Aug 28, 2019
parser_test.go fix for Issue #94 (#96) Nov 10, 2018
proto.go add Parent field to all Visitee (#68) Mar 8, 2018
protobuf_test.go fixes for issue #86 (#87) May 12, 2018
range.go Remove most String methods and change String to SourceRepresentation … Dec 7, 2017
range_test.go Remove most String methods and change String to SourceRepresentation … Dec 7, 2017
reserved.go
reserved_test.go Remove most String methods and change String to SourceRepresentation … Dec 7, 2017
service.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
service_test.go Inline comments before body token { breaks parser (#119) Sep 25, 2019
syntax.go fixes issues reported by mpvl #107, #109 (#110) May 8, 2019
syntax_test.go replacing scanner. branch is broken Nov 26, 2017
token.go fixes issues reported by mpvl #107, #109 (#110) May 8, 2019
token_test.go fixes issues reported by mpvl #107, #109 (#110) May 8, 2019
visitor.go add Parent field to all Visitee (#68) Mar 8, 2018
visitor_test.go add license notice Feb 14, 2017
walk.go Add WithImport handler (#123) Oct 19, 2019
walk_test.go Add WithImport handler (#123) Oct 19, 2019

README.md

proto

Build Status Go Report Card GoDoc

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) {
	fmt.Println(m.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 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.

You can’t perform that action at this time.