├── .gitignore ├── test ├── .gitignore ├── tags │ ├── doc.go │ ├── Makefile │ ├── tags.proto │ └── tags_test.go ├── packed │ ├── doc.go │ └── Makefile ├── embedconflict │ ├── .gitignore │ ├── doc.go │ ├── en.proto │ ├── ec.proto │ ├── er.proto │ ├── ee.proto │ └── em.proto ├── mixmatch │ └── doc.go ├── dashfilename │ ├── doc.go │ ├── dash-filename.proto │ └── df_test.go ├── defaultconflict │ ├── doc.go │ ├── nc.proto │ ├── dg.proto │ ├── ne.proto │ ├── nx.proto │ ├── df.proto │ └── nc_test.go ├── custom_types.go ├── issue8 │ ├── proto.proto │ ├── Makefile │ └── protopb_test.go ├── custom │ ├── custom.test.golden │ └── custom.proto ├── enumprefix │ ├── enumprefix.pb.go │ ├── Makefile │ └── enumprefix.proto ├── unmarshalmerge │ ├── unmarshalmerge_test.go │ ├── Makefile │ └── unmarshalmerge.proto ├── group │ ├── Makefile │ └── group.proto ├── Makefile ├── example │ ├── Makefile │ └── example.proto ├── moredefaults │ ├── Makefile │ ├── md.proto │ ├── md_test.go │ └── md.pb.go ├── enumstringer │ ├── Makefile │ ├── string.go │ └── enumstringer.proto ├── unrecognized │ ├── Makefile │ └── unrecognized.proto ├── unrecognizedgroup │ ├── Makefile │ └── unrecognizedgroup.proto └── mixbench │ ├── marshal.txt │ ├── marshaler.txt │ ├── unsafe_marshaler.txt │ ├── unmarshal.txt │ ├── unmarshaler.txt │ └── unsafe_unmarshaler.txt ├── protoc-gen-dgo ├── testdata │ ├── multi │ │ ├── .gitignore │ │ ├── multi3.proto │ │ ├── multi2.proto │ │ └── multi1.proto │ ├── imp3.proto │ ├── imp2.proto │ ├── extension_extra.proto │ ├── main_test.go │ ├── extension_base.proto │ ├── imp.proto │ ├── Makefile │ ├── golden_test.go │ ├── extension_user.proto │ ├── my_test │ │ └── test.proto │ └── imp.pb.go.golden ├── Makefile ├── descriptor │ └── Makefile ├── plugin │ ├── Makefile │ └── plugin.pb.golden └── doc.go ├── test_init.sh ├── contributors ├── gogoproto ├── gogo.pb.golden ├── Makefile └── gogo.proto ├── proto ├── lib_gogo.go ├── Makefile ├── testdata │ ├── Makefile │ └── golden_test.go ├── text_gogo.go ├── extensions_test.go ├── size2_test.go └── skip_gogo.go ├── parser ├── parse_test.go └── parse.go ├── license.txt ├── io ├── io.go ├── full.go └── uint32.go ├── plugin ├── description │ └── descriptiontest.go ├── stringer │ └── stringertest.go ├── union │ └── uniontest.go ├── equal │ └── equaltest.go └── enumstringer │ └── enumstringer.go ├── README.md └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | test_config 2 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | *.dat 2 | -------------------------------------------------------------------------------- /test/tags/doc.go: -------------------------------------------------------------------------------- 1 | package tags 2 | -------------------------------------------------------------------------------- /test/packed/doc.go: -------------------------------------------------------------------------------- 1 | package packed 2 | -------------------------------------------------------------------------------- /test/embedconflict/.gitignore: -------------------------------------------------------------------------------- 1 | *.pb.go 2 | -------------------------------------------------------------------------------- /test/mixmatch/doc.go: -------------------------------------------------------------------------------- 1 | package mixmatch 2 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/multi/.gitignore: -------------------------------------------------------------------------------- 1 | *.pb.go 2 | -------------------------------------------------------------------------------- /test/dashfilename/doc.go: -------------------------------------------------------------------------------- 1 | package dashfilename 2 | -------------------------------------------------------------------------------- /test/defaultconflict/doc.go: -------------------------------------------------------------------------------- 1 | package defaultcheck 2 | -------------------------------------------------------------------------------- /test/embedconflict/doc.go: -------------------------------------------------------------------------------- 1 | package embedconflict 2 | -------------------------------------------------------------------------------- /test/custom_types.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | type Id int64 4 | type Weight float64 5 | type Truth bool 6 | type Sbring string 7 | type Obj []byte 8 | -------------------------------------------------------------------------------- /test/dashfilename/dash-filename.proto: -------------------------------------------------------------------------------- 1 | package dashfilename; 2 | 3 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 4 | 5 | option (gogoproto.marshaler_all) = true; 6 | 7 | message test { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /test_init.sh: -------------------------------------------------------------------------------- 1 | rm -rf test_config && mkdir test_config 2 | echo $'#!/bin/bash\n\n'export PROTO_PATH='"'.:$(pwd | sed "s/\/github\.com.*//g")'"' > test_config/config 3 | echo $'package config\n\n'const ProtoPath string = '"'.:$(pwd | sed "s/\/github\.com.*//g")'"' > test_config/config.go 4 | -------------------------------------------------------------------------------- /test/issue8/proto.proto: -------------------------------------------------------------------------------- 1 | package proto; 2 | 3 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 4 | 5 | option (gogoproto.unmarshaler_all) = true; 6 | option (gogoproto.testgen_all) = true; 7 | option (gogoproto.populate_all) = true; 8 | option (gogoproto.equal_all) = true; 9 | 10 | message Foo { 11 | required uint64 bar = 1; 12 | } 13 | -------------------------------------------------------------------------------- /contributors: -------------------------------------------------------------------------------- 1 | This is a list of contributors to the GoGo protobuf repository. 2 | 3 | # Names should be added to this file like so: 4 | # Name 5 | 6 | # Please keep the list sorted. 7 | 8 | Walter Schulze 9 | Andrei Antonescu 10 | 11 | The contributors to the Go protobuf repository: 12 | 13 | # This source code was written by the Go contributors. 14 | # The master list of contributors is in the main Go distribution, 15 | # visible at http://tip.golang.org/CONTRIBUTORS. 16 | -------------------------------------------------------------------------------- /test/dashfilename/df_test.go: -------------------------------------------------------------------------------- 1 | package dashfilename 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | "testing" 7 | 8 | "github.com/dropbox/goprotoc/test_config" 9 | ) 10 | 11 | //Issue 16 : https://code.google.com/p/gogoprotobuf/issues/detail?id=16 12 | func TestDashFilename(t *testing.T) { 13 | name := "dash-filename" 14 | cmd := exec.Command("protoc", "--dgo_out=.", "-I="+config.ProtoPath, name+".proto") 15 | data, err := cmd.CombinedOutput() 16 | if err != nil { 17 | t.Fatalf("err = %v: %s", err, string(data)) 18 | } 19 | if err := os.Remove(name + ".pb.go"); err != nil { 20 | panic(err) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/custom/custom.test.golden: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | math_rand "math/rand" 7 | 8 | "github.com/dropbox/goprotoc/proto" 9 | ) 10 | 11 | func TestCustom(t *testing.T) { 12 | popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 13 | p := NewPopulatedMessageCustom(popr, false) 14 | data, err := proto.Marshal(p) 15 | if err != nil { 16 | panic(err) 17 | } 18 | msg := &MessageCustom{} 19 | if err := proto.Unmarshal(data, msg); err != nil { 20 | panic(err) 21 | } 22 | for i := range data { 23 | data[i] = byte(popr.Intn(256)) 24 | } 25 | if err := p.VerboseEqual(msg); err != nil { 26 | t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err) 27 | } 28 | if !p.Equal(msg) { 29 | t.Fatalf("%#v !Proto %#v", msg, p) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/enumprefix/enumprefix.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-dgo. 2 | // source: enumprefix.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package enumprefix is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | enumprefix.proto 10 | 11 | It has these top-level messages: 12 | MyMessage 13 | */ 14 | package enumprefix 15 | 16 | import proto "github.com/dropbox/goprotoc/proto" 17 | import math "math" 18 | import test "github.com/dropbox/goprotoc/test" 19 | 20 | // discarding unused import gogoproto "github.com/dropbox/goprotoc/gogoproto/gogo.pb" 21 | 22 | // Reference imports to suppress errors if they are not otherwise used. 23 | var _ = proto.Marshal 24 | var _ = math.Inf 25 | 26 | type MyMessage struct { 27 | TheField test.TheTestEnum `protobuf:"varint,1,opt,enum=test.TheTestEnum" json:"TheField"` 28 | XXX_unrecognized []byte `json:"-"` 29 | } 30 | 31 | func (m *MyMessage) Reset() { *m = MyMessage{} } 32 | func (m *MyMessage) String() string { return proto.CompactTextString(m) } 33 | func (*MyMessage) ProtoMessage() {} 34 | 35 | func (m *MyMessage) GetTheField() test.TheTestEnum { 36 | if m != nil { 37 | return m.TheField 38 | } 39 | return test.A 40 | } 41 | 42 | func init() { 43 | } 44 | -------------------------------------------------------------------------------- /test/custom/custom.proto: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 4 | 5 | option (gogoproto.populate_all) = true; 6 | option (gogoproto.equal_all) = true; 7 | option (gogoproto.verbose_equal_all) = true; 8 | option (gogoproto.stringer_all) = true; 9 | 10 | message MessageCustom { 11 | optional int64 field1 = 1 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Id"]; 12 | optional double field2 = 2 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Weight"]; 13 | optional bool field3 = 3 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Truth"]; 14 | optional string field4 = 4 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Sbring"]; 15 | optional bytes field5 = 5 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Obj"]; 16 | 17 | repeated int64 field11 = 11 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Id"]; 18 | repeated double field12 = 12 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Weight"]; 19 | repeated bool field13 = 13 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Truth"]; 20 | repeated string field14 = 14 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Sbring"]; 21 | repeated bytes field15 = 15 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Obj"]; 22 | } 23 | -------------------------------------------------------------------------------- /test/unmarshalmerge/unmarshalmerge_test.go: -------------------------------------------------------------------------------- 1 | package unmarshalmerge 2 | 3 | import ( 4 | "github.com/dropbox/goprotoc/proto" 5 | math_rand "math/rand" 6 | "testing" 7 | "time" 8 | ) 9 | 10 | func TestUnmarshalMerge(t *testing.T) { 11 | popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 12 | p := NewPopulatedBig(popr, true) 13 | if p.GetSub() == nil { 14 | p.Sub = &Sub{SubNumber: proto.Int64(12345)} 15 | } 16 | data, err := proto.Marshal(p) 17 | if err != nil { 18 | panic(err) 19 | } 20 | s := &Sub{} 21 | b := &Big{ 22 | Sub: s, 23 | } 24 | err = proto.UnmarshalMerge(data, b) 25 | if err != nil { 26 | panic(err) 27 | } 28 | if s.GetSubNumber() != p.GetSub().GetSubNumber() { 29 | t.Fatalf("should have unmarshaled subnumber into sub") 30 | } 31 | } 32 | 33 | func TestUnsafeUnmarshalMerge(t *testing.T) { 34 | popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 35 | p := NewPopulatedBigUnsafe(popr, true) 36 | if p.GetSub() == nil { 37 | p.Sub = &Sub{SubNumber: proto.Int64(12345)} 38 | } 39 | data, err := proto.Marshal(p) 40 | if err != nil { 41 | panic(err) 42 | } 43 | s := &Sub{} 44 | b := &BigUnsafe{ 45 | Sub: s, 46 | } 47 | err = proto.UnmarshalMerge(data, b) 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | if s.GetSubNumber() != p.GetSub().GetSubNumber() { 53 | t.Fatalf("should have unmarshaled subnumber into sub") 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gogoproto/gogo.pb.golden: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: gogo.proto 3 | // DO NOT EDIT! 4 | 5 | package gogoproto 6 | 7 | import proto "code.google.com/p/gogoprotobuf/proto" 8 | import json "encoding/json" 9 | import math "math" 10 | import google_protobuf "code.google.com/p/gogoprotobuf/protoc-gen-dgo/descriptor" 11 | 12 | // Reference proto, json, and math imports to suppress error if they are not otherwise used. 13 | var _ = proto.Marshal 14 | var _ = &json.SyntaxError{} 15 | var _ = math.Inf 16 | 17 | var E_Nullable = &proto.ExtensionDesc{ 18 | ExtendedType: (*google_protobuf.FieldOptions)(nil), 19 | ExtensionType: (*bool)(nil), 20 | Field: 51235, 21 | Name: "gogoproto.nullable", 22 | Tag: "varint,51235,opt,name=nullable", 23 | } 24 | 25 | var E_Embed = &proto.ExtensionDesc{ 26 | ExtendedType: (*google_protobuf.FieldOptions)(nil), 27 | ExtensionType: (*bool)(nil), 28 | Field: 51236, 29 | Name: "gogoproto.embed", 30 | Tag: "varint,51236,opt,name=embed", 31 | } 32 | 33 | var E_Customtype = &proto.ExtensionDesc{ 34 | ExtendedType: (*google_protobuf.FieldOptions)(nil), 35 | ExtensionType: (*string)(nil), 36 | Field: 51237, 37 | Name: "gogoproto.customtype", 38 | Tag: "bytes,51237,opt,name=customtype", 39 | } 40 | 41 | func init() { 42 | proto.RegisterExtension(E_Nullable) 43 | proto.RegisterExtension(E_Embed) 44 | proto.RegisterExtension(E_Customtype) 45 | } 46 | -------------------------------------------------------------------------------- /test/group/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. group.proto) 33 | -------------------------------------------------------------------------------- /test/tags/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. tags.proto) 33 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf/gogoproto 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. thetest.proto) 33 | -------------------------------------------------------------------------------- /test/example/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. example.proto) 33 | -------------------------------------------------------------------------------- /test/issue8/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. proto.proto) 33 | -------------------------------------------------------------------------------- /test/moredefaults/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. md.proto) 33 | -------------------------------------------------------------------------------- /test/packed/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. packed.proto) 33 | -------------------------------------------------------------------------------- /test/enumprefix/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. enumprefix.proto) 33 | -------------------------------------------------------------------------------- /test/enumstringer/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. enumstringer.proto) 33 | -------------------------------------------------------------------------------- /test/unrecognized/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. unrecognized.proto) 33 | -------------------------------------------------------------------------------- /test/unmarshalmerge/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. unmarshalmerge.proto) 33 | -------------------------------------------------------------------------------- /test/unrecognizedgroup/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../../test_config/config 30 | 31 | regenerate: 32 | (protoc --proto_path=$(PROTO_PATH) --dgo_out=. unrecognizedgroup.proto) 33 | -------------------------------------------------------------------------------- /test/defaultconflict/nc.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package defaultcheck; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | message A { 32 | optional int64 Field1 = 1 [default = 1234, (gogoproto.nullable) = false];; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /test/enumstringer/string.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package enumstringer 28 | 29 | func (this TheTestEnum) String() string { 30 | switch this { 31 | case 0: 32 | return "a" 33 | case 1: 34 | return "blabla" 35 | case 2: 36 | return "z" 37 | } 38 | return "3" 39 | } 40 | -------------------------------------------------------------------------------- /test/defaultconflict/dg.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package defaultcheck; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.goproto_getters_all) = false; 32 | 33 | message A { 34 | optional int64 Field1 = 1 [default=1234]; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /test/defaultconflict/ne.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package defaultcheck; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | enum E { 32 | P = 10; 33 | Q = 11; 34 | } 35 | 36 | message A { 37 | optional E Field1 = 1 [(gogoproto.nullable) = false]; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /test/defaultconflict/nx.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package defaultcheck; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | message A { 32 | extensions 1 to max; 33 | } 34 | 35 | extend A { 36 | optional int64 Field1 = 1 [(gogoproto.nullable) = false]; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /test/embedconflict/en.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package embedconflict; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | message F { 32 | optional G G = 2 [(gogoproto.embed) = true, (gogoproto.customname) = "G"]; 33 | } 34 | 35 | message G { 36 | optional int64 Field1 = 1; 37 | } 38 | -------------------------------------------------------------------------------- /gogoproto/Makefile: -------------------------------------------------------------------------------- 1 | # Extensions for Protocol Buffers to create more go like structures. 2 | # 3 | # Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | # http://code.google.com/p/gogoprotobuf/gogoproto 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | include ../test_config/config 30 | 31 | regenerate: 32 | protoc --dgo_out=. --proto_path=$(PROTO_PATH) *.proto 33 | 34 | restore: 35 | cp gogo.pb.golden gogo.pb.go 36 | 37 | preserve: 38 | cp gogo.pb.go gogo.pb.golden 39 | -------------------------------------------------------------------------------- /proto/lib_gogo.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package proto 28 | 29 | import ( 30 | "encoding/json" 31 | "strconv" 32 | ) 33 | 34 | func MarshalJSONEnum(m map[int32]string, value int32) ([]byte, error) { 35 | s, ok := m[value] 36 | if !ok { 37 | s = strconv.Itoa(int(value)) 38 | } 39 | return json.Marshal(s) 40 | } 41 | -------------------------------------------------------------------------------- /protoc-gen-dgo/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | test: 33 | cd testdata && make test 34 | -------------------------------------------------------------------------------- /test/embedconflict/ec.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package embedconflict; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | message A { 32 | optional int64 Field1 = 1; 33 | optional B B = 2 [(gogoproto.embed) = true]; 34 | } 35 | 36 | message B { 37 | optional double Field1 = 1; 38 | } 39 | -------------------------------------------------------------------------------- /test/embedconflict/er.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package embedconflict; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | message A { 32 | optional int64 Field1 = 1; 33 | repeated B B = 2 [(gogoproto.embed) = true]; 34 | } 35 | 36 | message B { 37 | optional double Field2 = 2; 38 | } 39 | -------------------------------------------------------------------------------- /test/enumprefix/enumprefix.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package enumprefix; 28 | 29 | import "github.com/dropbox/goprotoc/test/thetest.proto"; 30 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 31 | 32 | message MyMessage { 33 | optional test.TheTestEnum TheField = 1 [(gogoproto.nullable) = false]; 34 | } 35 | -------------------------------------------------------------------------------- /test/defaultconflict/df.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package defaultcheck; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.face_all) = true; 32 | option (gogoproto.goproto_getters_all) = false; 33 | 34 | message A { 35 | optional int64 Field1 = 1 [default=1234]; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /test/embedconflict/ee.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package embedconflict; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | message E { 32 | optional int64 Field1 = 1; 33 | extensions 100 to 199; 34 | } 35 | 36 | extend E { 37 | optional int64 Field1 = 100 [(gogoproto.embed) = true]; 38 | } 39 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/imp3.proto: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2012 The Go Authors. All rights reserved. 3 | // http://code.google.com/p/goprotobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package imp; 32 | 33 | message ForeignImportedMessage { 34 | optional string tuber = 1; 35 | } 36 | -------------------------------------------------------------------------------- /parser/parse_test.go: -------------------------------------------------------------------------------- 1 | // Extensions for Protocol Buffers to create more go like structures. 2 | // 3 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | // http://code.google.com/p/gogoprotobuf/gogoproto 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package parser 30 | 31 | import ( 32 | "testing" 33 | ) 34 | 35 | func TestParse(t *testing.T) { 36 | _, err := ParseFile("../protobuf/google/protobuf/descriptor.proto", "../protobuf/") 37 | if err != nil { 38 | panic(err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/imp2.proto: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // http://code.google.com/p/goprotobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package imp; 32 | 33 | message PubliclyImportedMessage { 34 | optional int64 field = 1; 35 | } 36 | 37 | enum PubliclyImportedEnum { 38 | GLASSES = 1; 39 | HAIR = 2; 40 | } 41 | -------------------------------------------------------------------------------- /proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install && cd testdata && make 41 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/extension_extra.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2011 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package extension_extra; 35 | 36 | message ExtraMessage { 37 | optional int32 width = 1; 38 | } 39 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Extended version of gogoprotobuf optimized for speed and full api support. 2 | 3 | Copyright (c) 2014 Dropbox, Inc 4 | All rights reserved. 5 | 6 | Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 7 | http://code.google.com/p/gogoprotobuf/gogoproto 8 | 9 | Go support for Protocol Buffers - Google's data interchange format 10 | 11 | Copyright 2010 The Go Authors. All rights reserved. 12 | http://code.google.com/p/goprotobuf/ 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, this 18 | list of conditions and the following disclaimer. 19 | 20 | 2. Redistributions in binary form must reproduce the above copyright notice, 21 | this list of conditions and the following disclaimer in the documentation 22 | and/or other materials provided with the distribution. 23 | 24 | 3. Neither the name of the copyright holder nor the names of its contributors 25 | may be used to endorse or promote products derived from this software without 26 | specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 29 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/multi/multi3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package multi; 33 | 34 | message Multi3 { 35 | enum HatType { 36 | FEDORA = 1; 37 | FEZ = 2; 38 | }; 39 | optional HatType hat_type = 1; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /test/embedconflict/em.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package embedconflict; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.marshaler_all) = false; 32 | option (gogoproto.sizer_all) = false; 33 | option (gogoproto.unmarshaler_all) = false; 34 | 35 | message C { 36 | optional int64 Field1 = 1; 37 | optional D D = 2 [(gogoproto.embed) = true]; 38 | } 39 | 40 | message D { 41 | option (gogoproto.marshaler) = true; 42 | optional double Field2 = 2; 43 | } 44 | -------------------------------------------------------------------------------- /protoc-gen-dgo/descriptor/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | regenerate: 33 | protoc --dgo_out=. -I=../../protobuf/google/protobuf ../../protobuf/google/protobuf/descriptor.proto 34 | 35 | restore: 36 | cp descriptor.pb.golden descriptor.pb.go 37 | 38 | preserve: 39 | cp descriptor.pb.go descriptor.pb.golden 40 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/multi/multi2.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package multi; 33 | 34 | message Multi2 { 35 | required int32 required_value = 1; 36 | 37 | enum Color { 38 | BLUE = 1; 39 | GREEN = 2; 40 | RED = 3; 41 | }; 42 | optional Color color = 2; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /test/tags/tags.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package tags; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.populate_all) = true; 32 | 33 | message Outside { 34 | optional Inside Inside = 1 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""]; 35 | optional string Field2 = 2 [(gogoproto.jsontag) = "MyField2", (gogoproto.moretags) = "xml:\",comment\""]; 36 | } 37 | 38 | message Inside { 39 | optional string Field1 = 1 [(gogoproto.jsontag) = "MyField1", (gogoproto.moretags) = "xml:\",chardata\""]; 40 | } 41 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/multi/multi1.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | import "multi/multi2.proto"; 33 | import "multi/multi3.proto"; 34 | 35 | package multi; 36 | 37 | message Multi1 { 38 | required Multi2 multi2 = 1; 39 | optional Multi2.Color color = 2; 40 | optional Multi3.HatType hat_type = 3; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/main_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // A simple binary to link together the protocol buffers in this test. 33 | 34 | package testdata 35 | 36 | import ( 37 | "testing" 38 | 39 | "./multi" 40 | "./my_test" 41 | ) 42 | 43 | func TestLink(t *testing.T) { 44 | _ = &multi.Multi1{} 45 | _ = &my_test.Request{} 46 | } 47 | -------------------------------------------------------------------------------- /io/io.go: -------------------------------------------------------------------------------- 1 | // Extensions for Protocol Buffers to create more go like structures. 2 | // 3 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | // http://code.google.com/p/gogoprotobuf/gogoproto 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package io 30 | 31 | import ( 32 | "github.com/dropbox/goprotoc/proto" 33 | "io" 34 | ) 35 | 36 | type Writer interface { 37 | WriteMsg(proto.Message) error 38 | } 39 | 40 | type WriteCloser interface { 41 | Writer 42 | io.Closer 43 | } 44 | 45 | type Reader interface { 46 | ReadMsg(msg proto.Message) error 47 | } 48 | 49 | type ReadCloser interface { 50 | Reader 51 | io.Closer 52 | } 53 | 54 | type marshaler interface { 55 | MarshalTo(data []byte) (n int, err error) 56 | Size() (n int) 57 | } 58 | -------------------------------------------------------------------------------- /proto/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | all: regenerate 33 | 34 | regenerate: 35 | rm -f test.pb.go 36 | protoc --go_out=. test.proto 37 | 38 | # The following rules are just aids to development. Not needed for typical testing. 39 | 40 | diff: regenerate 41 | hg diff test.pb.go 42 | 43 | restore: 44 | cp test.pb.go.golden test.pb.go 45 | 46 | preserve: 47 | cp test.pb.go test.pb.go.golden 48 | -------------------------------------------------------------------------------- /proto/text_gogo.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package proto 28 | 29 | import ( 30 | "fmt" 31 | "reflect" 32 | ) 33 | 34 | func writeEnum(w *textWriter, v reflect.Value, props *Properties) error { 35 | m, ok := enumStringMaps[props.Enum] 36 | if !ok { 37 | if err := writeAny(w, v, props); err != nil { 38 | return err 39 | } 40 | } 41 | key := int32(0) 42 | if v.Kind() == reflect.Ptr { 43 | key = int32(v.Elem().Int()) 44 | } else { 45 | key = int32(v.Int()) 46 | } 47 | s, ok := m[key] 48 | if !ok { 49 | if err := writeAny(w, v, props); err != nil { 50 | return err 51 | } 52 | } 53 | _, err := fmt.Fprint(w, s) 54 | return err 55 | } 56 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/extension_base.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package extension_base; 33 | 34 | message BaseMessage { 35 | optional int32 height = 1; 36 | extensions 4 to 9; 37 | extensions 16 to max; 38 | } 39 | 40 | // Another message that may be extended, using message_set_wire_format. 41 | message OldStyleMessage { 42 | option message_set_wire_format = true; 43 | extensions 100 to max; 44 | } 45 | -------------------------------------------------------------------------------- /test/moredefaults/md.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package moredefaults; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | import "github.com/dropbox/goprotoc/test/example/example.proto"; 31 | 32 | option (gogoproto.goproto_getters_all) = true; 33 | 34 | message MoreDefaultsB { 35 | optional string Field1 = 1; 36 | } 37 | 38 | message MoreDefaultsA { 39 | optional int64 Field1 = 1 [default=1234]; 40 | optional int64 Field2 = 2 [(gogoproto.nullable) = false]; 41 | optional MoreDefaultsB B1 = 3; 42 | optional MoreDefaultsB B2 = 4 [(gogoproto.nullable) = false]; 43 | optional test.A A1 = 5; 44 | optional test.A A2 = 6 [(gogoproto.nullable) = false]; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /protoc-gen-dgo/plugin/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Not stored here, but plugin.proto is in http://code.google.com/p/protobuf 33 | # at protobuf-2.3.0/src/google/protobuf/compiler/plugin.proto 34 | # Also we need to fix an import. 35 | regenerate: 36 | protoc --dgo_out=. -I=../../protobuf/google/protobuf/compiler/:../../protobuf/ ../../protobuf/google/protobuf/compiler/plugin.proto 37 | 38 | restore: 39 | cp plugin.pb.golden plugin.pb.go 40 | 41 | preserve: 42 | cp plugin.pb.go plugin.pb.golden 43 | -------------------------------------------------------------------------------- /test/moredefaults/md_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package moredefaults 28 | 29 | import ( 30 | "testing" 31 | 32 | test "github.com/dropbox/goprotoc/test/example" 33 | ) 34 | 35 | func TestDefaults(t *testing.T) { 36 | b := MoreDefaultsB{} 37 | aa := test.A{} 38 | a := &MoreDefaultsA{} 39 | b2 := a.GetB2() 40 | a2 := a.GetA2() 41 | if a.GetField1() != 1234 { 42 | t.Fatalf("Field1 wrong") 43 | } 44 | if a.GetField2() != 0 { 45 | t.Fatalf("Field2 wrong") 46 | } 47 | if a.GetB1() != nil { 48 | t.Fatalf("B1 wrong") 49 | } 50 | if b2.GetField1() != b.GetField1() { 51 | t.Fatalf("B2 wrong") 52 | } 53 | if a.GetA1() != nil { 54 | t.Fatalf("A1 wrong") 55 | } 56 | if a2.GetNumber() != aa.GetNumber() { 57 | t.Fatalf("A2 wrong") 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/enumstringer/enumstringer.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package enumstringer; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.goproto_enum_stringer_all) = false; 32 | 33 | option (gogoproto.equal_all) = true; 34 | option (gogoproto.verbose_equal_all) = true; 35 | 36 | option (gogoproto.testgen_all) = true; 37 | option (gogoproto.populate_all) = true; 38 | 39 | enum TheTestEnum { 40 | A = 0; 41 | B = 1; 42 | C = 2; 43 | } 44 | 45 | message NidOptEnum { 46 | optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; 47 | } 48 | 49 | message NinOptEnum { 50 | optional TheTestEnum Field1 = 1; 51 | } 52 | 53 | message NidRepEnum { 54 | repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; 55 | } 56 | 57 | message NinRepEnum { 58 | repeated TheTestEnum Field1 = 1; 59 | } 60 | -------------------------------------------------------------------------------- /test/unmarshalmerge/unmarshalmerge.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package unmarshalmerge; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.equal_all) = true; 32 | option (gogoproto.verbose_equal_all) = true; 33 | option (gogoproto.stringer_all) = true; 34 | option (gogoproto.gostring_all) = true; 35 | option (gogoproto.goproto_stringer_all) = false; 36 | 37 | option (gogoproto.testgen_all) = true; 38 | option (gogoproto.populate_all) = true; 39 | option (gogoproto.benchgen_all) = true; 40 | 41 | message Big { 42 | option (gogoproto.unmarshaler) = true; 43 | optional Sub Sub = 1; 44 | optional int64 Number = 2; 45 | } 46 | 47 | message BigUnsafe { 48 | option (gogoproto.unsafe_unmarshaler) = true; 49 | optional Sub Sub = 1; 50 | optional int64 Number = 2; 51 | } 52 | 53 | message Sub { 54 | option (gogoproto.unmarshaler) = true; 55 | optional int64 SubNumber = 1; 56 | } -------------------------------------------------------------------------------- /test/defaultconflict/nc_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package defaultcheck 28 | 29 | import ( 30 | "os" 31 | "os/exec" 32 | "testing" 33 | ) 34 | 35 | func testDefaultConflict(t *testing.T, name string) { 36 | cmd := exec.Command("protoc", "--dgo_out=.", name+".proto") 37 | data, err := cmd.CombinedOutput() 38 | if err == nil { 39 | t.Errorf("Expected error") 40 | if err := os.Remove(name + ".pb.go"); err != nil { 41 | panic(err) 42 | } 43 | } 44 | t.Logf("received expected error = %v and output = %v", err, string(data)) 45 | } 46 | 47 | func TestNullableDefault(t *testing.T) { 48 | testDefaultConflict(t, "nc") 49 | } 50 | 51 | func TestNullableExtension(t *testing.T) { 52 | testDefaultConflict(t, "nx") 53 | } 54 | 55 | func TestNullableEnum(t *testing.T) { 56 | testDefaultConflict(t, "ne") 57 | } 58 | 59 | func TestFaceDefault(t *testing.T) { 60 | testDefaultConflict(t, "df") 61 | } 62 | 63 | func TestNoGettersDefault(t *testing.T) { 64 | testDefaultConflict(t, "dg") 65 | } 66 | -------------------------------------------------------------------------------- /test/group/group.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package group; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.goproto_stringer_all) = false; 32 | option (gogoproto.goproto_enum_prefix_all) = false; 33 | option (gogoproto.goproto_getters_all) = false; 34 | 35 | option (gogoproto.equal_all) = true; 36 | option (gogoproto.verbose_equal_all) = true; 37 | option (gogoproto.stringer_all) = true; 38 | option (gogoproto.gostring_all) = true; 39 | option (gogoproto.description_all) = true; 40 | 41 | option (gogoproto.testgen_all) = true; 42 | option (gogoproto.populate_all) = true; 43 | 44 | option (gogoproto.unmarshaler_all) = false; 45 | option (gogoproto.marshaler_all) = false; 46 | option (gogoproto.sizer_all) = false; 47 | 48 | message Groups1 { 49 | repeated group G = 1 { 50 | optional int64 Field1 = 1; 51 | optional double Field2 = 2; 52 | } 53 | } 54 | 55 | message Groups2 { 56 | optional group G = 1 { 57 | optional int64 Field1 = 1; 58 | repeated double Field2 = 2; 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/imp.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package imp; 33 | 34 | import "imp2.proto"; 35 | import "imp3.proto"; 36 | 37 | message ImportedMessage { 38 | required int64 field = 1; 39 | 40 | // The forwarded getters for these fields are fiddly to get right. 41 | optional ImportedMessage2 local_msg = 2; 42 | optional ForeignImportedMessage foreign_msg = 3; // in imp3.proto 43 | optional Owner enum_field = 4; 44 | 45 | repeated string name = 5; 46 | repeated Owner boss = 6; 47 | repeated ImportedMessage2 memo = 7; 48 | 49 | enum Owner { 50 | DAVE = 1; 51 | MIKE = 2; 52 | } 53 | 54 | extensions 90 to 100; 55 | } 56 | 57 | message ImportedMessage2 { 58 | } 59 | 60 | message ImportedExtendable { 61 | option message_set_wire_format = true; 62 | extensions 100 to max; 63 | } 64 | -------------------------------------------------------------------------------- /proto/extensions_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto_test 33 | 34 | import ( 35 | "testing" 36 | 37 | pb "./testdata" 38 | "github.com/dropbox/goprotoc/proto" 39 | ) 40 | 41 | func TestGetExtensionsWithMissingExtensions(t *testing.T) { 42 | msg := &pb.MyMessage{} 43 | ext1 := &pb.Ext{} 44 | if err := proto.SetExtension(msg, pb.E_Ext_More, ext1); err != nil { 45 | t.Fatalf("Could not set ext1: %s", ext1) 46 | } 47 | exts, err := proto.GetExtensions(msg, []*proto.ExtensionDesc{ 48 | pb.E_Ext_More, 49 | pb.E_Ext_Text, 50 | }) 51 | if err != nil { 52 | t.Fatalf("GetExtensions() failed: %s", err) 53 | } 54 | if exts[0] != ext1 { 55 | t.Errorf("ext1 not in returned extensions: %T %v", exts[0], exts[0]) 56 | } 57 | if exts[1] != nil { 58 | t.Errorf("ext2 in returned extensions: %T %v", exts[1], exts[1]) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /proto/size2_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto 33 | 34 | import ( 35 | "testing" 36 | ) 37 | 38 | // This is a separate file and package from size_test.go because that one uses 39 | // generated messages and thus may not be in package proto without having a circular 40 | // dependency, whereas this file tests unexported details of size.go. 41 | 42 | func TestVarintSize(t *testing.T) { 43 | // Check the edge cases carefully. 44 | testCases := []struct { 45 | n uint64 46 | size int 47 | }{ 48 | {0, 1}, 49 | {1, 1}, 50 | {127, 1}, 51 | {128, 2}, 52 | {16383, 2}, 53 | {16384, 3}, 54 | {1<<63 - 1, 9}, 55 | {1 << 63, 10}, 56 | } 57 | for _, tc := range testCases { 58 | size := sizeVarint(tc.n) 59 | if size != tc.size { 60 | t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /protoc-gen-dgo/doc.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | /* 33 | A plugin for the Google protocol buffer compiler to generate Go code. 34 | Run it by building this program and putting it in your path with the name 35 | protoc-gen-dgo 36 | That word 'gogo' at the end becomes part of the option string set for the 37 | protocol compiler, so once the protocol compiler (protoc) is installed 38 | you can run 39 | protoc --dgo_out=output_directory input_directory/file.proto 40 | to generate Go bindings for the protocol defined by file.proto. 41 | With that input, the output will be written to 42 | output_directory/go_package/file.pb.go 43 | 44 | The generated code is documented in the package comment for 45 | the library. 46 | 47 | See the README and documentation for protocol buffers to learn more: 48 | http://code.google.com/p/protobuf/ 49 | 50 | */ 51 | package documentation 52 | -------------------------------------------------------------------------------- /plugin/description/descriptiontest.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package description 28 | 29 | import ( 30 | "github.com/dropbox/goprotoc/gogoproto" 31 | "github.com/dropbox/goprotoc/plugin/testgen" 32 | "github.com/dropbox/goprotoc/protoc-gen-dgo/generator" 33 | ) 34 | 35 | type test struct { 36 | *generator.Generator 37 | } 38 | 39 | func NewTest(g *generator.Generator) testgen.TestPlugin { 40 | return &test{g} 41 | } 42 | 43 | func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool { 44 | used := false 45 | testingPkg := imports.NewImport("testing") 46 | for _, message := range file.Messages() { 47 | if !gogoproto.HasDescription(file.FileDescriptorProto, message.DescriptorProto) || 48 | !gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) { 49 | continue 50 | } 51 | used = true 52 | } 53 | 54 | if used { 55 | localName := generator.FileName(file) 56 | p.P(`func Test`, localName, `Description(t *`, testingPkg.Use(), `.T) {`) 57 | p.In() 58 | p.P(localName, `Description()`) 59 | p.Out() 60 | p.P(`}`) 61 | 62 | } 63 | return used 64 | } 65 | 66 | func init() { 67 | testgen.RegisterTestPlugin(NewTest) 68 | } 69 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | all: 33 | @echo run make test 34 | 35 | test: golden testbuild 36 | 37 | #test: golden testbuild extension_test 38 | # ./extension_test 39 | # @echo PASS 40 | 41 | golden: 42 | protoc --dgo_out=. ./my_test/test.proto 43 | diff -w my_test/test.pb.go my_test/test.pb.go.golden 44 | 45 | nuke: clean 46 | 47 | testbuild: buildprotos 48 | go test 49 | 50 | buildprotos: 51 | # Invoke protoc once to generate three independent .pb.go files in the same package. 52 | protoc --dgo_out=. multi/multi{1,2,3}.proto 53 | 54 | #extension_test: extension_test.$O 55 | # $(LD) -L. -o $@ $< 56 | 57 | #multi.a: multi3.pb.$O multi2.pb.$O multi1.pb.$O 58 | # rm -f multi.a 59 | # $(QUOTED_GOBIN)/gopack grc $@ $< 60 | 61 | #test.pb.go: imp.pb.go 62 | #multi1.pb.go: multi2.pb.go multi3.pb.go 63 | #main.$O: imp.pb.$O test.pb.$O multi.a 64 | #extension_test.$O: extension_base.pb.$O extension_extra.pb.$O extension_user.pb.$O 65 | -------------------------------------------------------------------------------- /test/issue8/protopb_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-dgo. 2 | // source: proto.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package proto is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | proto.proto 10 | 11 | It has these top-level messages: 12 | Foo 13 | */ 14 | package proto 15 | 16 | import testing "testing" 17 | import math_rand "math/rand" 18 | import time "time" 19 | import dropbox_gogoprotobuf_proto "github.com/dropbox/goprotoc/proto" 20 | import testing1 "testing" 21 | import math_rand1 "math/rand" 22 | import time1 "time" 23 | import encoding_json "encoding/json" 24 | import testing2 "testing" 25 | import math_rand2 "math/rand" 26 | import time2 "time" 27 | import dropbox_gogoprotobuf_proto1 "github.com/dropbox/goprotoc/proto" 28 | 29 | func TestFooProto(t *testing.T) { 30 | popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 31 | p := NewPopulatedFoo(popr, false) 32 | data, err := dropbox_gogoprotobuf_proto.Marshal(p) 33 | if err != nil { 34 | panic(err) 35 | } 36 | msg := &Foo{} 37 | if err := dropbox_gogoprotobuf_proto.Unmarshal(data, msg); err != nil { 38 | panic(err) 39 | } 40 | for i := range data { 41 | data[i] = byte(popr.Intn(256)) 42 | } 43 | if !p.Equal(msg) { 44 | t.Fatalf("%#v !Proto %#v", msg, p) 45 | } 46 | } 47 | 48 | func TestFooJSON(t *testing1.T) { 49 | popr := math_rand1.New(math_rand1.NewSource(time1.Now().UnixNano())) 50 | p := NewPopulatedFoo(popr, true) 51 | jsondata, err := encoding_json.Marshal(p) 52 | if err != nil { 53 | panic(err) 54 | } 55 | msg := &Foo{} 56 | err = encoding_json.Unmarshal(jsondata, msg) 57 | if err != nil { 58 | panic(err) 59 | } 60 | if !p.Equal(msg) { 61 | t.Fatalf("%#v !Json Equal %#v", msg, p) 62 | } 63 | } 64 | func TestFooProtoText(t *testing2.T) { 65 | popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano())) 66 | p := NewPopulatedFoo(popr, true) 67 | data := dropbox_gogoprotobuf_proto1.MarshalTextString(p) 68 | msg := &Foo{} 69 | if err := dropbox_gogoprotobuf_proto1.UnmarshalText(data, msg); err != nil { 70 | panic(err) 71 | } 72 | if !p.Equal(msg) { 73 | t.Fatalf("%#v !Proto %#v", msg, p) 74 | } 75 | } 76 | 77 | func TestFooProtoCompactText(t *testing2.T) { 78 | popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano())) 79 | p := NewPopulatedFoo(popr, true) 80 | data := dropbox_gogoprotobuf_proto1.CompactTextString(p) 81 | msg := &Foo{} 82 | if err := dropbox_gogoprotobuf_proto1.UnmarshalText(data, msg); err != nil { 83 | panic(err) 84 | } 85 | if !p.Equal(msg) { 86 | t.Fatalf("%#v !Proto %#v", msg, p) 87 | } 88 | } 89 | 90 | //These tests are generated by code.google.com/p/gogoprotobuf/plugin/testgen 91 | -------------------------------------------------------------------------------- /test/example/example.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package test; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.gostring_all) = true; 32 | option (gogoproto.equal_all) = true; 33 | option (gogoproto.verbose_equal_all) = true; 34 | option (gogoproto.populate_all) = true; 35 | option (gogoproto.testgen_all) = true; 36 | option (gogoproto.benchgen_all) = true; 37 | option (gogoproto.sizer_all) = true; 38 | 39 | message A { 40 | option (gogoproto.face) = true; 41 | option (gogoproto.goproto_getters) = false; 42 | optional string Description = 1 [(gogoproto.nullable) = false]; 43 | optional int64 Number = 2 [(gogoproto.nullable) = false]; 44 | optional int64 Id = 3 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Id", (gogoproto.nullable) = false]; 45 | } 46 | 47 | message B { 48 | option (gogoproto.description) = true; 49 | optional A A = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; 50 | repeated int64 G = 2 [(gogoproto.customtype) = "github.com/dropbox/goprotoc/test.Id", (gogoproto.nullable) = false]; 51 | } 52 | 53 | message C { 54 | optional int64 size = 1 [(gogoproto.customname) = "MySize"]; 55 | } 56 | 57 | message U { 58 | option (gogoproto.onlyone) = true; 59 | optional A A = 1; 60 | optional B B = 2; 61 | } 62 | 63 | message E { 64 | option (gogoproto.goproto_extensions_map) = false; 65 | extensions 1 to max; 66 | } 67 | -------------------------------------------------------------------------------- /parser/parse.go: -------------------------------------------------------------------------------- 1 | // Extensions for Protocol Buffers to create more go like structures. 2 | // 3 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | // http://code.google.com/p/gogoprotobuf/gogoproto 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package parser 30 | 31 | import ( 32 | "github.com/dropbox/goprotoc/proto" 33 | descriptor "github.com/dropbox/goprotoc/protoc-gen-dgo/descriptor" 34 | "os/exec" 35 | "strings" 36 | ) 37 | 38 | type errCmd struct { 39 | output []byte 40 | err error 41 | } 42 | 43 | func (this *errCmd) Error() string { 44 | return this.err.Error() + ":" + string(this.output) 45 | } 46 | 47 | func ParseFile(filename string, paths ...string) (*descriptor.FileDescriptorSet, error) { 48 | return parseFile(filename, false, true, paths...) 49 | } 50 | 51 | func parseFile(filename string, includeSourceInfo bool, includeImports bool, paths ...string) (*descriptor.FileDescriptorSet, error) { 52 | args := []string{"--proto_path=" + strings.Join(paths, ":")} 53 | if includeSourceInfo { 54 | args = append(args, "--include_source_info") 55 | } 56 | if includeImports { 57 | args = append(args, "--include_imports") 58 | } 59 | args = append(args, "--descriptor_set_out=/dev/stdout") 60 | args = append(args, filename) 61 | cmd := exec.Command("protoc", args...) 62 | data, err := cmd.CombinedOutput() 63 | if err != nil { 64 | return nil, &errCmd{data, err} 65 | } 66 | fileDesc := &descriptor.FileDescriptorSet{} 67 | if err := proto.Unmarshal(data, fileDesc); err != nil { 68 | return nil, err 69 | } 70 | return fileDesc, nil 71 | } 72 | -------------------------------------------------------------------------------- /test/unrecognizedgroup/unrecognizedgroup.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package unrecognizedgroup; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.goproto_stringer_all) = false; 32 | option (gogoproto.goproto_enum_prefix_all) = false; 33 | option (gogoproto.goproto_getters_all) = false; 34 | 35 | option (gogoproto.equal_all) = true; 36 | option (gogoproto.verbose_equal_all) = true; 37 | option (gogoproto.stringer_all) = true; 38 | option (gogoproto.gostring_all) = true; 39 | option (gogoproto.description_all) = true; 40 | 41 | option (gogoproto.testgen_all) = true; 42 | option (gogoproto.populate_all) = true; 43 | 44 | message NewNoGroup { 45 | option (gogoproto.unmarshaler) = true; 46 | option (gogoproto.marshaler) = true; 47 | option (gogoproto.sizer) = true; 48 | optional int64 Field1 = 1; 49 | repeated double Field3 = 3; 50 | optional A A = 5; 51 | } 52 | 53 | message A { 54 | option (gogoproto.unmarshaler) = true; 55 | option (gogoproto.marshaler) = true; 56 | option (gogoproto.sizer) = true; 57 | optional int64 AField = 1; 58 | } 59 | 60 | message OldWithGroup { 61 | optional int64 Field1 = 1; 62 | optional group Group1 = 2 { 63 | optional int64 Field1 = 1; 64 | optional int32 Field2 = 2; 65 | repeated double Field3 = 3; 66 | } 67 | repeated double Field3 = 3; 68 | optional group Group2 = 4 { 69 | optional int64 Field1 = 1; 70 | repeated double Field2 = 2; 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /test/moredefaults/md.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-dgo. 2 | // source: md.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package moredefaults is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | md.proto 10 | 11 | It has these top-level messages: 12 | MoreDefaultsB 13 | MoreDefaultsA 14 | */ 15 | package moredefaults 16 | 17 | import proto "github.com/dropbox/goprotoc/proto" 18 | import math "math" 19 | 20 | // discarding unused import gogoproto "github.com/dropbox/goprotoc/gogoproto/gogo.pb" 21 | import test "github.com/dropbox/goprotoc/test/example" 22 | 23 | // Reference imports to suppress errors if they are not otherwise used. 24 | var _ = proto.Marshal 25 | var _ = math.Inf 26 | 27 | type MoreDefaultsB struct { 28 | Field1 *string `protobuf:"bytes,1,opt" json:"Field1,omitempty"` 29 | XXX_unrecognized []byte `json:"-"` 30 | } 31 | 32 | func (m *MoreDefaultsB) Reset() { *m = MoreDefaultsB{} } 33 | func (m *MoreDefaultsB) String() string { return proto.CompactTextString(m) } 34 | func (*MoreDefaultsB) ProtoMessage() {} 35 | 36 | func (m *MoreDefaultsB) GetField1() string { 37 | if m != nil && m.Field1 != nil { 38 | return *m.Field1 39 | } 40 | return "" 41 | } 42 | 43 | type MoreDefaultsA struct { 44 | Field1 *int64 `protobuf:"varint,1,opt,def=1234" json:"Field1,omitempty"` 45 | Field2 int64 `protobuf:"varint,2,opt" json:"Field2"` 46 | B1 *MoreDefaultsB `protobuf:"bytes,3,opt" json:"B1,omitempty"` 47 | B2 MoreDefaultsB `protobuf:"bytes,4,opt" json:"B2"` 48 | A1 *test.A `protobuf:"bytes,5,opt" json:"A1,omitempty"` 49 | A2 test.A `protobuf:"bytes,6,opt" json:"A2"` 50 | XXX_unrecognized []byte `json:"-"` 51 | } 52 | 53 | func (m *MoreDefaultsA) Reset() { *m = MoreDefaultsA{} } 54 | func (m *MoreDefaultsA) String() string { return proto.CompactTextString(m) } 55 | func (*MoreDefaultsA) ProtoMessage() {} 56 | 57 | const Default_MoreDefaultsA_Field1 int64 = 1234 58 | 59 | func (m *MoreDefaultsA) GetField1() int64 { 60 | if m != nil && m.Field1 != nil { 61 | return *m.Field1 62 | } 63 | return Default_MoreDefaultsA_Field1 64 | } 65 | 66 | func (m *MoreDefaultsA) GetField2() int64 { 67 | if m != nil { 68 | return m.Field2 69 | } 70 | return 0 71 | } 72 | 73 | func (m *MoreDefaultsA) GetB1() *MoreDefaultsB { 74 | if m != nil { 75 | return m.B1 76 | } 77 | return nil 78 | } 79 | 80 | func (m *MoreDefaultsA) GetB2() MoreDefaultsB { 81 | if m != nil { 82 | return m.B2 83 | } 84 | return MoreDefaultsB{} 85 | } 86 | 87 | func (m *MoreDefaultsA) GetA1() *test.A { 88 | if m != nil { 89 | return m.A1 90 | } 91 | return nil 92 | } 93 | 94 | func (m *MoreDefaultsA) GetA2() test.A { 95 | if m != nil { 96 | return m.A2 97 | } 98 | return test.A{} 99 | } 100 | 101 | func init() { 102 | } 103 | -------------------------------------------------------------------------------- /test/unrecognized/unrecognized.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package unrecognized; 28 | 29 | import "github.com/dropbox/goprotoc/gogoproto/gogo.proto"; 30 | 31 | option (gogoproto.goproto_stringer_all) = false; 32 | option (gogoproto.goproto_enum_prefix_all) = false; 33 | option (gogoproto.goproto_getters_all) = false; 34 | 35 | option (gogoproto.equal_all) = true; 36 | option (gogoproto.verbose_equal_all) = true; 37 | option (gogoproto.stringer_all) = true; 38 | option (gogoproto.gostring_all) = true; 39 | option (gogoproto.description_all) = true; 40 | 41 | option (gogoproto.testgen_all) = true; 42 | option (gogoproto.populate_all) = true; 43 | 44 | option (gogoproto.unmarshaler_all) = true; 45 | option (gogoproto.marshaler_all) = true; 46 | option (gogoproto.sizer_all) = true; 47 | 48 | message A { 49 | optional int64 Field1 = 2; 50 | repeated B B = 1; 51 | } 52 | 53 | message B { 54 | optional C C = 1; 55 | optional D D = 2; 56 | optional OldC F = 5; 57 | } 58 | 59 | message D { 60 | optional int64 Field1 = 1; 61 | } 62 | 63 | message C { 64 | optional double Field2 = 2; 65 | optional string Field3 = 3; 66 | optional double Field4 = 4; 67 | repeated bytes Field5 = 5; 68 | optional int64 Field6 = 6; 69 | repeated float Field7 = 7; 70 | } 71 | 72 | message OldA { 73 | optional int64 Field1 = 2; 74 | repeated OldB B = 1; 75 | } 76 | 77 | message OldB { 78 | optional OldC C = 1; 79 | optional OldC F = 5; 80 | } 81 | 82 | message OldC { 83 | optional int64 Field1 = 1; 84 | optional double Field2 = 2; 85 | optional string Field3 = 3; 86 | optional int64 Field6 = 6; 87 | repeated float Field7 = 7; 88 | } 89 | -------------------------------------------------------------------------------- /io/full.go: -------------------------------------------------------------------------------- 1 | // Extensions for Protocol Buffers to create more go like structures. 2 | // 3 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | // http://code.google.com/p/gogoprotobuf/gogoproto 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package io 30 | 31 | import ( 32 | "github.com/dropbox/goprotoc/proto" 33 | "io" 34 | ) 35 | 36 | func NewFullWriter(w io.Writer) WriteCloser { 37 | return &fullWriter{w, nil} 38 | } 39 | 40 | type fullWriter struct { 41 | w io.Writer 42 | buffer []byte 43 | } 44 | 45 | func (this *fullWriter) WriteMsg(msg proto.Message) (err error) { 46 | var data []byte 47 | if m, ok := msg.(marshaler); ok { 48 | n := m.Size() 49 | if n >= len(this.buffer) { 50 | this.buffer = make([]byte, n) 51 | } 52 | _, err = m.MarshalTo(this.buffer) 53 | if err != nil { 54 | return err 55 | } 56 | data = this.buffer[:n] 57 | } else { 58 | data, err = proto.Marshal(msg) 59 | if err != nil { 60 | return err 61 | } 62 | } 63 | _, err = this.w.Write(data) 64 | return err 65 | } 66 | 67 | func (this *fullWriter) Close() error { 68 | if closer, ok := this.w.(io.Closer); ok { 69 | return closer.Close() 70 | } 71 | return nil 72 | } 73 | 74 | type fullReader struct { 75 | r io.Reader 76 | buf []byte 77 | } 78 | 79 | func NewFullReader(r io.Reader, maxSize int) ReadCloser { 80 | return &fullReader{r, make([]byte, maxSize)} 81 | } 82 | 83 | func (this *fullReader) ReadMsg(msg proto.Message) error { 84 | length, err := this.r.Read(this.buf) 85 | if err != nil { 86 | return err 87 | } 88 | return proto.Unmarshal(this.buf[:length], msg) 89 | } 90 | 91 | func (this *fullReader) Close() error { 92 | if closer, ok := this.r.(io.Closer); ok { 93 | return closer.Close() 94 | } 95 | return nil 96 | } 97 | -------------------------------------------------------------------------------- /plugin/stringer/stringertest.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package stringer 28 | 29 | import ( 30 | "github.com/dropbox/goprotoc/gogoproto" 31 | "github.com/dropbox/goprotoc/plugin/testgen" 32 | "github.com/dropbox/goprotoc/protoc-gen-dgo/generator" 33 | ) 34 | 35 | type test struct { 36 | *generator.Generator 37 | } 38 | 39 | func NewTest(g *generator.Generator) testgen.TestPlugin { 40 | return &test{g} 41 | } 42 | 43 | func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool { 44 | used := false 45 | randPkg := imports.NewImport("math/rand") 46 | timePkg := imports.NewImport("time") 47 | testingPkg := imports.NewImport("testing") 48 | fmtPkg := imports.NewImport("fmt") 49 | for _, message := range file.Messages() { 50 | ccTypeName := generator.CamelCaseSlice(message.TypeName()) 51 | if !gogoproto.IsStringer(file.FileDescriptorProto, message.DescriptorProto) { 52 | continue 53 | } 54 | 55 | if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) { 56 | used = true 57 | p.P(`func Test`, ccTypeName, `Stringer(t *`, testingPkg.Use(), `.T) {`) 58 | p.In() 59 | p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`) 60 | p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`) 61 | p.P(`s1 := p.String()`) 62 | p.P(`s2 := `, fmtPkg.Use(), `.Sprintf("%v", p)`) 63 | p.P(`if s1 != s2 {`) 64 | p.In() 65 | p.P(`t.Fatalf("String want %v got %v", s1, s2)`) 66 | p.Out() 67 | p.P(`}`) 68 | p.Out() 69 | p.P(`}`) 70 | } 71 | 72 | } 73 | return used 74 | } 75 | 76 | func init() { 77 | testgen.RegisterTestPlugin(NewTest) 78 | } 79 | -------------------------------------------------------------------------------- /plugin/union/uniontest.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package union 28 | 29 | import ( 30 | "github.com/dropbox/goprotoc/gogoproto" 31 | "github.com/dropbox/goprotoc/plugin/testgen" 32 | "github.com/dropbox/goprotoc/protoc-gen-dgo/generator" 33 | ) 34 | 35 | type test struct { 36 | *generator.Generator 37 | } 38 | 39 | func NewTest(g *generator.Generator) testgen.TestPlugin { 40 | return &test{g} 41 | } 42 | 43 | func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool { 44 | used := false 45 | randPkg := imports.NewImport("math/rand") 46 | timePkg := imports.NewImport("time") 47 | testingPkg := imports.NewImport("testing") 48 | for _, message := range file.Messages() { 49 | if !gogoproto.IsUnion(file.FileDescriptorProto, message.DescriptorProto) || 50 | !gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) { 51 | continue 52 | } 53 | used = true 54 | ccTypeName := generator.CamelCaseSlice(message.TypeName()) 55 | 56 | p.P(`func Test`, ccTypeName, `OnlyOne(t *`, testingPkg.Use(), `.T) {`) 57 | p.In() 58 | p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`) 59 | p.P(`p := NewPopulated`, ccTypeName, `(popr, true)`) 60 | p.P(`v := p.GetValue()`) 61 | p.P(`msg := &`, ccTypeName, `{}`) 62 | p.P(`if !msg.SetValue(v) {`) 63 | p.In() 64 | p.P(`t.Fatalf("OnlyOne: Could not set Value")`) 65 | p.Out() 66 | p.P(`}`) 67 | p.P(`if !p.Equal(msg) {`) 68 | p.In() 69 | p.P(`t.Fatalf("%#v !OnlyOne Equal %#v", msg, p)`) 70 | p.Out() 71 | p.P(`}`) 72 | p.Out() 73 | p.P(`}`) 74 | 75 | } 76 | return used 77 | } 78 | 79 | func init() { 80 | testgen.RegisterTestPlugin(NewTest) 81 | } 82 | -------------------------------------------------------------------------------- /proto/testdata/golden_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // Verify that the compiler output for test.proto is unchanged. 33 | 34 | package testdata 35 | 36 | import ( 37 | "crypto/sha1" 38 | "fmt" 39 | "io/ioutil" 40 | "os" 41 | "os/exec" 42 | "path/filepath" 43 | "testing" 44 | ) 45 | 46 | // sum returns in string form (for easy comparison) the SHA-1 hash of the named file. 47 | func sum(t *testing.T, name string) string { 48 | data, err := ioutil.ReadFile(name) 49 | if err != nil { 50 | t.Fatal(err) 51 | } 52 | t.Logf("sum(%q): length is %d", name, len(data)) 53 | hash := sha1.New() 54 | _, err = hash.Write(data) 55 | if err != nil { 56 | t.Fatal(err) 57 | } 58 | return fmt.Sprintf("% x", hash.Sum(nil)) 59 | } 60 | 61 | func run(t *testing.T, name string, args ...string) { 62 | cmd := exec.Command(name, args...) 63 | cmd.Stdin = os.Stdin 64 | cmd.Stdout = os.Stdout 65 | cmd.Stderr = os.Stderr 66 | err := cmd.Run() 67 | if err != nil { 68 | t.Fatal(err) 69 | } 70 | } 71 | 72 | func TestGolden(t *testing.T) { 73 | // Compute the original checksum. 74 | goldenSum := sum(t, "test.pb.go") 75 | // Run the proto compiler. 76 | run(t, "protoc", "--go_out="+os.TempDir(), "test.proto") 77 | newFile := filepath.Join(os.TempDir(), "test.pb.go") 78 | defer os.Remove(newFile) 79 | // Compute the new checksum. 80 | newSum := sum(t, newFile) 81 | // Verify 82 | if newSum != goldenSum { 83 | run(t, "diff", "-u", "test.pb.go", newFile) 84 | t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/golden_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // Verify that the compiler output for test.proto is unchanged. 33 | 34 | package testdata 35 | 36 | import ( 37 | "crypto/sha1" 38 | "fmt" 39 | "io/ioutil" 40 | "os" 41 | "os/exec" 42 | "path/filepath" 43 | "testing" 44 | ) 45 | 46 | // sum returns in string form (for easy comparison) the SHA-1 hash of the named file. 47 | func sum(t *testing.T, name string) string { 48 | data, err := ioutil.ReadFile(name) 49 | if err != nil { 50 | t.Fatal(err) 51 | } 52 | t.Logf("sum(%q): length is %d", name, len(data)) 53 | hash := sha1.New() 54 | _, err = hash.Write(data) 55 | if err != nil { 56 | t.Fatal(err) 57 | } 58 | return fmt.Sprintf("% x", hash.Sum(nil)) 59 | } 60 | 61 | func run(t *testing.T, name string, args ...string) { 62 | cmd := exec.Command(name, args...) 63 | cmd.Stdin = os.Stdin 64 | cmd.Stdout = os.Stdout 65 | cmd.Stderr = os.Stderr 66 | err := cmd.Run() 67 | if err != nil { 68 | t.Fatal(err) 69 | } 70 | } 71 | 72 | func TestGolden(t *testing.T) { 73 | // Compute the original checksum. 74 | goldenSum := sum(t, "my_test/test.pb.go") 75 | // Run the proto compiler. 76 | run(t, "protoc", "--dgo_out="+os.TempDir(), "my_test/test.proto") 77 | newFile := filepath.Join(os.TempDir(), "my_test/test.pb.go") 78 | defer os.Remove(newFile) 79 | // Compute the new checksum. 80 | newSum := sum(t, newFile) 81 | // Verify 82 | if newSum != goldenSum { 83 | run(t, "diff", "-u", "my_test/test.pb.go", newFile) 84 | t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Goprotoc 2 | 3 | Goprotoc is a new experimental go protobuf compiler. It is a fork of GoGoProtobuf http://code.google.com/p/gogoprotobuf, which extends GoProtobuf http://code.google.com/p/goprotobuf 4 | 5 | The main goal of this project is to reduce memory pressure/gc pauses and to provide useful API for accessing/mutating message fields. 6 | 7 | ### Current state 8 | 9 | Goprotoc should be considered in early alpha; it "works" that in can successfully compile proto files 10 | on a few number of testcases but is not used in any production environment. 11 | 12 | ### Contributing 13 | 14 | Goprotoc welcomes any kind of contribution; please send any pull request for feature, tests or fixes. 15 | > tl;dr: You will need to sign the [Dropbox CLA](https://opensource.dropbox.com/cla/) and run the tests. 16 | 17 | ### Roadmap 18 | 19 | ##### v0.1: [released 9/19/2014] 20 | - Remove pointers from messages, add special fields to check is set 21 | - Generate full API functions to set/get/clear fields 22 | - Make all fields private 23 | - Optimize dynamic array growing 24 | - Support custom fields 25 | 26 | ### Getting started 27 | 28 | # Grab the code from this repository and install the proto package. 29 | go get -u github.com/dropbox/goprotoc 30 | run "make install" from goprotoc directory 31 | 32 | ### Running goprotoc 33 | 34 | The compiler plugin, protoc-gen-dgo, will be installed in $GOBIN, defaulting to $GOPATH/bin. It must be in your $PATH for the protocol compiler, protoc, to find it. 35 | 36 | Once the software is installed, there are two steps to using it. First you must compile the protocol buffer definitions and then import them, with the support library, into your program. 37 | 38 | To compile the protocol buffer definition, run protoc with the --dgo_out parameter set to the directory you want to output the Go code to. 39 | 40 | protoc --dgo_out=. *.proto 41 | 42 | If you are using any gogo.proto extensions you will need to specify the proto_path to include the descriptor.proto and gogo.proto. Located in github.com/dropbox/goprotoc/gogoproto and github.com/dropbox/goprotoc/protobuf respectively. 43 | 44 | The proto package converts data structures to and from the 45 | wire format of protocol buffers. It works in concert with the 46 | Go source code generated for .proto files by the protocol compiler. 47 | 48 | ### Unit tests 49 | 50 | # The majority of the library code is covered by unittests. You need to configure test settings first: 51 | make config && go test ./... 52 | 53 | 54 | ### A summary of the properties of the goprotc protocol buffer interface: 55 | 56 | - Names are turned from camel_case to CamelCase for export. 57 | - There are getters that return a field's value if set, and return the field's default value if unset. 58 | - There are setters that can change the value of a field. For message fields they return a mutable pointer. 59 | - There are adders that can add a element to a repeated field. The slice grows exponentially to optimize memory allocation. 60 | - There are clear methods for each individual field or for a message as a whole that clear each field recursively. 61 | - All the fields are private so the only way to get/set them is by using the api functions. 62 | - Custom fields are supported for user defined types and string to bytes casting. 63 | - Marshal and Unmarshal are functions to encode and decode the wire format. 64 | -------------------------------------------------------------------------------- /plugin/equal/equaltest.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package equal 28 | 29 | import ( 30 | "github.com/dropbox/goprotoc/gogoproto" 31 | "github.com/dropbox/goprotoc/plugin/testgen" 32 | "github.com/dropbox/goprotoc/protoc-gen-dgo/generator" 33 | ) 34 | 35 | type test struct { 36 | *generator.Generator 37 | } 38 | 39 | func NewTest(g *generator.Generator) testgen.TestPlugin { 40 | return &test{g} 41 | } 42 | 43 | func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool { 44 | used := false 45 | randPkg := imports.NewImport("math/rand") 46 | timePkg := imports.NewImport("time") 47 | testingPkg := imports.NewImport("testing") 48 | protoPkg := imports.NewImport("github.com/dropbox/goprotoc/proto") 49 | for _, message := range file.Messages() { 50 | ccTypeName := generator.CamelCaseSlice(message.TypeName()) 51 | if !gogoproto.HasVerboseEqual(file.FileDescriptorProto, message.DescriptorProto) { 52 | continue 53 | } 54 | 55 | if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) { 56 | used = true 57 | p.P(`func Test`, ccTypeName, `VerboseEqual(t *`, testingPkg.Use(), `.T) {`) 58 | p.In() 59 | p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`) 60 | p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`) 61 | p.P(`data, err := `, protoPkg.Use(), `.Marshal(p)`) 62 | p.P(`if err != nil {`) 63 | p.In() 64 | p.P(`panic(err)`) 65 | p.Out() 66 | p.P(`}`) 67 | p.P(`msg := &`, ccTypeName, `{}`) 68 | p.P(`if err := `, protoPkg.Use(), `.Unmarshal(data, msg); err != nil {`) 69 | p.In() 70 | p.P(`panic(err)`) 71 | p.Out() 72 | p.P(`}`) 73 | p.P(`if err := p.VerboseEqual(msg); err != nil {`) 74 | p.In() 75 | p.P(`t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)`) 76 | p.Out() 77 | p.P(`}`) 78 | p.Out() 79 | p.P(`}`) 80 | } 81 | 82 | } 83 | return used 84 | } 85 | 86 | func init() { 87 | testgen.RegisterTestPlugin(NewTest) 88 | } 89 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/extension_user.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | import "extension_base.proto"; 33 | import "extension_extra.proto"; 34 | 35 | package extension_user; 36 | 37 | message UserMessage { 38 | optional string name = 1; 39 | optional string rank = 2; 40 | } 41 | 42 | // Extend with a message 43 | extend extension_base.BaseMessage { 44 | optional UserMessage user_message = 5; 45 | } 46 | 47 | // Extend with a foreign message 48 | extend extension_base.BaseMessage { 49 | optional extension_extra.ExtraMessage extra_message = 9; 50 | } 51 | 52 | // Extend with some primitive types 53 | extend extension_base.BaseMessage { 54 | optional int32 width = 6; 55 | optional int64 area = 7; 56 | } 57 | 58 | // Extend inside the scope of another type 59 | message LoudMessage { 60 | extend extension_base.BaseMessage { 61 | optional uint32 volume = 8; 62 | } 63 | extensions 100 to max; 64 | } 65 | 66 | // Extend inside the scope of another type, using a message. 67 | message LoginMessage { 68 | extend extension_base.BaseMessage { 69 | optional UserMessage user_message = 16; 70 | } 71 | } 72 | 73 | // Extend with a repeated field 74 | extend extension_base.BaseMessage { 75 | repeated Detail detail = 17; 76 | } 77 | 78 | message Detail { 79 | optional string color = 1; 80 | } 81 | 82 | // An extension of an extension 83 | message Announcement { 84 | optional string words = 1; 85 | extend LoudMessage { 86 | optional Announcement loud_ext = 100; 87 | } 88 | } 89 | 90 | // Something that can be put in a message set. 91 | message OldStyleParcel { 92 | extend extension_base.OldStyleMessage { 93 | optional OldStyleParcel message_set_extension = 2001; 94 | } 95 | 96 | required string name = 1; 97 | optional int32 height = 2; 98 | } 99 | -------------------------------------------------------------------------------- /proto/skip_gogo.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package proto 28 | 29 | import ( 30 | "fmt" 31 | "io" 32 | ) 33 | 34 | func Skip(data []byte) (n int, err error) { 35 | l := len(data) 36 | index := 0 37 | for index < l { 38 | var wire uint64 39 | for shift := uint(0); ; shift += 7 { 40 | if index >= l { 41 | return 0, io.ErrUnexpectedEOF 42 | } 43 | b := data[index] 44 | index++ 45 | wire |= (uint64(b) & 0x7F) << shift 46 | if b < 0x80 { 47 | break 48 | } 49 | } 50 | wireType := int(wire & 0x7) 51 | switch wireType { 52 | case 0: 53 | for { 54 | if index >= l { 55 | return 0, io.ErrUnexpectedEOF 56 | } 57 | index++ 58 | if data[index-1] < 0x80 { 59 | break 60 | } 61 | } 62 | return index, nil 63 | case 1: 64 | index += 8 65 | return index, nil 66 | case 2: 67 | var length int 68 | for shift := uint(0); ; shift += 7 { 69 | if index >= l { 70 | return 0, io.ErrUnexpectedEOF 71 | } 72 | b := data[index] 73 | index++ 74 | length |= (int(b) & 0x7F) << shift 75 | if b < 0x80 { 76 | break 77 | } 78 | } 79 | index += length 80 | return index, nil 81 | case 3: 82 | for { 83 | var wire uint64 84 | var start int = index 85 | for shift := uint(0); ; shift += 7 { 86 | if index >= l { 87 | return 0, io.ErrUnexpectedEOF 88 | } 89 | b := data[index] 90 | index++ 91 | wire |= (uint64(b) & 0x7F) << shift 92 | if b < 0x80 { 93 | break 94 | } 95 | } 96 | wireType := int(wire & 0x7) 97 | if wireType == 4 { 98 | break 99 | } 100 | next, err := Skip(data[start:]) 101 | if err != nil { 102 | return 0, err 103 | } 104 | index = start + next 105 | } 106 | return index, nil 107 | case 4: 108 | return index, nil 109 | case 5: 110 | index += 4 111 | return index, nil 112 | default: 113 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType) 114 | } 115 | } 116 | panic("unreachable") 117 | } 118 | -------------------------------------------------------------------------------- /plugin/enumstringer/enumstringer.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | /* 28 | The enumstringer (experimental) plugin generates a String method for each enum. 29 | 30 | It is enabled by the following extensions: 31 | 32 | - enum_stringer 33 | - enum_stringer_all 34 | 35 | This package is subject to change. 36 | 37 | */ 38 | package enumstringer 39 | 40 | import ( 41 | "github.com/dropbox/goprotoc/gogoproto" 42 | "github.com/dropbox/goprotoc/protoc-gen-dgo/generator" 43 | ) 44 | 45 | type enumstringer struct { 46 | *generator.Generator 47 | generator.PluginImports 48 | atleastOne bool 49 | localName string 50 | } 51 | 52 | func NewEnumStringer() *enumstringer { 53 | return &enumstringer{} 54 | } 55 | 56 | func (p *enumstringer) Name() string { 57 | return "enumstringer" 58 | } 59 | 60 | func (p *enumstringer) Init(g *generator.Generator) { 61 | p.Generator = g 62 | } 63 | 64 | func (p *enumstringer) Generate(file *generator.FileDescriptor) { 65 | p.PluginImports = generator.NewPluginImports(p.Generator) 66 | p.atleastOne = false 67 | 68 | p.localName = generator.FileName(file) 69 | 70 | strconvPkg := p.NewImport("strconv") 71 | 72 | for _, enum := range file.Enums() { 73 | if !gogoproto.IsEnumStringer(file.FileDescriptorProto, enum.EnumDescriptorProto) { 74 | continue 75 | } 76 | if gogoproto.IsGoEnumStringer(file.FileDescriptorProto, enum.EnumDescriptorProto) { 77 | panic("old enum string method needs to be disabled, please use gogoproto.old_enum_stringer or gogoproto.old_enum_string_all and set it to false") 78 | } 79 | p.atleastOne = true 80 | ccTypeName := generator.CamelCaseSlice(enum.TypeName()) 81 | p.P("func (x ", ccTypeName, ") String() string {") 82 | p.In() 83 | p.P(`s, ok := `, ccTypeName, `_name[int32(x)]`) 84 | p.P(`if ok {`) 85 | p.In() 86 | p.P(`return s`) 87 | p.Out() 88 | p.P(`}`) 89 | p.P(`return `, strconvPkg.Use(), `.Itoa(int(x))`) 90 | p.Out() 91 | p.P(`}`) 92 | } 93 | 94 | if !p.atleastOne { 95 | return 96 | } 97 | 98 | } 99 | 100 | func init() { 101 | generator.RegisterPlugin(NewEnumStringer()) 102 | } 103 | -------------------------------------------------------------------------------- /gogoproto/gogo.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package gogoproto; 28 | 29 | import "github.com/dropbox/goprotoc/protobuf/google/protobuf/descriptor.proto"; 30 | 31 | extend google.protobuf.EnumOptions { 32 | optional bool goproto_enum_prefix = 62001; 33 | optional bool goproto_enum_stringer = 62021; 34 | optional bool enum_stringer = 62022; 35 | } 36 | 37 | extend google.protobuf.FileOptions { 38 | optional bool goproto_getters_all = 63001; 39 | optional bool goproto_enum_prefix_all = 63002; 40 | optional bool verbose_equal_all = 63004; 41 | optional bool face_all = 63005; 42 | optional bool gostring_all = 63006; 43 | optional bool populate_all = 63007; 44 | optional bool stringer_all = 63008; 45 | optional bool onlyone_all = 63009; 46 | 47 | optional bool equal_all = 63013; 48 | optional bool description_all = 63014; 49 | optional bool testgen_all = 63015; 50 | optional bool benchgen_all = 63016; 51 | optional bool marshaler_all = 63017; 52 | optional bool unmarshaler_all = 63018; 53 | optional bool bufferto_all = 63019; 54 | optional bool sizer_all = 63020; 55 | 56 | optional bool goproto_enum_stringer_all = 63021; 57 | optional bool enum_stringer_all = 63022; 58 | 59 | optional bool goproto_extensions_map_all = 63025; 60 | optional bool setter_all = 63026; 61 | } 62 | 63 | extend google.protobuf.MessageOptions { 64 | optional bool goproto_getters = 64001; 65 | optional bool verbose_equal = 64004; 66 | optional bool face = 64005; 67 | optional bool gostring = 64006; 68 | optional bool populate = 64007; 69 | optional bool stringer = 67008; 70 | optional bool onlyone = 64009; 71 | 72 | optional bool equal = 64013; 73 | optional bool description = 64014; 74 | optional bool testgen = 64015; 75 | optional bool benchgen = 64016; 76 | optional bool marshaler = 64017; 77 | optional bool unmarshaler = 64018; 78 | optional bool bufferto = 64019; 79 | optional bool sizer = 64020; 80 | 81 | optional bool goproto_extensions_map = 64025; 82 | optional bool setter = 64026; 83 | } 84 | 85 | extend google.protobuf.FieldOptions { 86 | optional bool nullable = 65001; 87 | optional bool embed = 65002; 88 | optional string customtype = 65003; 89 | optional string customname = 65004; 90 | optional string jsontag = 65005; 91 | optional string moretags = 65006; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /test/mixbench/marshal.txt: -------------------------------------------------------------------------------- 1 | PASS 2 | BenchmarkNidOptNativeProtoMarshal-4 1000000 1912 ns/op 194.48 MB/s 3 | BenchmarkNinOptNativeProtoMarshal-4 1000000 2207 ns/op 154.04 MB/s 4 | BenchmarkNidRepNativeProtoMarshal-4 50000 36321 ns/op 195.12 MB/s 5 | BenchmarkNinRepNativeProtoMarshal-4 50000 36979 ns/op 191.65 MB/s 6 | BenchmarkNidRepPackedNativeProtoMarshal-4 50000 29607 ns/op 115.41 MB/s 7 | BenchmarkNinRepPackedNativeProtoMarshal-4 50000 29781 ns/op 114.73 MB/s 8 | BenchmarkNidOptStructProtoMarshal-4 500000 6986 ns/op 201.40 MB/s 9 | BenchmarkNinOptStructProtoMarshal-4 500000 7044 ns/op 180.14 MB/s 10 | BenchmarkNidRepStructProtoMarshal-4 50000 40141 ns/op 219.87 MB/s 11 | BenchmarkNinRepStructProtoMarshal-4 50000 40930 ns/op 215.63 MB/s 12 | BenchmarkNidEmbeddedStructProtoMarshal-4 500000 4595 ns/op 163.62 MB/s 13 | BenchmarkNinEmbeddedStructProtoMarshal-4 500000 4502 ns/op 158.37 MB/s 14 | BenchmarkNidNestedStructProtoMarshal-4 10000 171850 ns/op 215.28 MB/s 15 | BenchmarkNinNestedStructProtoMarshal-4 10000 150174 ns/op 246.19 MB/s 16 | BenchmarkNidOptCustomProtoMarshal-4 1000000 1867 ns/op 38.02 MB/s 17 | BenchmarkNinOptCustomProtoMarshal-4 1000000 1799 ns/op 37.24 MB/s 18 | BenchmarkNidRepCustomProtoMarshal-4 500000 4120 ns/op 43.93 MB/s 19 | BenchmarkNinRepCustomProtoMarshal-4 500000 4059 ns/op 44.58 MB/s 20 | BenchmarkNinOptNativeUnionProtoMarshal-4 1000000 1316 ns/op 23.54 MB/s 21 | BenchmarkNinOptStructUnionProtoMarshal-4 1000000 1945 ns/op 57.06 MB/s 22 | BenchmarkNinEmbeddedStructUnionProtoMarshal-4 1000000 2861 ns/op 84.22 MB/s 23 | BenchmarkNinNestedStructUnionProtoMarshal-4 1000000 2490 ns/op 52.60 MB/s 24 | BenchmarkTreeProtoMarshal-4 1000000 2293 ns/op 109.89 MB/s 25 | BenchmarkOrBranchProtoMarshal-4 500000 4401 ns/op 124.74 MB/s 26 | BenchmarkAndBranchProtoMarshal-4 500000 4394 ns/op 124.93 MB/s 27 | BenchmarkLeafProtoMarshal-4 1000000 1696 ns/op 142.68 MB/s 28 | BenchmarkDeepTreeProtoMarshal-4 500000 3740 ns/op 79.40 MB/s 29 | BenchmarkADeepBranchProtoMarshal-4 500000 4677 ns/op 71.41 MB/s 30 | BenchmarkAndDeepBranchProtoMarshal-4 500000 6597 ns/op 96.25 MB/s 31 | BenchmarkDeepLeafProtoMarshal-4 500000 3179 ns/op 91.21 MB/s 32 | BenchmarkNilProtoMarshal-4 1000000 1326 ns/op 26.39 MB/s 33 | BenchmarkNidOptEnumProtoMarshal-4 1000000 1360 ns/op 27.20 MB/s 34 | BenchmarkNinOptEnumProtoMarshal-4 1000000 1360 ns/op 26.46 MB/s 35 | BenchmarkNidRepEnumProtoMarshal-4 1000000 1314 ns/op 32.72 MB/s 36 | BenchmarkNinRepEnumProtoMarshal-4 1000000 1311 ns/op 32.78 MB/s 37 | BenchmarkNinOptEnumDefaultProtoMarshal-4 1000000 1349 ns/op 26.67 MB/s 38 | BenchmarkAnotherNinOptEnumProtoMarshal-4 1000000 1369 ns/op 26.29 MB/s 39 | BenchmarkAnotherNinOptEnumDefaultProtoMarshal-4 1000000 1341 ns/op 26.84 MB/s 40 | BenchmarkTimerProtoMarshal-4 1000000 1604 ns/op 65.45 MB/s 41 | BenchmarkMyExtendableProtoMarshal-4 1000000 1545 ns/op 51.75 MB/s 42 | BenchmarkOtherExtenableProtoMarshal-4 1000000 2704 ns/op 58.04 MB/s 43 | BenchmarkNestedDefinitionProtoMarshal-4 500000 4177 ns/op 108.92 MB/s 44 | BenchmarkNestedDefinition_NestedMessageProtoMarshal-4 1000000 2473 ns/op 95.43 MB/s 45 | BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-4 1000000 1616 ns/op 131.14 MB/s 46 | BenchmarkNestedScopeProtoMarshal-4 500000 4058 ns/op 110.14 MB/s 47 | BenchmarkNinOptNativeDefaultProtoMarshal-4 500000 2863 ns/op 118.72 MB/s 48 | BenchmarkCustomContainerProtoMarshal-4 1000000 2289 ns/op 47.17 MB/s 49 | ok code.google.com/p/gogoprotobuf/test/mixbench/testdata 152.674s 50 | -------------------------------------------------------------------------------- /test/mixbench/marshaler.txt: -------------------------------------------------------------------------------- 1 | PASS 2 | BenchmarkNidOptNativeProtoMarshal-4 5000000 558 ns/op 665.90 MB/s 3 | BenchmarkNinOptNativeProtoMarshal-4 5000000 632 ns/op 537.89 MB/s 4 | BenchmarkNidRepNativeProtoMarshal-4 200000 9070 ns/op 781.29 MB/s 5 | BenchmarkNinRepNativeProtoMarshal-4 200000 8943 ns/op 792.42 MB/s 6 | BenchmarkNidRepPackedNativeProtoMarshal-4 200000 8142 ns/op 419.65 MB/s 7 | BenchmarkNinRepPackedNativeProtoMarshal-4 200000 8114 ns/op 421.11 MB/s 8 | BenchmarkNidOptStructProtoMarshal-4 1000000 2018 ns/op 697.03 MB/s 9 | BenchmarkNinOptStructProtoMarshal-4 1000000 1919 ns/op 661.19 MB/s 10 | BenchmarkNidRepStructProtoMarshal-4 100000 11442 ns/op 771.31 MB/s 11 | BenchmarkNinRepStructProtoMarshal-4 200000 10742 ns/op 821.60 MB/s 12 | BenchmarkNidEmbeddedStructProtoMarshal-4 1000000 1203 ns/op 624.73 MB/s 13 | BenchmarkNinEmbeddedStructProtoMarshal-4 1000000 1135 ns/op 627.68 MB/s 14 | BenchmarkNidNestedStructProtoMarshal-4 50000 56182 ns/op 658.50 MB/s 15 | BenchmarkNinNestedStructProtoMarshal-4 50000 49802 ns/op 742.37 MB/s 16 | BenchmarkNidOptCustomProtoMarshal-4 5000000 303 ns/op 233.89 MB/s 17 | BenchmarkNinOptCustomProtoMarshal-4 10000000 280 ns/op 238.94 MB/s 18 | BenchmarkNidRepCustomProtoMarshal-4 5000000 604 ns/op 299.21 MB/s 19 | BenchmarkNinRepCustomProtoMarshal-4 5000000 599 ns/op 301.77 MB/s 20 | BenchmarkNinOptNativeUnionProtoMarshal-4 10000000 196 ns/op 158.04 MB/s 21 | BenchmarkNinOptStructUnionProtoMarshal-4 5000000 384 ns/op 288.81 MB/s 22 | BenchmarkNinEmbeddedStructUnionProtoMarshal-4 5000000 662 ns/op 363.93 MB/s 23 | BenchmarkNinNestedStructUnionProtoMarshal-4 5000000 502 ns/op 260.48 MB/s 24 | BenchmarkTreeProtoMarshal-4 5000000 558 ns/op 451.53 MB/s 25 | BenchmarkOrBranchProtoMarshal-4 2000000 992 ns/op 553.08 MB/s 26 | BenchmarkAndBranchProtoMarshal-4 2000000 998 ns/op 550.04 MB/s 27 | BenchmarkLeafProtoMarshal-4 5000000 523 ns/op 462.20 MB/s 28 | BenchmarkDeepTreeProtoMarshal-4 5000000 691 ns/op 429.41 MB/s 29 | BenchmarkADeepBranchProtoMarshal-4 2000000 787 ns/op 424.31 MB/s 30 | BenchmarkAndDeepBranchProtoMarshal-4 1000000 1329 ns/op 477.67 MB/s 31 | BenchmarkDeepLeafProtoMarshal-4 5000000 639 ns/op 453.35 MB/s 32 | BenchmarkNilProtoMarshal-4 10000000 189 ns/op 184.92 MB/s 33 | BenchmarkNidOptEnumProtoMarshal-4 10000000 216 ns/op 170.86 MB/s 34 | BenchmarkNinOptEnumProtoMarshal-4 10000000 209 ns/op 171.60 MB/s 35 | BenchmarkNidRepEnumProtoMarshal-4 10000000 237 ns/op 180.80 MB/s 36 | BenchmarkNinRepEnumProtoMarshal-4 10000000 235 ns/op 182.93 MB/s 37 | BenchmarkNinOptEnumDefaultProtoMarshal-4 10000000 209 ns/op 171.51 MB/s 38 | BenchmarkAnotherNinOptEnumProtoMarshal-4 10000000 211 ns/op 170.44 MB/s 39 | BenchmarkAnotherNinOptEnumDefaultProtoMarshal-4 10000000 214 ns/op 167.95 MB/s 40 | BenchmarkTimerProtoMarshal-4 5000000 344 ns/op 305.21 MB/s 41 | BenchmarkMyExtendableProtoMarshal-4 5000000 695 ns/op 115.09 MB/s 42 | BenchmarkOtherExtenableProtoMarshal-4 1000000 1295 ns/op 121.15 MB/s 43 | BenchmarkNestedDefinitionProtoMarshal-4 2000000 906 ns/op 501.69 MB/s 44 | BenchmarkNestedDefinition_NestedMessageProtoMarshal-4 5000000 537 ns/op 438.85 MB/s 45 | BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-4 5000000 479 ns/op 442.52 MB/s 46 | BenchmarkNestedScopeProtoMarshal-4 2000000 862 ns/op 518.19 MB/s 47 | BenchmarkNinOptNativeDefaultProtoMarshal-4 2000000 758 ns/op 448.10 MB/s 48 | BenchmarkCustomContainerProtoMarshal-4 5000000 390 ns/op 276.58 MB/s 49 | ok code.google.com/p/gogoprotobuf/test/mixbench/testdata 190.796s 50 | -------------------------------------------------------------------------------- /test/mixbench/unsafe_marshaler.txt: -------------------------------------------------------------------------------- 1 | PASS 2 | BenchmarkNidOptNativeProtoMarshal-4 5000000 531 ns/op 700.19 MB/s 3 | BenchmarkNinOptNativeProtoMarshal-4 5000000 594 ns/op 572.27 MB/s 4 | BenchmarkNidRepNativeProtoMarshal-4 200000 8087 ns/op 876.29 MB/s 5 | BenchmarkNinRepNativeProtoMarshal-4 500000 8344 ns/op 849.34 MB/s 6 | BenchmarkNidRepPackedNativeProtoMarshal-4 200000 7595 ns/op 449.89 MB/s 7 | BenchmarkNinRepPackedNativeProtoMarshal-4 500000 7342 ns/op 465.38 MB/s 8 | BenchmarkNidOptStructProtoMarshal-4 1000000 1928 ns/op 729.46 MB/s 9 | BenchmarkNinOptStructProtoMarshal-4 1000000 1859 ns/op 682.32 MB/s 10 | BenchmarkNidRepStructProtoMarshal-4 100000 10993 ns/op 802.82 MB/s 11 | BenchmarkNinRepStructProtoMarshal-4 200000 10088 ns/op 874.84 MB/s 12 | BenchmarkNidEmbeddedStructProtoMarshal-4 1000000 1179 ns/op 637.53 MB/s 13 | BenchmarkNinEmbeddedStructProtoMarshal-4 1000000 1077 ns/op 661.58 MB/s 14 | BenchmarkNidNestedStructProtoMarshal-4 50000 53464 ns/op 691.97 MB/s 15 | BenchmarkNinNestedStructProtoMarshal-4 50000 47677 ns/op 775.46 MB/s 16 | BenchmarkNidOptCustomProtoMarshal-4 5000000 303 ns/op 234.13 MB/s 17 | BenchmarkNinOptCustomProtoMarshal-4 10000000 284 ns/op 235.56 MB/s 18 | BenchmarkNidRepCustomProtoMarshal-4 5000000 598 ns/op 302.19 MB/s 19 | BenchmarkNinRepCustomProtoMarshal-4 5000000 593 ns/op 304.87 MB/s 20 | BenchmarkNinOptNativeUnionProtoMarshal-4 10000000 190 ns/op 162.47 MB/s 21 | BenchmarkNinOptStructUnionProtoMarshal-4 5000000 374 ns/op 296.15 MB/s 22 | BenchmarkNinEmbeddedStructUnionProtoMarshal-4 5000000 652 ns/op 369.55 MB/s 23 | BenchmarkNinNestedStructUnionProtoMarshal-4 5000000 474 ns/op 275.97 MB/s 24 | BenchmarkTreeProtoMarshal-4 5000000 567 ns/op 444.16 MB/s 25 | BenchmarkOrBranchProtoMarshal-4 1000000 1007 ns/op 544.72 MB/s 26 | BenchmarkAndBranchProtoMarshal-4 1000000 1061 ns/op 517.27 MB/s 27 | BenchmarkLeafProtoMarshal-4 5000000 511 ns/op 473.41 MB/s 28 | BenchmarkDeepTreeProtoMarshal-4 5000000 716 ns/op 414.59 MB/s 29 | BenchmarkADeepBranchProtoMarshal-4 2000000 811 ns/op 411.60 MB/s 30 | BenchmarkAndDeepBranchProtoMarshal-4 1000000 1324 ns/op 479.34 MB/s 31 | BenchmarkDeepLeafProtoMarshal-4 5000000 636 ns/op 455.66 MB/s 32 | BenchmarkNilProtoMarshal-4 10000000 189 ns/op 184.91 MB/s 33 | BenchmarkNidOptEnumProtoMarshal-4 10000000 211 ns/op 174.55 MB/s 34 | BenchmarkNinOptEnumProtoMarshal-4 10000000 207 ns/op 173.24 MB/s 35 | BenchmarkNidRepEnumProtoMarshal-4 10000000 231 ns/op 185.80 MB/s 36 | BenchmarkNinRepEnumProtoMarshal-4 10000000 230 ns/op 186.79 MB/s 37 | BenchmarkNinOptEnumDefaultProtoMarshal-4 10000000 208 ns/op 172.65 MB/s 38 | BenchmarkAnotherNinOptEnumProtoMarshal-4 10000000 207 ns/op 173.15 MB/s 39 | BenchmarkAnotherNinOptEnumDefaultProtoMarshal-4 10000000 209 ns/op 171.99 MB/s 40 | BenchmarkTimerProtoMarshal-4 5000000 320 ns/op 327.65 MB/s 41 | BenchmarkMyExtendableProtoMarshal-4 5000000 702 ns/op 113.85 MB/s 42 | BenchmarkOtherExtenableProtoMarshal-4 1000000 1329 ns/op 118.07 MB/s 43 | BenchmarkNestedDefinitionProtoMarshal-4 2000000 904 ns/op 502.96 MB/s 44 | BenchmarkNestedDefinition_NestedMessageProtoMarshal-4 5000000 542 ns/op 434.70 MB/s 45 | BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-4 5000000 465 ns/op 455.00 MB/s 46 | BenchmarkNestedScopeProtoMarshal-4 2000000 857 ns/op 521.49 MB/s 47 | BenchmarkNinOptNativeDefaultProtoMarshal-4 5000000 734 ns/op 462.95 MB/s 48 | BenchmarkCustomContainerProtoMarshal-4 5000000 378 ns/op 285.67 MB/s 49 | ok code.google.com/p/gogoprotobuf/test/mixbench/testdata 192.235s 50 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/my_test/test.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package my.test; // dotted package name 33 | 34 | //import "imp.proto"; 35 | import "multi/multi1.proto"; // unused import 36 | 37 | enum HatType { 38 | // deliberately skipping 0 39 | FEDORA = 1; 40 | FEZ = 2; 41 | } 42 | 43 | // This enum represents days of the week. 44 | enum Days { 45 | option allow_alias = true; 46 | 47 | MONDAY = 1; 48 | TUESDAY = 2; 49 | LUNDI = 1; // same value as MONDAY 50 | } 51 | 52 | // This is a message that might be sent somewhere. 53 | message Request { 54 | enum Color { 55 | RED = 0; 56 | GREEN = 1; 57 | BLUE = 2; 58 | } 59 | repeated int64 key = 1; 60 | // optional imp.ImportedMessage imported_message = 2; 61 | optional Color hue = 3; // no default 62 | optional HatType hat = 4 [default=FEDORA]; 63 | // optional imp.ImportedMessage.Owner owner = 6; 64 | optional float deadline = 7 [default=inf]; 65 | optional group SomeGroup = 8 { 66 | optional int32 group_field = 9; 67 | } 68 | 69 | // These foreign types are in imp2.proto, 70 | // which is publicly imported by imp.proto. 71 | // optional imp.PubliclyImportedMessage pub = 10; 72 | // optional imp.PubliclyImportedEnum pub_enum = 13 [default=HAIR]; 73 | 74 | 75 | optional int32 reset = 12; 76 | } 77 | 78 | message Reply { 79 | message Entry { 80 | required int64 key_that_needs_1234camel_CasIng = 1; 81 | optional int64 value = 2 [default=7]; 82 | optional int64 _my_field_name_2 = 3; 83 | enum Game { 84 | FOOTBALL = 1; 85 | TENNIS = 2; 86 | } 87 | } 88 | repeated Entry found = 1; 89 | repeated int32 compact_keys = 2 [packed=true]; 90 | extensions 100 to max; 91 | } 92 | 93 | message ReplyExtensions { 94 | extend Reply { 95 | optional double time = 101; 96 | } 97 | } 98 | 99 | // top-level extension 100 | extend Reply { 101 | optional string tag = 103; 102 | } 103 | 104 | message OldReply { 105 | // Extensions will be encoded in MessageSet wire format. 106 | option message_set_wire_format = true; 107 | extensions 100 to max; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /test/mixbench/unmarshal.txt: -------------------------------------------------------------------------------- 1 | PASS 2 | BenchmarkNidOptNativeProtoUnmarshal-4 1000000 2006 ns/op 185.44 MB/s 3 | BenchmarkNinOptNativeProtoUnmarshal-4 1000000 1960 ns/op 173.41 MB/s 4 | BenchmarkNidRepNativeProtoUnmarshal-4 50000 36241 ns/op 195.55 MB/s 5 | BenchmarkNinRepNativeProtoUnmarshal-4 50000 35648 ns/op 198.80 MB/s 6 | BenchmarkNidRepPackedNativeProtoUnmarshal-4 100000 18641 ns/op 183.30 MB/s 7 | BenchmarkNinRepPackedNativeProtoUnmarshal-4 100000 18398 ns/op 185.72 MB/s 8 | BenchmarkNidOptStructProtoUnmarshal-4 500000 5938 ns/op 236.92 MB/s 9 | BenchmarkNinOptStructProtoUnmarshal-4 500000 5871 ns/op 216.14 MB/s 10 | BenchmarkNidRepStructProtoUnmarshal-4 50000 46237 ns/op 190.88 MB/s 11 | BenchmarkNinRepStructProtoUnmarshal-4 50000 39915 ns/op 221.12 MB/s 12 | BenchmarkNidEmbeddedStructProtoUnmarshal-4 500000 3946 ns/op 190.56 MB/s 13 | BenchmarkNinEmbeddedStructProtoUnmarshal-4 500000 3997 ns/op 178.35 MB/s 14 | BenchmarkNidNestedStructProtoUnmarshal-4 10000 207132 ns/op 178.61 MB/s 15 | BenchmarkNinNestedStructProtoUnmarshal-4 10000 170116 ns/op 217.33 MB/s 16 | BenchmarkNidOptCustomProtoUnmarshal-4 1000000 2321 ns/op 30.58 MB/s 17 | BenchmarkNinOptCustomProtoUnmarshal-4 1000000 1947 ns/op 34.40 MB/s 18 | BenchmarkNidRepCustomProtoUnmarshal-4 200000 7884 ns/op 22.96 MB/s 19 | BenchmarkNinRepCustomProtoUnmarshal-4 200000 7926 ns/op 22.83 MB/s 20 | BenchmarkNinOptNativeUnionProtoUnmarshal-4 1000000 1242 ns/op 24.94 MB/s 21 | BenchmarkNinOptStructUnionProtoUnmarshal-4 1000000 1550 ns/op 71.58 MB/s 22 | BenchmarkNinEmbeddedStructUnionProtoUnmarshal-4 1000000 2209 ns/op 109.07 MB/s 23 | BenchmarkNinNestedStructUnionProtoUnmarshal-4 1000000 1954 ns/op 67.02 MB/s 24 | BenchmarkTreeProtoUnmarshal-4 1000000 1785 ns/op 141.12 MB/s 25 | BenchmarkOrBranchProtoUnmarshal-4 1000000 2769 ns/op 198.23 MB/s 26 | BenchmarkAndBranchProtoUnmarshal-4 500000 2680 ns/op 204.84 MB/s 27 | BenchmarkLeafProtoUnmarshal-4 1000000 1407 ns/op 171.92 MB/s 28 | BenchmarkDeepTreeProtoUnmarshal-4 1000000 2387 ns/op 124.40 MB/s 29 | BenchmarkADeepBranchProtoUnmarshal-4 1000000 2621 ns/op 127.39 MB/s 30 | BenchmarkAndDeepBranchProtoUnmarshal-4 500000 3853 ns/op 164.79 MB/s 31 | BenchmarkDeepLeafProtoUnmarshal-4 1000000 2027 ns/op 143.02 MB/s 32 | BenchmarkNilProtoUnmarshal-4 1000000 1472 ns/op 23.78 MB/s 33 | BenchmarkNidOptEnumProtoUnmarshal-4 1000000 1597 ns/op 23.16 MB/s 34 | BenchmarkNinOptEnumProtoUnmarshal-4 1000000 1557 ns/op 23.12 MB/s 35 | BenchmarkNidRepEnumProtoUnmarshal-4 1000000 1746 ns/op 24.62 MB/s 36 | BenchmarkNinRepEnumProtoUnmarshal-4 1000000 1779 ns/op 24.16 MB/s 37 | BenchmarkNinOptEnumDefaultProtoUnmarshal-4 1000000 1607 ns/op 22.39 MB/s 38 | BenchmarkAnotherNinOptEnumProtoUnmarshal-4 1000000 1545 ns/op 23.29 MB/s 39 | BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-4 1000000 1578 ns/op 22.81 MB/s 40 | BenchmarkTimerProtoUnmarshal-4 1000000 1572 ns/op 66.79 MB/s 41 | BenchmarkMyExtendableProtoUnmarshal-4 1000000 2610 ns/op 30.64 MB/s 42 | BenchmarkOtherExtenableProtoUnmarshal-4 500000 3792 ns/op 41.40 MB/s 43 | BenchmarkNestedDefinitionProtoUnmarshal-4 500000 2987 ns/op 152.29 MB/s 44 | BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-4 1000000 1898 ns/op 124.30 MB/s 45 | BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-4 1000000 1326 ns/op 159.87 MB/s 46 | BenchmarkNestedScopeProtoUnmarshal-4 1000000 2956 ns/op 151.20 MB/s 47 | BenchmarkNinOptNativeDefaultProtoUnmarshal-4 1000000 2244 ns/op 151.45 MB/s 48 | BenchmarkCustomContainerProtoUnmarshal-4 1000000 2652 ns/op 40.71 MB/s 49 | ok code.google.com/p/gogoprotobuf/test/mixbench/testdata 167.715s 50 | -------------------------------------------------------------------------------- /test/mixbench/unmarshaler.txt: -------------------------------------------------------------------------------- 1 | PASS 2 | BenchmarkNidOptNativeProtoUnmarshal-4 2000000 792 ns/op 469.35 MB/s 3 | BenchmarkNinOptNativeProtoUnmarshal-4 1000000 1167 ns/op 291.16 MB/s 4 | BenchmarkNidRepNativeProtoUnmarshal-4 100000 25302 ns/op 280.09 MB/s 5 | BenchmarkNinRepNativeProtoUnmarshal-4 100000 25069 ns/op 282.70 MB/s 6 | BenchmarkNidRepPackedNativeProtoUnmarshal-4 100000 16569 ns/op 206.22 MB/s 7 | BenchmarkNinRepPackedNativeProtoUnmarshal-4 100000 16323 ns/op 209.33 MB/s 8 | BenchmarkNidOptStructProtoUnmarshal-4 1000000 3107 ns/op 452.75 MB/s 9 | BenchmarkNinOptStructProtoUnmarshal-4 500000 3262 ns/op 388.98 MB/s 10 | BenchmarkNidRepStructProtoUnmarshal-4 100000 26090 ns/op 338.28 MB/s 11 | BenchmarkNinRepStructProtoUnmarshal-4 100000 26086 ns/op 338.34 MB/s 12 | BenchmarkNidEmbeddedStructProtoUnmarshal-4 1000000 1785 ns/op 421.14 MB/s 13 | BenchmarkNinEmbeddedStructProtoUnmarshal-4 1000000 1838 ns/op 387.83 MB/s 14 | BenchmarkNidNestedStructProtoUnmarshal-4 10000 119933 ns/op 308.47 MB/s 15 | BenchmarkNinNestedStructProtoUnmarshal-4 10000 106914 ns/op 345.81 MB/s 16 | BenchmarkNidOptCustomProtoUnmarshal-4 5000000 485 ns/op 146.36 MB/s 17 | BenchmarkNinOptCustomProtoUnmarshal-4 5000000 648 ns/op 103.26 MB/s 18 | BenchmarkNidRepCustomProtoUnmarshal-4 1000000 1743 ns/op 103.83 MB/s 19 | BenchmarkNinRepCustomProtoUnmarshal-4 1000000 1766 ns/op 102.44 MB/s 20 | BenchmarkNinOptNativeUnionProtoUnmarshal-4 10000000 187 ns/op 165.31 MB/s 21 | BenchmarkNinOptStructUnionProtoUnmarshal-4 5000000 519 ns/op 213.49 MB/s 22 | BenchmarkNinEmbeddedStructUnionProtoUnmarshal-4 2000000 971 ns/op 247.99 MB/s 23 | BenchmarkNinNestedStructUnionProtoUnmarshal-4 2000000 801 ns/op 163.54 MB/s 24 | BenchmarkTreeProtoUnmarshal-4 2000000 789 ns/op 319.14 MB/s 25 | BenchmarkOrBranchProtoUnmarshal-4 1000000 1553 ns/op 353.47 MB/s 26 | BenchmarkAndBranchProtoUnmarshal-4 1000000 1552 ns/op 353.60 MB/s 27 | BenchmarkLeafProtoUnmarshal-4 5000000 654 ns/op 369.63 MB/s 28 | BenchmarkDeepTreeProtoUnmarshal-4 1000000 1219 ns/op 243.63 MB/s 29 | BenchmarkADeepBranchProtoUnmarshal-4 1000000 1504 ns/op 222.02 MB/s 30 | BenchmarkAndDeepBranchProtoUnmarshal-4 1000000 2327 ns/op 272.88 MB/s 31 | BenchmarkDeepLeafProtoUnmarshal-4 1000000 1083 ns/op 267.74 MB/s 32 | BenchmarkNilProtoUnmarshal-4 5000000 401 ns/op 87.26 MB/s 33 | BenchmarkNidOptEnumProtoUnmarshal-4 5000000 412 ns/op 89.66 MB/s 34 | BenchmarkNinOptEnumProtoUnmarshal-4 5000000 451 ns/op 79.80 MB/s 35 | BenchmarkNidRepEnumProtoUnmarshal-4 5000000 670 ns/op 64.12 MB/s 36 | BenchmarkNinRepEnumProtoUnmarshal-4 5000000 667 ns/op 64.40 MB/s 37 | BenchmarkNinOptEnumDefaultProtoUnmarshal-4 5000000 450 ns/op 79.88 MB/s 38 | BenchmarkAnotherNinOptEnumProtoUnmarshal-4 5000000 449 ns/op 80.15 MB/s 39 | BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-4 5000000 448 ns/op 80.24 MB/s 40 | BenchmarkTimerProtoUnmarshal-4 5000000 575 ns/op 182.50 MB/s 41 | BenchmarkMyExtendableProtoUnmarshal-4 1000000 1450 ns/op 55.14 MB/s 42 | BenchmarkOtherExtenableProtoUnmarshal-4 1000000 2567 ns/op 61.15 MB/s 43 | BenchmarkNestedDefinitionProtoUnmarshal-4 1000000 1889 ns/op 240.85 MB/s 44 | BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-4 1000000 1080 ns/op 218.42 MB/s 45 | BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-4 5000000 693 ns/op 305.86 MB/s 46 | BenchmarkNestedScopeProtoUnmarshal-4 1000000 1843 ns/op 242.49 MB/s 47 | BenchmarkNinOptNativeDefaultProtoUnmarshal-4 1000000 1342 ns/op 253.25 MB/s 48 | BenchmarkCustomContainerProtoUnmarshal-4 2000000 831 ns/op 129.82 MB/s 49 | ok code.google.com/p/gogoprotobuf/test/mixbench/testdata 170.829s 50 | -------------------------------------------------------------------------------- /test/mixbench/unsafe_unmarshaler.txt: -------------------------------------------------------------------------------- 1 | PASS 2 | BenchmarkNidOptNativeProtoUnmarshal-4 2000000 760 ns/op 488.86 MB/s 3 | BenchmarkNinOptNativeProtoUnmarshal-4 1000000 1130 ns/op 300.67 MB/s 4 | BenchmarkNidRepNativeProtoUnmarshal-4 100000 23698 ns/op 299.05 MB/s 5 | BenchmarkNinRepNativeProtoUnmarshal-4 100000 23400 ns/op 302.86 MB/s 6 | BenchmarkNidRepPackedNativeProtoUnmarshal-4 100000 15286 ns/op 223.53 MB/s 7 | BenchmarkNinRepPackedNativeProtoUnmarshal-4 100000 15375 ns/op 222.23 MB/s 8 | BenchmarkNidOptStructProtoUnmarshal-4 1000000 3019 ns/op 466.02 MB/s 9 | BenchmarkNinOptStructProtoUnmarshal-4 500000 3169 ns/op 400.35 MB/s 10 | BenchmarkNidRepStructProtoUnmarshal-4 100000 25167 ns/op 350.69 MB/s 11 | BenchmarkNinRepStructProtoUnmarshal-4 100000 25199 ns/op 350.25 MB/s 12 | BenchmarkNidEmbeddedStructProtoUnmarshal-4 1000000 1714 ns/op 438.65 MB/s 13 | BenchmarkNinEmbeddedStructProtoUnmarshal-4 1000000 1793 ns/op 397.49 MB/s 14 | BenchmarkNidNestedStructProtoUnmarshal-4 10000 115531 ns/op 320.22 MB/s 15 | BenchmarkNinNestedStructProtoUnmarshal-4 10000 109260 ns/op 338.39 MB/s 16 | BenchmarkNidOptCustomProtoUnmarshal-4 5000000 487 ns/op 145.63 MB/s 17 | BenchmarkNinOptCustomProtoUnmarshal-4 5000000 644 ns/op 103.94 MB/s 18 | BenchmarkNidRepCustomProtoUnmarshal-4 1000000 1733 ns/op 104.42 MB/s 19 | BenchmarkNinRepCustomProtoUnmarshal-4 1000000 1734 ns/op 104.34 MB/s 20 | BenchmarkNinOptNativeUnionProtoUnmarshal-4 10000000 186 ns/op 166.02 MB/s 21 | BenchmarkNinOptStructUnionProtoUnmarshal-4 5000000 512 ns/op 216.66 MB/s 22 | BenchmarkNinEmbeddedStructUnionProtoUnmarshal-4 2000000 954 ns/op 252.56 MB/s 23 | BenchmarkNinNestedStructUnionProtoUnmarshal-4 2000000 788 ns/op 166.15 MB/s 24 | BenchmarkTreeProtoUnmarshal-4 2000000 790 ns/op 318.98 MB/s 25 | BenchmarkOrBranchProtoUnmarshal-4 1000000 1553 ns/op 353.43 MB/s 26 | BenchmarkAndBranchProtoUnmarshal-4 1000000 1554 ns/op 353.09 MB/s 27 | BenchmarkLeafProtoUnmarshal-4 5000000 642 ns/op 376.78 MB/s 28 | BenchmarkDeepTreeProtoUnmarshal-4 1000000 1236 ns/op 240.13 MB/s 29 | BenchmarkADeepBranchProtoUnmarshal-4 1000000 1493 ns/op 223.62 MB/s 30 | BenchmarkAndDeepBranchProtoUnmarshal-4 1000000 2327 ns/op 272.81 MB/s 31 | BenchmarkDeepLeafProtoUnmarshal-4 1000000 1068 ns/op 271.46 MB/s 32 | BenchmarkNilProtoUnmarshal-4 5000000 396 ns/op 88.30 MB/s 33 | BenchmarkNidOptEnumProtoUnmarshal-4 5000000 410 ns/op 90.10 MB/s 34 | BenchmarkNinOptEnumProtoUnmarshal-4 5000000 448 ns/op 80.25 MB/s 35 | BenchmarkNidRepEnumProtoUnmarshal-4 5000000 672 ns/op 63.91 MB/s 36 | BenchmarkNinRepEnumProtoUnmarshal-4 5000000 667 ns/op 64.38 MB/s 37 | BenchmarkNinOptEnumDefaultProtoUnmarshal-4 5000000 446 ns/op 80.63 MB/s 38 | BenchmarkAnotherNinOptEnumProtoUnmarshal-4 5000000 449 ns/op 80.09 MB/s 39 | BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-4 5000000 449 ns/op 80.08 MB/s 40 | BenchmarkTimerProtoUnmarshal-4 5000000 554 ns/op 189.24 MB/s 41 | BenchmarkMyExtendableProtoUnmarshal-4 1000000 1445 ns/op 55.36 MB/s 42 | BenchmarkOtherExtenableProtoUnmarshal-4 1000000 2544 ns/op 61.70 MB/s 43 | BenchmarkNestedDefinitionProtoUnmarshal-4 1000000 1847 ns/op 246.34 MB/s 44 | BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-4 1000000 1071 ns/op 220.23 MB/s 45 | BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-4 5000000 688 ns/op 308.09 MB/s 46 | BenchmarkNestedScopeProtoUnmarshal-4 1000000 1803 ns/op 247.86 MB/s 47 | BenchmarkNinOptNativeDefaultProtoUnmarshal-4 1000000 1330 ns/op 255.61 MB/s 48 | BenchmarkCustomContainerProtoUnmarshal-4 2000000 803 ns/op 134.48 MB/s 49 | ok code.google.com/p/gogoprotobuf/test/mixbench/testdata 168.327s 50 | -------------------------------------------------------------------------------- /protoc-gen-dgo/plugin/plugin.pb.golden: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-dgo. 2 | // source: code.google.com/p/gogoprotobuf/protoc-gen-dgo/plugin/plugin.proto 3 | // DO NOT EDIT! 4 | 5 | package google_protobuf_compiler 6 | 7 | import proto "code.google.com/p/gogoprotobuf/proto" 8 | import json "encoding/json" 9 | import math "math" 10 | import google_protobuf "code.google.com/p/gogoprotobuf/protoc-gen-dgo/descriptor" 11 | 12 | // Reference proto, json, and math imports to suppress error if they are not otherwise used. 13 | var _ = proto.Marshal 14 | var _ = &json.SyntaxError{} 15 | var _ = math.Inf 16 | 17 | type CodeGeneratorRequest struct { 18 | FileToGenerate []string `protobuf:"bytes,1,rep,name=file_to_generate" json:"file_to_generate,omitempty"` 19 | Parameter *string `protobuf:"bytes,2,opt,name=parameter" json:"parameter,omitempty"` 20 | ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file" json:"proto_file,omitempty"` 21 | XXX_unrecognized []byte `json:"-"` 22 | } 23 | 24 | func (m *CodeGeneratorRequest) Reset() { *m = CodeGeneratorRequest{} } 25 | func (m *CodeGeneratorRequest) String() string { return proto.CompactTextString(m) } 26 | func (*CodeGeneratorRequest) ProtoMessage() {} 27 | 28 | func (m *CodeGeneratorRequest) GetFileToGenerate() []string { 29 | if m != nil { 30 | return m.FileToGenerate 31 | } 32 | return nil 33 | } 34 | 35 | func (m *CodeGeneratorRequest) GetParameter() string { 36 | if m != nil && m.Parameter != nil { 37 | return *m.Parameter 38 | } 39 | return "" 40 | } 41 | 42 | func (m *CodeGeneratorRequest) GetProtoFile() []*google_protobuf.FileDescriptorProto { 43 | if m != nil { 44 | return m.ProtoFile 45 | } 46 | return nil 47 | } 48 | 49 | type CodeGeneratorResponse struct { 50 | Error *string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"` 51 | File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file" json:"file,omitempty"` 52 | XXX_unrecognized []byte `json:"-"` 53 | } 54 | 55 | func (m *CodeGeneratorResponse) Reset() { *m = CodeGeneratorResponse{} } 56 | func (m *CodeGeneratorResponse) String() string { return proto.CompactTextString(m) } 57 | func (*CodeGeneratorResponse) ProtoMessage() {} 58 | 59 | func (m *CodeGeneratorResponse) GetError() string { 60 | if m != nil && m.Error != nil { 61 | return *m.Error 62 | } 63 | return "" 64 | } 65 | 66 | func (m *CodeGeneratorResponse) GetFile() []*CodeGeneratorResponse_File { 67 | if m != nil { 68 | return m.File 69 | } 70 | return nil 71 | } 72 | 73 | type CodeGeneratorResponse_File struct { 74 | Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` 75 | InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point" json:"insertion_point,omitempty"` 76 | Content *string `protobuf:"bytes,15,opt,name=content" json:"content,omitempty"` 77 | XXX_unrecognized []byte `json:"-"` 78 | } 79 | 80 | func (m *CodeGeneratorResponse_File) Reset() { *m = CodeGeneratorResponse_File{} } 81 | func (m *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(m) } 82 | func (*CodeGeneratorResponse_File) ProtoMessage() {} 83 | 84 | func (m *CodeGeneratorResponse_File) GetName() string { 85 | if m != nil && m.Name != nil { 86 | return *m.Name 87 | } 88 | return "" 89 | } 90 | 91 | func (m *CodeGeneratorResponse_File) GetInsertionPoint() string { 92 | if m != nil && m.InsertionPoint != nil { 93 | return *m.InsertionPoint 94 | } 95 | return "" 96 | } 97 | 98 | func (m *CodeGeneratorResponse_File) GetContent() string { 99 | if m != nil && m.Content != nil { 100 | return *m.Content 101 | } 102 | return "" 103 | } 104 | 105 | func init() { 106 | } 107 | -------------------------------------------------------------------------------- /test/tags/tags_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 2 | // http://code.google.com/p/gogoprotobuf/gogoproto 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | package tags 28 | 29 | import ( 30 | "bytes" 31 | "encoding/json" 32 | "encoding/xml" 33 | math_rand "math/rand" 34 | "testing" 35 | "time" 36 | ) 37 | 38 | type MyJson struct { 39 | MyField1 string 40 | MyField2 string 41 | } 42 | 43 | func NewPopulatedMyJson(r randyTags) *MyJson { 44 | this := &MyJson{} 45 | if r.Intn(10) != 0 { 46 | this.MyField1 = randStringTags(r) 47 | } 48 | if r.Intn(10) != 0 { 49 | this.MyField2 = randStringTags(r) 50 | } 51 | return this 52 | } 53 | 54 | func TestJson(t *testing.T) { 55 | popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 56 | msg1 := NewPopulatedMyJson(popr) 57 | data, err := json.Marshal(msg1) 58 | if err != nil { 59 | panic(err) 60 | } 61 | outside := &Outside{} 62 | err = json.Unmarshal(data, outside) 63 | if err != nil { 64 | panic(err) 65 | } 66 | if outside.GetField1() != msg1.MyField1 { 67 | t.Fatalf("proto field1 %s != %s", outside.GetField1(), msg1.MyField1) 68 | } 69 | if outside.GetField2() != msg1.MyField2 { 70 | t.Fatalf("proto field2 %s != %s", outside.GetField2(), msg1.MyField2) 71 | } 72 | data2, err := json.Marshal(outside) 73 | if err != nil { 74 | panic(err) 75 | } 76 | msg2 := &MyJson{} 77 | err = json.Unmarshal(data2, msg2) 78 | if err != nil { 79 | panic(err) 80 | } 81 | if msg2.MyField1 != msg1.MyField1 { 82 | t.Fatalf("proto field1 %s != %s", msg2.MyField1, msg1.MyField1) 83 | } 84 | if msg2.MyField2 != msg1.MyField2 { 85 | t.Fatalf("proto field2 %s != %s", msg2.MyField2, msg1.MyField2) 86 | } 87 | } 88 | 89 | func TestXml(t *testing.T) { 90 | s := "Field1Value" 91 | field1 := "Field1Value" 92 | field2 := "Field2Value" 93 | msg1 := &Outside{} 94 | err := xml.Unmarshal([]byte(s), msg1) 95 | if err != nil { 96 | panic(err) 97 | } 98 | msg2 := &Outside{ 99 | Inside: &Inside{ 100 | Field1: &field1, 101 | }, 102 | Field2: &field2, 103 | } 104 | if msg1.GetField1() != msg2.GetField1() { 105 | t.Fatalf("field1 expected %s got %s", msg2.GetField1(), msg1.GetField1()) 106 | } 107 | if err != nil { 108 | panic(err) 109 | } 110 | data, err := xml.Marshal(msg2) 111 | if err != nil { 112 | panic(err) 113 | } 114 | if !bytes.Equal(data, []byte(s)) { 115 | t.Fatalf("expected %s got %s", s, string(data)) 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /io/uint32.go: -------------------------------------------------------------------------------- 1 | // Extensions for Protocol Buffers to create more go like structures. 2 | // 3 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved. 4 | // http://code.google.com/p/gogoprotobuf/gogoproto 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package io 30 | 31 | import ( 32 | "encoding/binary" 33 | "github.com/dropbox/goprotoc/proto" 34 | "io" 35 | ) 36 | 37 | func NewUint32DelimitedWriter(w io.Writer, byteOrder binary.ByteOrder) WriteCloser { 38 | return &uint32Writer{w, byteOrder, nil} 39 | } 40 | 41 | type uint32Writer struct { 42 | w io.Writer 43 | byteOrder binary.ByteOrder 44 | buffer []byte 45 | } 46 | 47 | func (this *uint32Writer) WriteMsg(msg proto.Message) (err error) { 48 | var data []byte 49 | if m, ok := msg.(marshaler); ok { 50 | n := m.Size() 51 | if n >= len(this.buffer) { 52 | this.buffer = make([]byte, n) 53 | } 54 | _, err = m.MarshalTo(this.buffer) 55 | if err != nil { 56 | return err 57 | } 58 | data = this.buffer[:n] 59 | } else { 60 | data, err = proto.Marshal(msg) 61 | if err != nil { 62 | return err 63 | } 64 | } 65 | length := uint32(len(data)) 66 | if err := binary.Write(this.w, this.byteOrder, &length); err != nil { 67 | return err 68 | } 69 | _, err = this.w.Write(data) 70 | return err 71 | } 72 | 73 | func (this *uint32Writer) Close() error { 74 | if closer, ok := this.w.(io.Closer); ok { 75 | return closer.Close() 76 | } 77 | return nil 78 | } 79 | 80 | type uint32Reader struct { 81 | r io.Reader 82 | byteOrder binary.ByteOrder 83 | lenBuf []byte 84 | buf []byte 85 | maxSize int 86 | } 87 | 88 | func NewUint32DelimitedReader(r io.Reader, byteOrder binary.ByteOrder, maxSize int) ReadCloser { 89 | return &uint32Reader{r, byteOrder, make([]byte, 4), nil, maxSize} 90 | } 91 | 92 | func (this *uint32Reader) ReadMsg(msg proto.Message) error { 93 | if _, err := io.ReadFull(this.r, this.lenBuf); err != nil { 94 | return err 95 | } 96 | length32 := this.byteOrder.Uint32(this.lenBuf) 97 | length := int(length32) 98 | if length < 0 || length > this.maxSize { 99 | return io.ErrShortBuffer 100 | } 101 | if length >= len(this.buf) { 102 | this.buf = make([]byte, length) 103 | } 104 | _, err := io.ReadFull(this.r, this.buf[:length]) 105 | if err != nil { 106 | return err 107 | } 108 | return proto.Unmarshal(this.buf[:length], msg) 109 | } 110 | 111 | func (this *uint32Reader) Close() error { 112 | if closer, ok := this.r.(io.Closer); ok { 113 | return closer.Close() 114 | } 115 | return nil 116 | } 117 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | .PHONY: nuke regenerate tests clean config install install-gen gofmt 33 | 34 | install: 35 | go install ./proto 36 | go install ./gogoproto 37 | go install ./protoc-gen-dgo 38 | 39 | install-gen: 40 | go install ./protoc-gen-dgo 41 | 42 | all: clean install config regenerate gofmt tests 43 | 44 | config: 45 | bash test_init.sh 46 | 47 | clean: 48 | go clean ./... 49 | 50 | nuke: 51 | go clean -i ./... 52 | 53 | gofmt: 54 | gofmt -l -s -w . 55 | 56 | regenerate: 57 | make -C protoc-gen-dgo/descriptor regenerate 58 | make -C protoc-gen-dgo/plugin regenerate 59 | make -C gogoproto regenerate 60 | make -C proto/testdata regenerate 61 | make -C test regenerate 62 | make -C test/example regenerate 63 | make -C test/unrecognized regenerate 64 | make -C test/group regenerate 65 | make -C test/unrecognizedgroup regenerate 66 | make -C test/enumstringer regenerate 67 | make -C test/unmarshalmerge regenerate 68 | make -C test/moredefaults regenerate 69 | make -C test/issue8 regenerate 70 | make -C test/enumprefix regenerate 71 | make -C test/packed regenerate 72 | make -C test/tags regenerate 73 | gofmt -l -s -w . 74 | 75 | tests: 76 | go test -v ./test 77 | go test -v ./proto 78 | go test -v ./io 79 | go test -v ./test/custom 80 | go test -v ./test/embedconflict 81 | go test -v ./test/defaultconflict 82 | go test -v ./test/unrecognized 83 | go test -v ./test/group 84 | go test -v ./test/unrecognizedgroup 85 | go test -v ./test/enumstringer 86 | go test -v ./test/unmarshalmerge 87 | go test -v ./test/moredefaults 88 | go test -v ./test/issue8 89 | go test -v ./test/example 90 | go test -v ./test/dashfilename 91 | go build ./test/enumprefix 92 | go test -v ./test/packed 93 | go test -v ./test/tags 94 | go test -v ./parser 95 | 96 | drone: 97 | sudo apt-get install protobuf-compiler 98 | git clone https://code.google.com/p/gogoprotobuf 99 | (cd $(GOPATH)/src/code.google.com/p/gogoprotobuf && make all) 100 | 101 | testall: tests 102 | make -C protoc-gen-dgo/testdata test 103 | go test -v ./test/mixmatch 104 | 105 | bench: 106 | (cd test/mixbench && go build .) 107 | (cd test/mixbench && ./mixbench) 108 | 109 | -------------------------------------------------------------------------------- /protoc-gen-dgo/testdata/imp.pb.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: imp.proto 3 | // DO NOT EDIT! 4 | 5 | package imp 6 | 7 | import proto "code.google.com/p/goprotobuf/proto" 8 | import "math" 9 | import "os" 10 | import imp1 "imp2.pb" 11 | 12 | // Reference proto & math imports to suppress error if they are not otherwise used. 13 | var _ = proto.GetString 14 | var _ = math.Inf 15 | 16 | // Types from public import imp2.proto 17 | type PubliclyImportedMessage imp1.PubliclyImportedMessage 18 | 19 | func (this *PubliclyImportedMessage) Reset() { (*imp1.PubliclyImportedMessage)(this).Reset() } 20 | func (this *PubliclyImportedMessage) String() string { 21 | return (*imp1.PubliclyImportedMessage)(this).String() 22 | } 23 | 24 | // PubliclyImportedMessage from public import imp.proto 25 | 26 | type ImportedMessage_Owner int32 27 | 28 | const ( 29 | ImportedMessage_DAVE ImportedMessage_Owner = 1 30 | ImportedMessage_MIKE ImportedMessage_Owner = 2 31 | ) 32 | 33 | var ImportedMessage_Owner_name = map[int32]string{ 34 | 1: "DAVE", 35 | 2: "MIKE", 36 | } 37 | var ImportedMessage_Owner_value = map[string]int32{ 38 | "DAVE": 1, 39 | "MIKE": 2, 40 | } 41 | 42 | // NewImportedMessage_Owner is deprecated. Use x.Enum() instead. 43 | func NewImportedMessage_Owner(x ImportedMessage_Owner) *ImportedMessage_Owner { 44 | e := ImportedMessage_Owner(x) 45 | return &e 46 | } 47 | func (x ImportedMessage_Owner) Enum() *ImportedMessage_Owner { 48 | p := new(ImportedMessage_Owner) 49 | *p = x 50 | return p 51 | } 52 | func (x ImportedMessage_Owner) String() string { 53 | return proto.EnumName(ImportedMessage_Owner_name, int32(x)) 54 | } 55 | 56 | type ImportedMessage struct { 57 | Field *int64 `protobuf:"varint,1,req,name=field" json:"field,omitempty"` 58 | XXX_extensions map[int32][]byte `json:",omitempty"` 59 | XXX_unrecognized []byte `json:",omitempty"` 60 | } 61 | 62 | func (this *ImportedMessage) Reset() { *this = ImportedMessage{} } 63 | func (this *ImportedMessage) String() string { return proto.CompactTextString(this) } 64 | 65 | var extRange_ImportedMessage = []proto.ExtensionRange{ 66 | proto.ExtensionRange{90, 100}, 67 | } 68 | 69 | func (*ImportedMessage) ExtensionRangeArray() []proto.ExtensionRange { 70 | return extRange_ImportedMessage 71 | } 72 | func (this *ImportedMessage) ExtensionMap() map[int32][]byte { 73 | if this.XXX_extensions == nil { 74 | this.XXX_extensions = make(map[int32][]byte) 75 | } 76 | return this.XXX_extensions 77 | } 78 | 79 | type ImportedExtendable struct { 80 | XXX_extensions map[int32][]byte `json:",omitempty"` 81 | XXX_unrecognized []byte `json:",omitempty"` 82 | } 83 | 84 | func (this *ImportedExtendable) Reset() { *this = ImportedExtendable{} } 85 | func (this *ImportedExtendable) String() string { return proto.CompactTextString(this) } 86 | 87 | func (this *ImportedExtendable) Marshal() ([]byte, error) { 88 | return proto.MarshalMessageSet(this.ExtensionMap()) 89 | } 90 | func (this *ImportedExtendable) Unmarshal(buf []byte) error { 91 | return proto.UnmarshalMessageSet(buf, this.ExtensionMap()) 92 | } 93 | // ensure ImportedExtendable satisfies proto.Marshaler and proto.Unmarshaler 94 | var _ proto.Marshaler = (*ImportedExtendable)(nil) 95 | var _ proto.Unmarshaler = (*ImportedExtendable)(nil) 96 | 97 | var extRange_ImportedExtendable = []proto.ExtensionRange{ 98 | proto.ExtensionRange{100, 536870911}, 99 | } 100 | 101 | func (*ImportedExtendable) ExtensionRangeArray() []proto.ExtensionRange { 102 | return extRange_ImportedExtendable 103 | } 104 | func (this *ImportedExtendable) ExtensionMap() map[int32][]byte { 105 | if this.XXX_extensions == nil { 106 | this.XXX_extensions = make(map[int32][]byte) 107 | } 108 | return this.XXX_extensions 109 | } 110 | 111 | func init() { 112 | proto.RegisterEnum("imp.ImportedMessage_Owner", ImportedMessage_Owner_name, ImportedMessage_Owner_value) 113 | } 114 | --------------------------------------------------------------------------------