emicklei/proto

parser for Google ProtocolBuffers definition

Go

614

144 commits

updated Aug 8, 2026

See the code

README

proto

Go GoDoc codecov

Package in Go for parsing Google Protocol Buffers .proto files version 2 + 3, editions

install

go get 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 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-2025, ernestmicklei.com. MIT License. Contributions welcome.

formatter
golang-package
parser
proto2
proto3
protobuf
protobuf-parser
protocol-buffers

Significant stargazers

Matt Layher

2,094 followers · starred Aug 2017

Márk Sági-Kazár

1,390 followers · starred Jan 2019

Yuki Yugui Sonoda

825 followers · starred Apr 2018

Paul Jolly

708 followers · starred Mar 2017

emicklei/proto

parser for Google ProtocolBuffers definition

Go

614

144 commits

updated Aug 8, 2026

See the code

README

proto

Go GoDoc codecov

Package in Go for parsing Google Protocol Buffers .proto files version 2 + 3, editions

install

go get 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 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-2025, ernestmicklei.com. MIT License. Contributions welcome.

formatter
golang-package
parser
proto2
proto3
protobuf
protobuf-parser
protocol-buffers

Significant stargazers

Matt Layher

2,094 followers · starred Aug 2017

Márk Sági-Kazár

1,390 followers · starred Jan 2019

Yuki Yugui Sonoda

825 followers · starred Apr 2018

Paul Jolly

708 followers · starred Mar 2017