Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
rename proto3- > proto
Browse files Browse the repository at this point in the history
Change-Id: I30c381049b4e8a8b5d768b467ea79aeaa956a3ab
  • Loading branch information
emicklei committed Feb 1, 2017
1 parent 9e6d66e commit f033c90
Show file tree
Hide file tree
Showing 35 changed files with 71 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "proto3fmt",
"command": "protofmt",
"isShellCommand": true,
"args": ["${file}"],
"showOutput": "always"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# proto3
# proto

[![Build Status](https://travis-ci.org/emicklei/proto3.png)](https://travis-ci.org/emicklei/proto3)
[![GoDoc](https://godoc.org/github.com/emicklei/proto3?status.svg)](https://godoc.org/github.com/emicklei/proto3)
[![Build Status](https://travis-ci.org/emicklei/proto.png)](https://travis-ci.org/emicklei/proto)
[![GoDoc](https://godoc.org/github.com/emicklei/proto?status.svg)](https://godoc.org/github.com/emicklei/proto)

Package in Go for parsing Google Protocol Buffers [.proto files version 3] (https://developers.google.com/protocol-buffers/docs/reference/proto3-spec)
Package in Go for parsing Google Protocol Buffers [.proto files version 3] (https://developers.google.com/protocol-buffers/docs/reference/proto-spec)

### usage

parser := proto3.NewParser(anIOReader)
parser := proto.NewParser(anIOReader)
proto, err := parser.Parse()
if err != nil {
log.Fatalln("proto3 parsing failed", err)
log.Fatalln("proto parsing failed", err)
}

### install

go get -u -v github.com/emicklei/proto3
go get -u -v github.com/emicklei/proto

© 2017, ernestmicklei.com. MIT License. Contributions welcome.
32 changes: 16 additions & 16 deletions cmd/proto3fmt/formatter.go → cmd/protofmt/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"strings"

"github.com/emicklei/proto3"
"github.com/emicklei/proto"
)

type formatter struct {
Expand All @@ -16,7 +16,7 @@ type formatter struct {
indentSeparator string
}

func (f *formatter) VisitComment(c *proto3.Comment) {
func (f *formatter) VisitComment(c *proto.Comment) {
f.begin("comment")
if c.IsMultiline() {
fmt.Fprintln(f.w, "/*")
Expand All @@ -27,7 +27,7 @@ func (f *formatter) VisitComment(c *proto3.Comment) {
}
}

func (f *formatter) VisitEnum(e *proto3.Enum) {
func (f *formatter) VisitEnum(e *proto.Enum) {
f.begin("enum")
fmt.Fprintf(f.w, "enum %s {", e.Name)
f.indentLevel++
Expand All @@ -38,7 +38,7 @@ func (f *formatter) VisitEnum(e *proto3.Enum) {
io.WriteString(f.w, "}\n")
}

func (f *formatter) VisitEnumField(e *proto3.EnumField) {
func (f *formatter) VisitEnumField(e *proto.EnumField) {
f.begin("field")
io.WriteString(f.w, paddedTo(e.Name, 10))
fmt.Fprintf(f.w, " = %d", e.Integer)
Expand All @@ -50,15 +50,15 @@ func (f *formatter) VisitEnumField(e *proto3.EnumField) {
}
}

func (f *formatter) VisitImport(i *proto3.Import) {
func (f *formatter) VisitImport(i *proto.Import) {
f.begin("import")
if len(i.Kind) > 0 {
fmt.Fprintf(f.w, "import %s ", i.Kind)
}
fmt.Fprintf(f.w, "import %q;\n", i.Filename)
}

func (f *formatter) VisitMessage(m *proto3.Message) {
func (f *formatter) VisitMessage(m *proto.Message) {
f.begin("message")
fmt.Fprintf(f.w, "message %s {", m.Name)
f.newLineIf(len(m.Elements) > 0)
Expand All @@ -70,7 +70,7 @@ func (f *formatter) VisitMessage(m *proto3.Message) {
io.WriteString(f.w, "}\n")
}

func (f *formatter) VisitOption(o *proto3.Option) {
func (f *formatter) VisitOption(o *proto.Option) {
if o.IsEmbedded {
io.WriteString(f.w, "[(")
} else {
Expand All @@ -92,12 +92,12 @@ func (f *formatter) VisitOption(o *proto3.Option) {
}
}

func (f *formatter) VisitPackage(p *proto3.Package) {
func (f *formatter) VisitPackage(p *proto.Package) {
f.begin("package")
fmt.Fprintf(f.w, "package %s;\n", p.Name)
}

func (f *formatter) VisitService(s *proto3.Service) {
func (f *formatter) VisitService(s *proto.Service) {
f.begin("service")
fmt.Fprintf(f.w, "service %s {", s.Name)
f.indentLevel++
Expand All @@ -108,11 +108,11 @@ func (f *formatter) VisitService(s *proto3.Service) {
io.WriteString(f.w, "}\n")
}

func (f *formatter) VisitSyntax(s *proto3.Syntax) {
func (f *formatter) VisitSyntax(s *proto.Syntax) {
fmt.Fprintf(f.w, "syntax = %q;\n\n", s.Value)
}

func (f *formatter) VisitOneof(o *proto3.Oneof) {
func (f *formatter) VisitOneof(o *proto.Oneof) {
f.begin("oneof")
fmt.Fprintf(f.w, "oneof %s {", o.Name)
f.indentLevel++
Expand All @@ -123,7 +123,7 @@ func (f *formatter) VisitOneof(o *proto3.Oneof) {
io.WriteString(f.w, "}\n")
}

func (f *formatter) VisitOneofField(o *proto3.OneOfField) {
func (f *formatter) VisitOneofField(o *proto.OneOfField) {
f.begin("oneoffield")
fmt.Fprintf(f.w, "%s %s = %d", o.Type, o.Name, o.Sequence)
for _, each := range o.Options {
Expand All @@ -132,7 +132,7 @@ func (f *formatter) VisitOneofField(o *proto3.OneOfField) {
io.WriteString(f.w, ";\n")
}

func (f *formatter) VisitReserved(r *proto3.Reserved) {
func (f *formatter) VisitReserved(r *proto.Reserved) {
f.begin("reserved")
io.WriteString(f.w, "reserved")
if len(r.Ranges) > 0 {
Expand All @@ -148,7 +148,7 @@ func (f *formatter) VisitReserved(r *proto3.Reserved) {
io.WriteString(f.w, ";\n")
}

func (f *formatter) VisitRPC(r *proto3.RPC) {
func (f *formatter) VisitRPC(r *proto.RPC) {
f.begin("rpc")
fmt.Fprintf(f.w, "rpc %s (", r.Name)
if r.StreamsRequest {
Expand All @@ -163,12 +163,12 @@ func (f *formatter) VisitRPC(r *proto3.RPC) {
io.WriteString(f.w, ");\n")
}

func (f *formatter) VisitMapField(m *proto3.MapField) {
func (f *formatter) VisitMapField(m *proto.MapField) {
f.begin("map")
fmt.Fprintf(f.w, "map<%s,%s> %s = %d;\n", m.KeyType, m.Type, m.Name, m.Sequence)
}

func (f *formatter) VisitNormalField(f1 *proto3.NormalField) {
func (f *formatter) VisitNormalField(f1 *proto.NormalField) {
f.begin("field")
if f1.Repeated {
io.WriteString(f.w, "repeated ")
Expand Down
11 changes: 5 additions & 6 deletions cmd/proto3fmt/main.go → cmd/protofmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"log"
"os"

"github.com/emicklei/proto3"
"github.com/emicklei/proto"
)

// go run *.go example1.proto
// go run *.go example0.proto
// go run *.go unformatted.proto
func main() {
if len(os.Args) == 1 {
log.Fatal("Usage: proto3fmt my.proto")
log.Fatal("Usage: protofmt my.proto")
}
i, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer i.Close()
p := proto3.NewParser(i)
p := proto.NewParser(i)
def, err := p.Parse()
if err != nil {
log.Fatalln("proto3fmt failed", err)
log.Fatalln("protofmt failed", err)
}
f := &formatter{w: os.Stdout, indentSeparator: " "}
for _, each := range def.Elements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import public "testdata/test.proto";

/* This pkg
*/
package here.proto3_proto ;
package here.proto_proto ;


// from a bottle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//
// A proto file we will use for unit testing.

syntax = "proto3";
syntax = "proto";

// Some generic_services option(s) added automatically.
// See: http://go/proto2-generic-services-default
Expand All @@ -44,7 +44,7 @@ option py_generic_services = true; // auto-added
option cc_enable_arenas = true;
option csharp_namespace = "Google.Protobuf.TestProtos";

import "google/protobuf/unittest_import_proto3.proto";
import "google/protobuf/unittest_import_proto.proto";

// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
Expand Down Expand Up @@ -221,7 +221,7 @@ enum TestSparseEnum {
SPARSE_C = 12589234;
SPARSE_D = -15;
SPARSE_E = -53452;
// In proto3, value 0 must be the first one specified
// In proto, value 0 must be the first one specified
// SPARSE_F = 0;
SPARSE_G = 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto3";
syntax = "proto";

option cc_enable_arenas = true;

import "google/protobuf/unittest_import.proto";

package proto3_arena_unittest;
package proto_arena_unittest;

// This proto includes every type of field in both singular and repeated
// forms.
Expand Down Expand Up @@ -71,7 +71,7 @@ message TestAllTypes {
string optional_string = 14;
bytes optional_bytes = 15;

// Groups are not allowed in proto3.
// Groups are not allowed in proto.
// optional group OptionalGroup = 16 {
// optional int32 a = 17;
// }
Expand Down Expand Up @@ -114,7 +114,7 @@ message TestAllTypes {
repeated string repeated_string = 44;
repeated bytes repeated_bytes = 45;

// Groups are not allowed in proto3.
// Groups are not allowed in proto.
// repeated group RepeatedGroup = 46 {
// optional int32 a = 47;
// }
Expand Down
2 changes: 1 addition & 1 deletion enum.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion enum_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion field.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

// Field is an abstract message field.
type Field struct {
Expand Down
2 changes: 1 addition & 1 deletion field_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion import.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

// Import holds a filename to another .proto definition.
type Import struct {
Expand Down
2 changes: 1 addition & 1 deletion import_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion message.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

// Message consists of a message name and a message body.
type Message struct {
Expand Down
2 changes: 1 addition & 1 deletion message_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion oneof.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion oneof_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion option.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion option_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion package.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import (
"strings"
Expand Down
2 changes: 1 addition & 1 deletion proto.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import (
"log"
Expand Down
4 changes: 2 additions & 2 deletions proto_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package proto3
package proto

import "testing"

const example = `
syntax = “proto3”;
syntax = “proto”;
import public “other.proto”;
option java_package = "com.example.foo";
enum EnumAllowingAlias {
Expand Down
2 changes: 1 addition & 1 deletion reserved.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion reserved_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion scanner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto3
package proto

// partial code from https://raw.githubusercontent.com/benbjohnson/sql-parser/master/scanner.go

Expand Down
Loading

0 comments on commit f033c90

Please sign in to comment.