cmd/stdiscosrv: New discovery server (fixes #4618)
This is a new revision of the discovery server. Relevant changes and non-changes: - Protocol towards clients is unchanged. - Recommended large scale design is still to be deployed nehind nginx (I tested, and it's still a lot faster at terminating TLS). - Database backend is leveldb again, only. It scales enough, is easy to setup, and we don't need any backend to take care of. - Server supports replication. This is a simple TCP channel - protect it with a firewall when deploying over the internet. (We deploy this within the same datacenter, and with firewall.) Any incoming client announces are sent over the replication channel(s) to other peer discosrvs. Incoming replication changes are applied to the database as if they came from clients, but without the TLS/certificate overhead. - Metrics are exposed using the prometheus library, when enabled. - The database values and replication protocol is protobuf, because JSON was quite CPU intensive when I tried that and benchmarked it. - The "Retry-After" value for failed lookups gets slowly increased from a default of 120 seconds, by 5 seconds for each failed lookup, independently by each discosrv. This lowers the query load over time for clients that are never seen. The Retry-After maxes out at 3600 after a couple of weeks of this increase. The number of failed lookups is stored in the database, now and then (avoiding making each lookup a database put). All in all this means clients can be pointed towards a cluster using just multiple A / AAAA records to gain both load sharing and redundancy (if one is down, clients will talk to the remaining ones). GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4648
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
*.dat
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
go install github.com/gogo/protobuf/protoc-gen-combo
|
||||
protoc --gogo_out=. --proto_path=../:../../../../:../protobuf/:. thetest.proto
|
||||
protoc-gen-combo --default=false --gogo_out=. --proto_path=../:../../../../:../protobuf/:. thetest.proto
|
||||
cp uuid.go ./combos/both/
|
||||
cp uuid.go ./combos/marshaler/
|
||||
cp uuid.go ./combos/unmarshaler/
|
||||
cp bug_test.go ./combos/both/
|
||||
cp bug_test.go ./combos/marshaler/
|
||||
cp bug_test.go ./combos/unmarshaler/
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. asym.proto)
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package asym;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.testgen_all) = true;
|
||||
|
||||
message M {
|
||||
repeated bytes arr = 1 [(gogoproto.customtype) = "MyType", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message MyType {
|
||||
option (gogoproto.marshaler) = false;
|
||||
option (gogoproto.sizer) = false;
|
||||
option (gogoproto.populate) = false;
|
||||
option (gogoproto.testgen) = false;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package asym
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAsym(t *testing.T) {
|
||||
m := &M{[]MyType{{}, {}}, nil}
|
||||
if err := m.VerboseEqual(m); err != nil {
|
||||
t.Fatalf("should be equal: %v", err)
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: asym.proto
|
||||
|
||||
/*
|
||||
Package asym is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
asym.proto
|
||||
|
||||
It has these top-level messages:
|
||||
M
|
||||
MyType
|
||||
*/
|
||||
package asym
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestMProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &M{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &M{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &M{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestMProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &M{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &M{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedM(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &M{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestMSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=39
|
||||
func TestBugUint32VarintSize(t *testing.T) {
|
||||
temp := uint32(math.MaxUint32)
|
||||
n := &NinOptNative{}
|
||||
n.Field5 = &temp
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != 6 {
|
||||
t.Fatalf("data should be length 6, but its %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBugZeroLengthSliceSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field8: []int64{},
|
||||
}
|
||||
size := n.Size()
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v", len(data), size)
|
||||
}
|
||||
}
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=40
|
||||
func TestBugPackedProtoSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711},
|
||||
Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361},
|
||||
Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8},
|
||||
Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84},
|
||||
Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243},
|
||||
}
|
||||
size := proto.Size(n)
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size)
|
||||
}
|
||||
}
|
||||
|
||||
func testSize(m interface {
|
||||
proto.Message
|
||||
Size() int
|
||||
}, desc string, expected int) ([]byte, error) {
|
||||
data, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
protoSize := proto.Size(m)
|
||||
mSize := m.Size()
|
||||
lenData := len(data)
|
||||
if protoSize != mSize || protoSize != lenData || mSize != lenData {
|
||||
return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData)
|
||||
}
|
||||
if got := protoSize; got != expected {
|
||||
return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := mSize; got != expected {
|
||||
return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := lenData; got != expected {
|
||||
return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func TestInt32Int64Compatibility(t *testing.T) {
|
||||
|
||||
//test nullable int32 and int64
|
||||
|
||||
data1, err := testSize(&NinOptNative{
|
||||
Field3: proto.Int32(-1),
|
||||
}, "nullable", 11)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data1 to unmarshal into 4th field which is an int64
|
||||
data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
u1 := &NinOptNative{}
|
||||
if err = proto.Unmarshal(data1, u1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u1.Equal(&NinOptNative{
|
||||
Field4: proto.Int64(-1),
|
||||
}) {
|
||||
t.Error("nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test non-nullable int32 and int64
|
||||
|
||||
data2, err := testSize(&NidOptNative{
|
||||
Field3: -1,
|
||||
}, "non nullable", 67)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data2 to unmarshal into 4th field which is an int64
|
||||
field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
for i, c := range data2 {
|
||||
if c == field4 {
|
||||
data2[i] = field3
|
||||
} else if c == field3 {
|
||||
data2[i] = field4
|
||||
}
|
||||
}
|
||||
u2 := &NidOptNative{}
|
||||
if err = proto.Unmarshal(data2, u2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u2.Equal(&NidOptNative{
|
||||
Field4: -1,
|
||||
}) {
|
||||
t.Error("non nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test packed repeated int32 and int64
|
||||
|
||||
m4 := &NinRepPackedNative{
|
||||
Field3: []int32{-1},
|
||||
}
|
||||
data4, err := testSize(m4, "packed", 12)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
u4 := &NinRepPackedNative{}
|
||||
if err := proto.Unmarshal(data4, u4); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := u4.VerboseEqual(m4); err != nil {
|
||||
t.Fatalf("%#v", u4)
|
||||
}
|
||||
|
||||
//test repeated int32 and int64
|
||||
|
||||
if _, err := testSize(&NinRepNative{
|
||||
Field3: []int32{-1},
|
||||
}, "repeated", 11); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Logf("tested all")
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsMsgsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
nins := make([]*NinOptNative, rep)
|
||||
for i := range nins {
|
||||
nins[i] = NewPopulatedNinOptNative(r, true)
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldE, nins); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsFieldsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
ints := make([]int64, rep)
|
||||
for i := range ints {
|
||||
ints[i] = r.Int63()
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldD, ints); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-gen-combo
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc-gen-combo --gogo_out=. --version="3.0.0" --proto_path=../../../../../:../../protobuf/:. casttype.proto
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package casttype;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"];
|
||||
optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false];
|
||||
optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false];
|
||||
optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"];
|
||||
optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false];
|
||||
optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"];
|
||||
optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false];
|
||||
optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"];
|
||||
optional bytes NormalBytes = 10;
|
||||
repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<string,uint64> MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"];
|
||||
map<string,uint64> MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<int32,Wilson> MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"];
|
||||
map<int32,Wilson> MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false];
|
||||
optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package casttype;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"];
|
||||
optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false];
|
||||
optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false];
|
||||
optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"];
|
||||
optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false];
|
||||
optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"];
|
||||
optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false];
|
||||
optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"];
|
||||
optional bytes NormalBytes = 10;
|
||||
repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<string,uint64> MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"];
|
||||
map<string,uint64> MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<int32,Wilson> MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"];
|
||||
map<int32,Wilson> MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false];
|
||||
optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
+511
@@ -0,0 +1,511 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/both/casttype.proto
|
||||
|
||||
/*
|
||||
Package casttype is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/both/casttype.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package casttype
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCasttypeDescription(t *testing.T) {
|
||||
CasttypeDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package casttype;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"];
|
||||
optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false];
|
||||
optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false];
|
||||
optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"];
|
||||
optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false];
|
||||
optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"];
|
||||
optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false];
|
||||
optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"];
|
||||
optional bytes NormalBytes = 10;
|
||||
repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<string,uint64> MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"];
|
||||
map<string,uint64> MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<int32,Wilson> MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"];
|
||||
map<int32,Wilson> MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false];
|
||||
optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
Generated
Vendored
+511
@@ -0,0 +1,511 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/marshaler/casttype.proto
|
||||
|
||||
/*
|
||||
Package casttype is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/marshaler/casttype.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package casttype
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCasttypeDescription(t *testing.T) {
|
||||
CasttypeDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package casttype;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"];
|
||||
optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false];
|
||||
optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false];
|
||||
optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"];
|
||||
optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false];
|
||||
optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"];
|
||||
optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false];
|
||||
optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"];
|
||||
optional bytes NormalBytes = 10;
|
||||
repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<string,uint64> MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"];
|
||||
map<string,uint64> MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<int32,Wilson> MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"];
|
||||
map<int32,Wilson> MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false];
|
||||
optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
+455
@@ -0,0 +1,455 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/neither/casttype.proto
|
||||
|
||||
/*
|
||||
Package casttype is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/neither/casttype.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package casttype
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCasttypeDescription(t *testing.T) {
|
||||
CasttypeDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package casttype;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"];
|
||||
optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false];
|
||||
optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false];
|
||||
optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"];
|
||||
optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false];
|
||||
optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"];
|
||||
optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false];
|
||||
optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"];
|
||||
optional bytes NormalBytes = 10;
|
||||
repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<string,uint64> MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"];
|
||||
map<string,uint64> MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"];
|
||||
map<int32,Wilson> MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"];
|
||||
map<int32,Wilson> MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false];
|
||||
optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
Generated
Vendored
+455
@@ -0,0 +1,455 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/unmarshaler/casttype.proto
|
||||
|
||||
/*
|
||||
Package casttype is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/unmarshaler/casttype.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package casttype
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCasttypeDescription(t *testing.T) {
|
||||
CasttypeDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
rm -rf combos
|
||||
go install github.com/gogo/protobuf/protoc-gen-combo
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. castvalue.proto
|
||||
protoc-gen-combo --default=false --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. castvalue.proto
|
||||
cp mytypes.go ./combos/both/ || true
|
||||
cp mytypes.go ./combos/marshaler/ || true
|
||||
cp mytypes.go ./combos/unmarshaler/ || true
|
||||
cp mytypes.go ./combos/unsafeboth/ || true
|
||||
cp mytypes.go ./combos/unsafemarshaler/ || true
|
||||
cp mytypes.go ./combos/unsafeunmarshaler/ || true
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package castvalue;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
map<int32,Wilson> CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false];
|
||||
map<int32,Wilson> CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
+455
@@ -0,0 +1,455 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: castvalue.proto
|
||||
|
||||
/*
|
||||
Package castvalue is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
castvalue.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package castvalue
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastvalueDescription(t *testing.T) {
|
||||
CastvalueDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package castvalue;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
map<int32,Wilson> CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false];
|
||||
map<int32,Wilson> CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
+511
@@ -0,0 +1,511 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/both/castvalue.proto
|
||||
|
||||
/*
|
||||
Package castvalue is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/both/castvalue.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package castvalue
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastvalueDescription(t *testing.T) {
|
||||
CastvalueDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package castvalue;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
map<int32,Wilson> CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false];
|
||||
map<int32,Wilson> CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
Generated
Vendored
+511
@@ -0,0 +1,511 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/marshaler/castvalue.proto
|
||||
|
||||
/*
|
||||
Package castvalue is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/marshaler/castvalue.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package castvalue
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastvalueDescription(t *testing.T) {
|
||||
CastvalueDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
Generated
Vendored
+66
@@ -0,0 +1,66 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package castvalue;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message Castaway {
|
||||
map<int32,Wilson> CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false];
|
||||
map<int32,Wilson> CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"];
|
||||
}
|
||||
|
||||
message Wilson {
|
||||
optional int64 Int64 = 1;
|
||||
}
|
||||
Generated
Vendored
+455
@@ -0,0 +1,455 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: combos/unmarshaler/castvalue.proto
|
||||
|
||||
/*
|
||||
Package castvalue is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
combos/unmarshaler/castvalue.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Castaway
|
||||
Wilson
|
||||
*/
|
||||
package castvalue
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestCastawayProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Castaway{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Wilson{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastawayProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Castaway{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWilsonProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Wilson{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastvalueDescription(t *testing.T) {
|
||||
CastvalueDescription()
|
||||
}
|
||||
func TestCastawayVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Castaway{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestWilsonVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Wilson{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestCastawayFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestWilsonFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestCastawayGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestWilsonGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestCastawaySize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedCastaway(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCastawaySize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Castaway, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedCastaway(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestWilsonSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedWilson(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWilsonSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Wilson, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedWilson(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestCastawayStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedCastaway(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestWilsonStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedWilson(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=39
|
||||
func TestBugUint32VarintSize(t *testing.T) {
|
||||
temp := uint32(math.MaxUint32)
|
||||
n := &NinOptNative{}
|
||||
n.Field5 = &temp
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != 6 {
|
||||
t.Fatalf("data should be length 6, but its %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBugZeroLengthSliceSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field8: []int64{},
|
||||
}
|
||||
size := n.Size()
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v", len(data), size)
|
||||
}
|
||||
}
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=40
|
||||
func TestBugPackedProtoSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711},
|
||||
Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361},
|
||||
Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8},
|
||||
Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84},
|
||||
Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243},
|
||||
}
|
||||
size := proto.Size(n)
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size)
|
||||
}
|
||||
}
|
||||
|
||||
func testSize(m interface {
|
||||
proto.Message
|
||||
Size() int
|
||||
}, desc string, expected int) ([]byte, error) {
|
||||
data, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
protoSize := proto.Size(m)
|
||||
mSize := m.Size()
|
||||
lenData := len(data)
|
||||
if protoSize != mSize || protoSize != lenData || mSize != lenData {
|
||||
return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData)
|
||||
}
|
||||
if got := protoSize; got != expected {
|
||||
return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := mSize; got != expected {
|
||||
return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := lenData; got != expected {
|
||||
return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func TestInt32Int64Compatibility(t *testing.T) {
|
||||
|
||||
//test nullable int32 and int64
|
||||
|
||||
data1, err := testSize(&NinOptNative{
|
||||
Field3: proto.Int32(-1),
|
||||
}, "nullable", 11)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data1 to unmarshal into 4th field which is an int64
|
||||
data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
u1 := &NinOptNative{}
|
||||
if err = proto.Unmarshal(data1, u1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u1.Equal(&NinOptNative{
|
||||
Field4: proto.Int64(-1),
|
||||
}) {
|
||||
t.Error("nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test non-nullable int32 and int64
|
||||
|
||||
data2, err := testSize(&NidOptNative{
|
||||
Field3: -1,
|
||||
}, "non nullable", 67)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data2 to unmarshal into 4th field which is an int64
|
||||
field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
for i, c := range data2 {
|
||||
if c == field4 {
|
||||
data2[i] = field3
|
||||
} else if c == field3 {
|
||||
data2[i] = field4
|
||||
}
|
||||
}
|
||||
u2 := &NidOptNative{}
|
||||
if err = proto.Unmarshal(data2, u2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u2.Equal(&NidOptNative{
|
||||
Field4: -1,
|
||||
}) {
|
||||
t.Error("non nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test packed repeated int32 and int64
|
||||
|
||||
m4 := &NinRepPackedNative{
|
||||
Field3: []int32{-1},
|
||||
}
|
||||
data4, err := testSize(m4, "packed", 12)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
u4 := &NinRepPackedNative{}
|
||||
if err := proto.Unmarshal(data4, u4); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := u4.VerboseEqual(m4); err != nil {
|
||||
t.Fatalf("%#v", u4)
|
||||
}
|
||||
|
||||
//test repeated int32 and int64
|
||||
|
||||
if _, err := testSize(&NinRepNative{
|
||||
Field3: []int32{-1},
|
||||
}, "repeated", 11); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Logf("tested all")
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsMsgsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
nins := make([]*NinOptNative, rep)
|
||||
for i := range nins {
|
||||
nins[i] = NewPopulatedNinOptNative(r, true)
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldE, nins); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsFieldsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
ints := make([]int64, rep)
|
||||
for i := range ints {
|
||||
ints[i] = r.Int63()
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldD, ints); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
+649
@@ -0,0 +1,649 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package test;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.protosizer_all) = false;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
option (gogoproto.compare_all) = true;
|
||||
|
||||
message NidOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
optional int32 Field3 = 3 [(gogoproto.nullable) = false];
|
||||
optional int64 Field4 = 4 [(gogoproto.nullable) = false];
|
||||
optional uint32 Field5 = 5 [(gogoproto.nullable) = false];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
optional sint64 Field8 = 8 [(gogoproto.nullable) = false];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.nullable) = false];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.nullable) = false];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptNative {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional sint64 Field8 = 8;
|
||||
optional fixed32 Field9 = 9;
|
||||
optional sfixed32 Field10 = 10;
|
||||
optional fixed64 Field11 = 11;
|
||||
optional sfixed64 Field12 = 12;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepNative {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated int32 Field3 = 3 [(gogoproto.nullable) = false];
|
||||
repeated int64 Field4 = 4 [(gogoproto.nullable) = false];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.nullable) = false];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.nullable) = false];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
repeated string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
repeated bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepNative {
|
||||
repeated double Field1 = 1;
|
||||
repeated float Field2 = 2;
|
||||
repeated int32 Field3 = 3;
|
||||
repeated int64 Field4 = 4;
|
||||
repeated uint32 Field5 = 5;
|
||||
repeated uint64 Field6 = 6;
|
||||
repeated sint32 Field7 = 7;
|
||||
repeated sint64 Field8 = 8;
|
||||
repeated fixed32 Field9 = 9;
|
||||
repeated sfixed32 Field10 = 10;
|
||||
repeated fixed64 Field11 = 11;
|
||||
repeated sfixed64 Field12 = 12;
|
||||
repeated bool Field13 = 13;
|
||||
repeated string Field14 = 14;
|
||||
repeated bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepPackedNative {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true];
|
||||
}
|
||||
|
||||
message NinRepPackedNative {
|
||||
repeated double Field1 = 1 [packed = true];
|
||||
repeated float Field2 = 2 [packed = true];
|
||||
repeated int32 Field3 = 3 [packed = true];
|
||||
repeated int64 Field4 = 4 [packed = true];
|
||||
repeated uint32 Field5 = 5 [packed = true];
|
||||
repeated uint64 Field6 = 6 [packed = true];
|
||||
repeated sint32 Field7 = 7 [packed = true];
|
||||
repeated sint64 Field8 = 8 [packed = true];
|
||||
repeated fixed32 Field9 = 9 [packed = true];
|
||||
repeated sfixed32 Field10 = 10 [packed = true];
|
||||
repeated fixed64 Field11 = 11 [packed = true];
|
||||
repeated sfixed64 Field12 = 12 [packed = true];
|
||||
repeated bool Field13 = 13 [packed = true];
|
||||
}
|
||||
|
||||
message NidOptStruct {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false];
|
||||
optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptStruct {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NidOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional NidOptNative Field8 = 8;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepStruct {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false];
|
||||
repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
repeated string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
repeated bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepStruct {
|
||||
repeated double Field1 = 1;
|
||||
repeated float Field2 = 2;
|
||||
repeated NidOptNative Field3 = 3;
|
||||
repeated NinOptNative Field4 = 4;
|
||||
repeated uint64 Field6 = 6;
|
||||
repeated sint32 Field7 = 7;
|
||||
repeated NidOptNative Field8 = 8;
|
||||
repeated bool Field13 = 13;
|
||||
repeated string Field14 = 14;
|
||||
repeated bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidEmbeddedStruct {
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false];
|
||||
optional bool Field210 = 210 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinEmbeddedStruct {
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NidOptNative Field200 = 200;
|
||||
optional bool Field210 = 210;
|
||||
}
|
||||
|
||||
message NidNestedStruct {
|
||||
optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinNestedStruct {
|
||||
optional NinOptStruct Field1 = 1;
|
||||
repeated NinRepStruct Field2 = 2;
|
||||
}
|
||||
|
||||
message NidOptCustom {
|
||||
optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
|
||||
optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message CustomDash {
|
||||
optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"];
|
||||
}
|
||||
|
||||
message NinOptCustom {
|
||||
optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"];
|
||||
optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message NidRepCustom {
|
||||
repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
|
||||
repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepCustom {
|
||||
repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"];
|
||||
repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message NinOptNativeUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinOptStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NidOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinEmbeddedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NinOptNative Field200 = 200;
|
||||
optional bool Field210 = 210;
|
||||
}
|
||||
|
||||
message NinNestedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NinOptNativeUnion Field1 = 1;
|
||||
optional NinOptStructUnion Field2 = 2;
|
||||
optional NinEmbeddedStructUnion Field3 = 3;
|
||||
}
|
||||
|
||||
message Tree {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional OrBranch Or = 1;
|
||||
optional AndBranch And = 2;
|
||||
optional Leaf Leaf = 3;
|
||||
}
|
||||
|
||||
message OrBranch {
|
||||
optional Tree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional Tree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message AndBranch {
|
||||
optional Tree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional Tree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message Leaf {
|
||||
optional int64 Value = 1 [(gogoproto.nullable) = false];
|
||||
optional string StrValue = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeepTree {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional ADeepBranch Down = 1;
|
||||
optional AndDeepBranch And = 2;
|
||||
optional DeepLeaf Leaf = 3;
|
||||
}
|
||||
|
||||
message ADeepBranch {
|
||||
optional DeepTree Down = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message AndDeepBranch {
|
||||
optional DeepTree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional DeepTree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeepLeaf {
|
||||
optional Tree Tree = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message Nil {
|
||||
|
||||
}
|
||||
|
||||
enum TheTestEnum {
|
||||
A = 0;
|
||||
B = 1;
|
||||
C = 2;
|
||||
}
|
||||
|
||||
enum AnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
D = 10;
|
||||
E = 11;
|
||||
}
|
||||
|
||||
// YetAnotherTestEnum is used to test cross-package import of custom name
|
||||
// fields and default resolution.
|
||||
enum YetAnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
AA = 0;
|
||||
BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"];
|
||||
}
|
||||
|
||||
// YetAnotherTestEnum is used to test cross-package import of custom name
|
||||
// fields and default resolution.
|
||||
enum YetYetAnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = true;
|
||||
CC = 0;
|
||||
DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"];
|
||||
}
|
||||
|
||||
message NidOptEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptEnum {
|
||||
optional TheTestEnum Field1 = 1;
|
||||
optional YetAnotherTestEnum Field2 = 2;
|
||||
optional YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message NidRepEnum {
|
||||
repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepEnum {
|
||||
repeated TheTestEnum Field1 = 1;
|
||||
repeated YetAnotherTestEnum Field2 = 2;
|
||||
repeated YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message NinOptEnumDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional TheTestEnum Field1 = 1 [default=C];
|
||||
optional YetAnotherTestEnum Field2 = 2 [default=BB];
|
||||
optional YetYetAnotherTestEnum Field3 = 3 [default=CC];
|
||||
}
|
||||
|
||||
message AnotherNinOptEnum {
|
||||
optional AnotherTestEnum Field1 = 1;
|
||||
optional YetAnotherTestEnum Field2 = 2;
|
||||
optional YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message AnotherNinOptEnumDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional AnotherTestEnum Field1 = 1 [default=E];
|
||||
optional YetAnotherTestEnum Field2 = 2 [default=BB];
|
||||
optional YetYetAnotherTestEnum Field3 = 3 [default=CC];
|
||||
}
|
||||
|
||||
|
||||
message Timer {
|
||||
optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false];
|
||||
optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false];
|
||||
optional bytes Data = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message MyExtendable {
|
||||
option (gogoproto.face) = false;
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend MyExtendable {
|
||||
optional double FieldA = 100;
|
||||
optional NinOptNative FieldB = 101;
|
||||
optional NinEmbeddedStruct FieldC = 102;
|
||||
repeated int64 FieldD = 104;
|
||||
repeated NinOptNative FieldE = 105;
|
||||
}
|
||||
|
||||
message OtherExtenable {
|
||||
option (gogoproto.face) = false;
|
||||
optional int64 Field2 = 2;
|
||||
extensions 14 to 16;
|
||||
optional int64 Field13 = 13;
|
||||
extensions 10 to 12;
|
||||
optional MyExtendable M = 1;
|
||||
}
|
||||
|
||||
message NestedDefinition {
|
||||
optional int64 Field1 = 1;
|
||||
message NestedMessage {
|
||||
optional fixed64 NestedField1 = 1;
|
||||
optional NestedNestedMsg NNM = 2;
|
||||
message NestedNestedMsg {
|
||||
optional string NestedNestedField1 = 10;
|
||||
}
|
||||
}
|
||||
enum NestedEnum {
|
||||
TYPE_NESTED = 1;
|
||||
}
|
||||
optional NestedEnum EnumField = 2;
|
||||
optional NestedMessage.NestedNestedMsg NNM = 3;
|
||||
optional NestedMessage NM = 4;
|
||||
}
|
||||
|
||||
message NestedScope {
|
||||
optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1;
|
||||
optional NestedDefinition.NestedEnum B = 2;
|
||||
optional NestedDefinition.NestedMessage C = 3;
|
||||
}
|
||||
|
||||
message NinOptNativeDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional double Field1 = 1 [default = 1234.1234];
|
||||
optional float Field2 = 2 [default = 1234.1234];
|
||||
optional int32 Field3 = 3 [default = 1234];
|
||||
optional int64 Field4 = 4 [default = 1234];
|
||||
optional uint32 Field5 = 5 [default = 1234];
|
||||
optional uint64 Field6 = 6 [default = 1234];
|
||||
optional sint32 Field7 = 7 [default = 1234];
|
||||
optional sint64 Field8 = 8 [default = 1234];
|
||||
optional fixed32 Field9 = 9 [default = 1234];
|
||||
optional sfixed32 Field10 = 10 [default = 1234];
|
||||
optional fixed64 Field11 = 11 [default = 1234];
|
||||
optional sfixed64 Field12 = 12 [default = 1234];
|
||||
optional bool Field13 = 13 [default = true];
|
||||
optional string Field14 = 14 [default = "1234"];
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message CustomContainer {
|
||||
optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message CustomNameNidOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"];
|
||||
optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"];
|
||||
optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"];
|
||||
optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"];
|
||||
optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"];
|
||||
optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"];
|
||||
optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"];
|
||||
optional string Field14 = 14 [(gogoproto.customname) = "FieldN"];
|
||||
optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinRepNative {
|
||||
repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"];
|
||||
repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"];
|
||||
repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"];
|
||||
repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinStruct {
|
||||
optional double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"];
|
||||
optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"];
|
||||
optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"];
|
||||
optional string Field14 = 14 [(gogoproto.customname) = "FieldI"];
|
||||
optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"];
|
||||
}
|
||||
|
||||
message CustomNameCustomType {
|
||||
optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"];
|
||||
optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"];
|
||||
repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message CustomNameNinEmbeddedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"];
|
||||
optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"];
|
||||
}
|
||||
|
||||
message CustomNameEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
}
|
||||
|
||||
message NoExtensionsMap {
|
||||
option (gogoproto.face) = false;
|
||||
option (gogoproto.goproto_extensions_map) = false;
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend NoExtensionsMap {
|
||||
optional double FieldA1 = 100;
|
||||
optional NinOptNative FieldB1 = 101;
|
||||
optional NinEmbeddedStruct FieldC1 = 102;
|
||||
}
|
||||
|
||||
message Unrecognized {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional string Field1 = 1;
|
||||
}
|
||||
|
||||
message UnrecognizedWithInner {
|
||||
message Inner {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 Field1 = 1;
|
||||
}
|
||||
|
||||
repeated Inner embedded = 1;
|
||||
optional string Field2 = 2;
|
||||
}
|
||||
|
||||
message UnrecognizedWithEmbed {
|
||||
message Embedded {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 Field1 = 1;
|
||||
}
|
||||
|
||||
optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
|
||||
optional string Field2 = 2;
|
||||
}
|
||||
|
||||
message Node {
|
||||
optional string Label = 1;
|
||||
repeated Node Children = 2;
|
||||
}
|
||||
|
||||
message NonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message NidOptNonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptNonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message NidRepNonByteCustomType {
|
||||
repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepNonByteCustomType {
|
||||
repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message ProtoType {
|
||||
optional string Field2 = 1;
|
||||
}
|
||||
+17949
File diff suppressed because it is too large
Load Diff
+252
@@ -0,0 +1,252 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=39
|
||||
func TestBugUint32VarintSize(t *testing.T) {
|
||||
temp := uint32(math.MaxUint32)
|
||||
n := &NinOptNative{}
|
||||
n.Field5 = &temp
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != 6 {
|
||||
t.Fatalf("data should be length 6, but its %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBugZeroLengthSliceSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field8: []int64{},
|
||||
}
|
||||
size := n.Size()
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v", len(data), size)
|
||||
}
|
||||
}
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=40
|
||||
func TestBugPackedProtoSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711},
|
||||
Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361},
|
||||
Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8},
|
||||
Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84},
|
||||
Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243},
|
||||
}
|
||||
size := proto.Size(n)
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size)
|
||||
}
|
||||
}
|
||||
|
||||
func testSize(m interface {
|
||||
proto.Message
|
||||
Size() int
|
||||
}, desc string, expected int) ([]byte, error) {
|
||||
data, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
protoSize := proto.Size(m)
|
||||
mSize := m.Size()
|
||||
lenData := len(data)
|
||||
if protoSize != mSize || protoSize != lenData || mSize != lenData {
|
||||
return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData)
|
||||
}
|
||||
if got := protoSize; got != expected {
|
||||
return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := mSize; got != expected {
|
||||
return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := lenData; got != expected {
|
||||
return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func TestInt32Int64Compatibility(t *testing.T) {
|
||||
|
||||
//test nullable int32 and int64
|
||||
|
||||
data1, err := testSize(&NinOptNative{
|
||||
Field3: proto.Int32(-1),
|
||||
}, "nullable", 11)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data1 to unmarshal into 4th field which is an int64
|
||||
data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
u1 := &NinOptNative{}
|
||||
if err = proto.Unmarshal(data1, u1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u1.Equal(&NinOptNative{
|
||||
Field4: proto.Int64(-1),
|
||||
}) {
|
||||
t.Error("nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test non-nullable int32 and int64
|
||||
|
||||
data2, err := testSize(&NidOptNative{
|
||||
Field3: -1,
|
||||
}, "non nullable", 67)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data2 to unmarshal into 4th field which is an int64
|
||||
field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
for i, c := range data2 {
|
||||
if c == field4 {
|
||||
data2[i] = field3
|
||||
} else if c == field3 {
|
||||
data2[i] = field4
|
||||
}
|
||||
}
|
||||
u2 := &NidOptNative{}
|
||||
if err = proto.Unmarshal(data2, u2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u2.Equal(&NidOptNative{
|
||||
Field4: -1,
|
||||
}) {
|
||||
t.Error("non nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test packed repeated int32 and int64
|
||||
|
||||
m4 := &NinRepPackedNative{
|
||||
Field3: []int32{-1},
|
||||
}
|
||||
data4, err := testSize(m4, "packed", 12)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
u4 := &NinRepPackedNative{}
|
||||
if err := proto.Unmarshal(data4, u4); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := u4.VerboseEqual(m4); err != nil {
|
||||
t.Fatalf("%#v", u4)
|
||||
}
|
||||
|
||||
//test repeated int32 and int64
|
||||
|
||||
if _, err := testSize(&NinRepNative{
|
||||
Field3: []int32{-1},
|
||||
}, "repeated", 11); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Logf("tested all")
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsMsgsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
nins := make([]*NinOptNative, rep)
|
||||
for i := range nins {
|
||||
nins[i] = NewPopulatedNinOptNative(r, true)
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldE, nins); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsFieldsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
ints := make([]int64, rep)
|
||||
for i := range ints {
|
||||
ints[i] = r.Int63()
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldD, ints); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
+649
@@ -0,0 +1,649 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package test;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.protosizer_all) = false;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
option (gogoproto.compare_all) = true;
|
||||
|
||||
message NidOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
optional int32 Field3 = 3 [(gogoproto.nullable) = false];
|
||||
optional int64 Field4 = 4 [(gogoproto.nullable) = false];
|
||||
optional uint32 Field5 = 5 [(gogoproto.nullable) = false];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
optional sint64 Field8 = 8 [(gogoproto.nullable) = false];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.nullable) = false];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.nullable) = false];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptNative {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional sint64 Field8 = 8;
|
||||
optional fixed32 Field9 = 9;
|
||||
optional sfixed32 Field10 = 10;
|
||||
optional fixed64 Field11 = 11;
|
||||
optional sfixed64 Field12 = 12;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepNative {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated int32 Field3 = 3 [(gogoproto.nullable) = false];
|
||||
repeated int64 Field4 = 4 [(gogoproto.nullable) = false];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.nullable) = false];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.nullable) = false];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
repeated string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
repeated bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepNative {
|
||||
repeated double Field1 = 1;
|
||||
repeated float Field2 = 2;
|
||||
repeated int32 Field3 = 3;
|
||||
repeated int64 Field4 = 4;
|
||||
repeated uint32 Field5 = 5;
|
||||
repeated uint64 Field6 = 6;
|
||||
repeated sint32 Field7 = 7;
|
||||
repeated sint64 Field8 = 8;
|
||||
repeated fixed32 Field9 = 9;
|
||||
repeated sfixed32 Field10 = 10;
|
||||
repeated fixed64 Field11 = 11;
|
||||
repeated sfixed64 Field12 = 12;
|
||||
repeated bool Field13 = 13;
|
||||
repeated string Field14 = 14;
|
||||
repeated bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepPackedNative {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true];
|
||||
}
|
||||
|
||||
message NinRepPackedNative {
|
||||
repeated double Field1 = 1 [packed = true];
|
||||
repeated float Field2 = 2 [packed = true];
|
||||
repeated int32 Field3 = 3 [packed = true];
|
||||
repeated int64 Field4 = 4 [packed = true];
|
||||
repeated uint32 Field5 = 5 [packed = true];
|
||||
repeated uint64 Field6 = 6 [packed = true];
|
||||
repeated sint32 Field7 = 7 [packed = true];
|
||||
repeated sint64 Field8 = 8 [packed = true];
|
||||
repeated fixed32 Field9 = 9 [packed = true];
|
||||
repeated sfixed32 Field10 = 10 [packed = true];
|
||||
repeated fixed64 Field11 = 11 [packed = true];
|
||||
repeated sfixed64 Field12 = 12 [packed = true];
|
||||
repeated bool Field13 = 13 [packed = true];
|
||||
}
|
||||
|
||||
message NidOptStruct {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false];
|
||||
optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptStruct {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NidOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional NidOptNative Field8 = 8;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepStruct {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false];
|
||||
repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
repeated string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
repeated bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepStruct {
|
||||
repeated double Field1 = 1;
|
||||
repeated float Field2 = 2;
|
||||
repeated NidOptNative Field3 = 3;
|
||||
repeated NinOptNative Field4 = 4;
|
||||
repeated uint64 Field6 = 6;
|
||||
repeated sint32 Field7 = 7;
|
||||
repeated NidOptNative Field8 = 8;
|
||||
repeated bool Field13 = 13;
|
||||
repeated string Field14 = 14;
|
||||
repeated bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidEmbeddedStruct {
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false];
|
||||
optional bool Field210 = 210 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinEmbeddedStruct {
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NidOptNative Field200 = 200;
|
||||
optional bool Field210 = 210;
|
||||
}
|
||||
|
||||
message NidNestedStruct {
|
||||
optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinNestedStruct {
|
||||
optional NinOptStruct Field1 = 1;
|
||||
repeated NinRepStruct Field2 = 2;
|
||||
}
|
||||
|
||||
message NidOptCustom {
|
||||
optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
|
||||
optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message CustomDash {
|
||||
optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"];
|
||||
}
|
||||
|
||||
message NinOptCustom {
|
||||
optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"];
|
||||
optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message NidRepCustom {
|
||||
repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
|
||||
repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepCustom {
|
||||
repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"];
|
||||
repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message NinOptNativeUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinOptStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NidOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinEmbeddedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NinOptNative Field200 = 200;
|
||||
optional bool Field210 = 210;
|
||||
}
|
||||
|
||||
message NinNestedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NinOptNativeUnion Field1 = 1;
|
||||
optional NinOptStructUnion Field2 = 2;
|
||||
optional NinEmbeddedStructUnion Field3 = 3;
|
||||
}
|
||||
|
||||
message Tree {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional OrBranch Or = 1;
|
||||
optional AndBranch And = 2;
|
||||
optional Leaf Leaf = 3;
|
||||
}
|
||||
|
||||
message OrBranch {
|
||||
optional Tree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional Tree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message AndBranch {
|
||||
optional Tree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional Tree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message Leaf {
|
||||
optional int64 Value = 1 [(gogoproto.nullable) = false];
|
||||
optional string StrValue = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeepTree {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional ADeepBranch Down = 1;
|
||||
optional AndDeepBranch And = 2;
|
||||
optional DeepLeaf Leaf = 3;
|
||||
}
|
||||
|
||||
message ADeepBranch {
|
||||
optional DeepTree Down = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message AndDeepBranch {
|
||||
optional DeepTree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional DeepTree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeepLeaf {
|
||||
optional Tree Tree = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message Nil {
|
||||
|
||||
}
|
||||
|
||||
enum TheTestEnum {
|
||||
A = 0;
|
||||
B = 1;
|
||||
C = 2;
|
||||
}
|
||||
|
||||
enum AnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
D = 10;
|
||||
E = 11;
|
||||
}
|
||||
|
||||
// YetAnotherTestEnum is used to test cross-package import of custom name
|
||||
// fields and default resolution.
|
||||
enum YetAnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
AA = 0;
|
||||
BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"];
|
||||
}
|
||||
|
||||
// YetAnotherTestEnum is used to test cross-package import of custom name
|
||||
// fields and default resolution.
|
||||
enum YetYetAnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = true;
|
||||
CC = 0;
|
||||
DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"];
|
||||
}
|
||||
|
||||
message NidOptEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptEnum {
|
||||
optional TheTestEnum Field1 = 1;
|
||||
optional YetAnotherTestEnum Field2 = 2;
|
||||
optional YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message NidRepEnum {
|
||||
repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepEnum {
|
||||
repeated TheTestEnum Field1 = 1;
|
||||
repeated YetAnotherTestEnum Field2 = 2;
|
||||
repeated YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message NinOptEnumDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional TheTestEnum Field1 = 1 [default=C];
|
||||
optional YetAnotherTestEnum Field2 = 2 [default=BB];
|
||||
optional YetYetAnotherTestEnum Field3 = 3 [default=CC];
|
||||
}
|
||||
|
||||
message AnotherNinOptEnum {
|
||||
optional AnotherTestEnum Field1 = 1;
|
||||
optional YetAnotherTestEnum Field2 = 2;
|
||||
optional YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message AnotherNinOptEnumDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional AnotherTestEnum Field1 = 1 [default=E];
|
||||
optional YetAnotherTestEnum Field2 = 2 [default=BB];
|
||||
optional YetYetAnotherTestEnum Field3 = 3 [default=CC];
|
||||
}
|
||||
|
||||
|
||||
message Timer {
|
||||
optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false];
|
||||
optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false];
|
||||
optional bytes Data = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message MyExtendable {
|
||||
option (gogoproto.face) = false;
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend MyExtendable {
|
||||
optional double FieldA = 100;
|
||||
optional NinOptNative FieldB = 101;
|
||||
optional NinEmbeddedStruct FieldC = 102;
|
||||
repeated int64 FieldD = 104;
|
||||
repeated NinOptNative FieldE = 105;
|
||||
}
|
||||
|
||||
message OtherExtenable {
|
||||
option (gogoproto.face) = false;
|
||||
optional int64 Field2 = 2;
|
||||
extensions 14 to 16;
|
||||
optional int64 Field13 = 13;
|
||||
extensions 10 to 12;
|
||||
optional MyExtendable M = 1;
|
||||
}
|
||||
|
||||
message NestedDefinition {
|
||||
optional int64 Field1 = 1;
|
||||
message NestedMessage {
|
||||
optional fixed64 NestedField1 = 1;
|
||||
optional NestedNestedMsg NNM = 2;
|
||||
message NestedNestedMsg {
|
||||
optional string NestedNestedField1 = 10;
|
||||
}
|
||||
}
|
||||
enum NestedEnum {
|
||||
TYPE_NESTED = 1;
|
||||
}
|
||||
optional NestedEnum EnumField = 2;
|
||||
optional NestedMessage.NestedNestedMsg NNM = 3;
|
||||
optional NestedMessage NM = 4;
|
||||
}
|
||||
|
||||
message NestedScope {
|
||||
optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1;
|
||||
optional NestedDefinition.NestedEnum B = 2;
|
||||
optional NestedDefinition.NestedMessage C = 3;
|
||||
}
|
||||
|
||||
message NinOptNativeDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional double Field1 = 1 [default = 1234.1234];
|
||||
optional float Field2 = 2 [default = 1234.1234];
|
||||
optional int32 Field3 = 3 [default = 1234];
|
||||
optional int64 Field4 = 4 [default = 1234];
|
||||
optional uint32 Field5 = 5 [default = 1234];
|
||||
optional uint64 Field6 = 6 [default = 1234];
|
||||
optional sint32 Field7 = 7 [default = 1234];
|
||||
optional sint64 Field8 = 8 [default = 1234];
|
||||
optional fixed32 Field9 = 9 [default = 1234];
|
||||
optional sfixed32 Field10 = 10 [default = 1234];
|
||||
optional fixed64 Field11 = 11 [default = 1234];
|
||||
optional sfixed64 Field12 = 12 [default = 1234];
|
||||
optional bool Field13 = 13 [default = true];
|
||||
optional string Field14 = 14 [default = "1234"];
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message CustomContainer {
|
||||
optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message CustomNameNidOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"];
|
||||
optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"];
|
||||
optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"];
|
||||
optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"];
|
||||
optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"];
|
||||
optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"];
|
||||
optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"];
|
||||
optional string Field14 = 14 [(gogoproto.customname) = "FieldN"];
|
||||
optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinRepNative {
|
||||
repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"];
|
||||
repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"];
|
||||
repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"];
|
||||
repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinStruct {
|
||||
optional double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"];
|
||||
optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"];
|
||||
optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"];
|
||||
optional string Field14 = 14 [(gogoproto.customname) = "FieldI"];
|
||||
optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"];
|
||||
}
|
||||
|
||||
message CustomNameCustomType {
|
||||
optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"];
|
||||
optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"];
|
||||
repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message CustomNameNinEmbeddedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"];
|
||||
optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"];
|
||||
}
|
||||
|
||||
message CustomNameEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
}
|
||||
|
||||
message NoExtensionsMap {
|
||||
option (gogoproto.face) = false;
|
||||
option (gogoproto.goproto_extensions_map) = false;
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend NoExtensionsMap {
|
||||
optional double FieldA1 = 100;
|
||||
optional NinOptNative FieldB1 = 101;
|
||||
optional NinEmbeddedStruct FieldC1 = 102;
|
||||
}
|
||||
|
||||
message Unrecognized {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional string Field1 = 1;
|
||||
}
|
||||
|
||||
message UnrecognizedWithInner {
|
||||
message Inner {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 Field1 = 1;
|
||||
}
|
||||
|
||||
repeated Inner embedded = 1;
|
||||
optional string Field2 = 2;
|
||||
}
|
||||
|
||||
message UnrecognizedWithEmbed {
|
||||
message Embedded {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 Field1 = 1;
|
||||
}
|
||||
|
||||
optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
|
||||
optional string Field2 = 2;
|
||||
}
|
||||
|
||||
message Node {
|
||||
optional string Label = 1;
|
||||
repeated Node Children = 2;
|
||||
}
|
||||
|
||||
message NonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message NidOptNonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptNonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message NidRepNonByteCustomType {
|
||||
repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepNonByteCustomType {
|
||||
repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message ProtoType {
|
||||
optional string Field2 = 1;
|
||||
}
|
||||
+17949
File diff suppressed because it is too large
Load Diff
+252
@@ -0,0 +1,252 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=39
|
||||
func TestBugUint32VarintSize(t *testing.T) {
|
||||
temp := uint32(math.MaxUint32)
|
||||
n := &NinOptNative{}
|
||||
n.Field5 = &temp
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != 6 {
|
||||
t.Fatalf("data should be length 6, but its %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBugZeroLengthSliceSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field8: []int64{},
|
||||
}
|
||||
size := n.Size()
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v", len(data), size)
|
||||
}
|
||||
}
|
||||
|
||||
//http://code.google.com/p/goprotobuf/issues/detail?id=40
|
||||
func TestBugPackedProtoSize(t *testing.T) {
|
||||
n := &NinRepPackedNative{
|
||||
Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711},
|
||||
Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361},
|
||||
Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8},
|
||||
Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84},
|
||||
Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243},
|
||||
}
|
||||
size := proto.Size(n)
|
||||
data, err := proto.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(data) != size {
|
||||
t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size)
|
||||
}
|
||||
}
|
||||
|
||||
func testSize(m interface {
|
||||
proto.Message
|
||||
Size() int
|
||||
}, desc string, expected int) ([]byte, error) {
|
||||
data, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
protoSize := proto.Size(m)
|
||||
mSize := m.Size()
|
||||
lenData := len(data)
|
||||
if protoSize != mSize || protoSize != lenData || mSize != lenData {
|
||||
return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData)
|
||||
}
|
||||
if got := protoSize; got != expected {
|
||||
return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := mSize; got != expected {
|
||||
return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected)
|
||||
}
|
||||
if got := lenData; got != expected {
|
||||
return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func TestInt32Int64Compatibility(t *testing.T) {
|
||||
|
||||
//test nullable int32 and int64
|
||||
|
||||
data1, err := testSize(&NinOptNative{
|
||||
Field3: proto.Int32(-1),
|
||||
}, "nullable", 11)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data1 to unmarshal into 4th field which is an int64
|
||||
data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
u1 := &NinOptNative{}
|
||||
if err = proto.Unmarshal(data1, u1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u1.Equal(&NinOptNative{
|
||||
Field4: proto.Int64(-1),
|
||||
}) {
|
||||
t.Error("nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test non-nullable int32 and int64
|
||||
|
||||
data2, err := testSize(&NidOptNative{
|
||||
Field3: -1,
|
||||
}, "non nullable", 67)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//change marshaled data2 to unmarshal into 4th field which is an int64
|
||||
field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/))
|
||||
for i, c := range data2 {
|
||||
if c == field4 {
|
||||
data2[i] = field3
|
||||
} else if c == field3 {
|
||||
data2[i] = field4
|
||||
}
|
||||
}
|
||||
u2 := &NidOptNative{}
|
||||
if err = proto.Unmarshal(data2, u2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !u2.Equal(&NidOptNative{
|
||||
Field4: -1,
|
||||
}) {
|
||||
t.Error("non nullable unmarshaled int32 is not the same int64")
|
||||
}
|
||||
|
||||
//test packed repeated int32 and int64
|
||||
|
||||
m4 := &NinRepPackedNative{
|
||||
Field3: []int32{-1},
|
||||
}
|
||||
data4, err := testSize(m4, "packed", 12)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
u4 := &NinRepPackedNative{}
|
||||
if err := proto.Unmarshal(data4, u4); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := u4.VerboseEqual(m4); err != nil {
|
||||
t.Fatalf("%#v", u4)
|
||||
}
|
||||
|
||||
//test repeated int32 and int64
|
||||
|
||||
if _, err := testSize(&NinRepNative{
|
||||
Field3: []int32{-1},
|
||||
}, "repeated", 11); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Logf("tested all")
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsMsgsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
nins := make([]*NinOptNative, rep)
|
||||
for i := range nins {
|
||||
nins[i] = NewPopulatedNinOptNative(r, true)
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldE, nins); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatedExtensionsFieldsIssue161(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
rep := 10
|
||||
ints := make([]int64, rep)
|
||||
for i := range ints {
|
||||
ints[i] = r.Int63()
|
||||
}
|
||||
input := &MyExtendable{}
|
||||
if err := proto.SetExtension(input, E_FieldD, ints); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := proto.Marshal(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &MyExtendable{}
|
||||
if err := proto.Unmarshal(data, output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !input.Equal(output) {
|
||||
t.Fatal("expected equal")
|
||||
}
|
||||
data2, err2 := proto.Marshal(output)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
if len(data) != len(data2) {
|
||||
t.Fatal("expected equal length buffers")
|
||||
}
|
||||
}
|
||||
+649
@@ -0,0 +1,649 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package test;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.protosizer_all) = false;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
option (gogoproto.compare_all) = true;
|
||||
|
||||
message NidOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
optional int32 Field3 = 3 [(gogoproto.nullable) = false];
|
||||
optional int64 Field4 = 4 [(gogoproto.nullable) = false];
|
||||
optional uint32 Field5 = 5 [(gogoproto.nullable) = false];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
optional sint64 Field8 = 8 [(gogoproto.nullable) = false];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.nullable) = false];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.nullable) = false];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptNative {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional sint64 Field8 = 8;
|
||||
optional fixed32 Field9 = 9;
|
||||
optional sfixed32 Field10 = 10;
|
||||
optional fixed64 Field11 = 11;
|
||||
optional sfixed64 Field12 = 12;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepNative {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated int32 Field3 = 3 [(gogoproto.nullable) = false];
|
||||
repeated int64 Field4 = 4 [(gogoproto.nullable) = false];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.nullable) = false];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.nullable) = false];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
repeated string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
repeated bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepNative {
|
||||
repeated double Field1 = 1;
|
||||
repeated float Field2 = 2;
|
||||
repeated int32 Field3 = 3;
|
||||
repeated int64 Field4 = 4;
|
||||
repeated uint32 Field5 = 5;
|
||||
repeated uint64 Field6 = 6;
|
||||
repeated sint32 Field7 = 7;
|
||||
repeated sint64 Field8 = 8;
|
||||
repeated fixed32 Field9 = 9;
|
||||
repeated sfixed32 Field10 = 10;
|
||||
repeated fixed64 Field11 = 11;
|
||||
repeated sfixed64 Field12 = 12;
|
||||
repeated bool Field13 = 13;
|
||||
repeated string Field14 = 14;
|
||||
repeated bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepPackedNative {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true];
|
||||
}
|
||||
|
||||
message NinRepPackedNative {
|
||||
repeated double Field1 = 1 [packed = true];
|
||||
repeated float Field2 = 2 [packed = true];
|
||||
repeated int32 Field3 = 3 [packed = true];
|
||||
repeated int64 Field4 = 4 [packed = true];
|
||||
repeated uint32 Field5 = 5 [packed = true];
|
||||
repeated uint64 Field6 = 6 [packed = true];
|
||||
repeated sint32 Field7 = 7 [packed = true];
|
||||
repeated sint64 Field8 = 8 [packed = true];
|
||||
repeated fixed32 Field9 = 9 [packed = true];
|
||||
repeated sfixed32 Field10 = 10 [packed = true];
|
||||
repeated fixed64 Field11 = 11 [packed = true];
|
||||
repeated sfixed64 Field12 = 12 [packed = true];
|
||||
repeated bool Field13 = 13 [packed = true];
|
||||
}
|
||||
|
||||
message NidOptStruct {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false];
|
||||
optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptStruct {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NidOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional NidOptNative Field8 = 8;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidRepStruct {
|
||||
repeated double Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated float Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false];
|
||||
repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.nullable) = false];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.nullable) = false];
|
||||
repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false];
|
||||
repeated bool Field13 = 13 [(gogoproto.nullable) = false];
|
||||
repeated string Field14 = 14 [(gogoproto.nullable) = false];
|
||||
repeated bytes Field15 = 15 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepStruct {
|
||||
repeated double Field1 = 1;
|
||||
repeated float Field2 = 2;
|
||||
repeated NidOptNative Field3 = 3;
|
||||
repeated NinOptNative Field4 = 4;
|
||||
repeated uint64 Field6 = 6;
|
||||
repeated sint32 Field7 = 7;
|
||||
repeated NidOptNative Field8 = 8;
|
||||
repeated bool Field13 = 13;
|
||||
repeated string Field14 = 14;
|
||||
repeated bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NidEmbeddedStruct {
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false];
|
||||
optional bool Field210 = 210 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinEmbeddedStruct {
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NidOptNative Field200 = 200;
|
||||
optional bool Field210 = 210;
|
||||
}
|
||||
|
||||
message NidNestedStruct {
|
||||
optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinNestedStruct {
|
||||
optional NinOptStruct Field1 = 1;
|
||||
repeated NinRepStruct Field2 = 2;
|
||||
}
|
||||
|
||||
message NidOptCustom {
|
||||
optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
|
||||
optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message CustomDash {
|
||||
optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"];
|
||||
}
|
||||
|
||||
message NinOptCustom {
|
||||
optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"];
|
||||
optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message NidRepCustom {
|
||||
repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
|
||||
repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepCustom {
|
||||
repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"];
|
||||
repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message NinOptNativeUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinOptStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NidOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinEmbeddedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NinOptNative Field200 = 200;
|
||||
optional bool Field210 = 210;
|
||||
}
|
||||
|
||||
message NinNestedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NinOptNativeUnion Field1 = 1;
|
||||
optional NinOptStructUnion Field2 = 2;
|
||||
optional NinEmbeddedStructUnion Field3 = 3;
|
||||
}
|
||||
|
||||
message Tree {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional OrBranch Or = 1;
|
||||
optional AndBranch And = 2;
|
||||
optional Leaf Leaf = 3;
|
||||
}
|
||||
|
||||
message OrBranch {
|
||||
optional Tree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional Tree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message AndBranch {
|
||||
optional Tree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional Tree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message Leaf {
|
||||
optional int64 Value = 1 [(gogoproto.nullable) = false];
|
||||
optional string StrValue = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeepTree {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional ADeepBranch Down = 1;
|
||||
optional AndDeepBranch And = 2;
|
||||
optional DeepLeaf Leaf = 3;
|
||||
}
|
||||
|
||||
message ADeepBranch {
|
||||
optional DeepTree Down = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message AndDeepBranch {
|
||||
optional DeepTree Left = 1 [(gogoproto.nullable) = false];
|
||||
optional DeepTree Right = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeepLeaf {
|
||||
optional Tree Tree = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message Nil {
|
||||
|
||||
}
|
||||
|
||||
enum TheTestEnum {
|
||||
A = 0;
|
||||
B = 1;
|
||||
C = 2;
|
||||
}
|
||||
|
||||
enum AnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
D = 10;
|
||||
E = 11;
|
||||
}
|
||||
|
||||
// YetAnotherTestEnum is used to test cross-package import of custom name
|
||||
// fields and default resolution.
|
||||
enum YetAnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
AA = 0;
|
||||
BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"];
|
||||
}
|
||||
|
||||
// YetAnotherTestEnum is used to test cross-package import of custom name
|
||||
// fields and default resolution.
|
||||
enum YetYetAnotherTestEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = true;
|
||||
CC = 0;
|
||||
DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"];
|
||||
}
|
||||
|
||||
message NidOptEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptEnum {
|
||||
optional TheTestEnum Field1 = 1;
|
||||
optional YetAnotherTestEnum Field2 = 2;
|
||||
optional YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message NidRepEnum {
|
||||
repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false];
|
||||
repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepEnum {
|
||||
repeated TheTestEnum Field1 = 1;
|
||||
repeated YetAnotherTestEnum Field2 = 2;
|
||||
repeated YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message NinOptEnumDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional TheTestEnum Field1 = 1 [default=C];
|
||||
optional YetAnotherTestEnum Field2 = 2 [default=BB];
|
||||
optional YetYetAnotherTestEnum Field3 = 3 [default=CC];
|
||||
}
|
||||
|
||||
message AnotherNinOptEnum {
|
||||
optional AnotherTestEnum Field1 = 1;
|
||||
optional YetAnotherTestEnum Field2 = 2;
|
||||
optional YetYetAnotherTestEnum Field3 = 3;
|
||||
}
|
||||
|
||||
message AnotherNinOptEnumDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional AnotherTestEnum Field1 = 1 [default=E];
|
||||
optional YetAnotherTestEnum Field2 = 2 [default=BB];
|
||||
optional YetYetAnotherTestEnum Field3 = 3 [default=CC];
|
||||
}
|
||||
|
||||
|
||||
message Timer {
|
||||
optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false];
|
||||
optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false];
|
||||
optional bytes Data = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message MyExtendable {
|
||||
option (gogoproto.face) = false;
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend MyExtendable {
|
||||
optional double FieldA = 100;
|
||||
optional NinOptNative FieldB = 101;
|
||||
optional NinEmbeddedStruct FieldC = 102;
|
||||
repeated int64 FieldD = 104;
|
||||
repeated NinOptNative FieldE = 105;
|
||||
}
|
||||
|
||||
message OtherExtenable {
|
||||
option (gogoproto.face) = false;
|
||||
optional int64 Field2 = 2;
|
||||
extensions 14 to 16;
|
||||
optional int64 Field13 = 13;
|
||||
extensions 10 to 12;
|
||||
optional MyExtendable M = 1;
|
||||
}
|
||||
|
||||
message NestedDefinition {
|
||||
optional int64 Field1 = 1;
|
||||
message NestedMessage {
|
||||
optional fixed64 NestedField1 = 1;
|
||||
optional NestedNestedMsg NNM = 2;
|
||||
message NestedNestedMsg {
|
||||
optional string NestedNestedField1 = 10;
|
||||
}
|
||||
}
|
||||
enum NestedEnum {
|
||||
TYPE_NESTED = 1;
|
||||
}
|
||||
optional NestedEnum EnumField = 2;
|
||||
optional NestedMessage.NestedNestedMsg NNM = 3;
|
||||
optional NestedMessage NM = 4;
|
||||
}
|
||||
|
||||
message NestedScope {
|
||||
optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1;
|
||||
optional NestedDefinition.NestedEnum B = 2;
|
||||
optional NestedDefinition.NestedMessage C = 3;
|
||||
}
|
||||
|
||||
message NinOptNativeDefault {
|
||||
option (gogoproto.goproto_getters) = true;
|
||||
option (gogoproto.face) = false;
|
||||
optional double Field1 = 1 [default = 1234.1234];
|
||||
optional float Field2 = 2 [default = 1234.1234];
|
||||
optional int32 Field3 = 3 [default = 1234];
|
||||
optional int64 Field4 = 4 [default = 1234];
|
||||
optional uint32 Field5 = 5 [default = 1234];
|
||||
optional uint64 Field6 = 6 [default = 1234];
|
||||
optional sint32 Field7 = 7 [default = 1234];
|
||||
optional sint64 Field8 = 8 [default = 1234];
|
||||
optional fixed32 Field9 = 9 [default = 1234];
|
||||
optional sfixed32 Field10 = 10 [default = 1234];
|
||||
optional fixed64 Field11 = 11 [default = 1234];
|
||||
optional sfixed64 Field12 = 12 [default = 1234];
|
||||
optional bool Field13 = 13 [default = true];
|
||||
optional string Field14 = 14 [default = "1234"];
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message CustomContainer {
|
||||
optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message CustomNameNidOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"];
|
||||
optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"];
|
||||
optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"];
|
||||
optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"];
|
||||
optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"];
|
||||
optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"];
|
||||
optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"];
|
||||
optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinOptNative {
|
||||
optional double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"];
|
||||
optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"];
|
||||
optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"];
|
||||
optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"];
|
||||
optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"];
|
||||
optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"];
|
||||
optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"];
|
||||
optional string Field14 = 14 [(gogoproto.customname) = "FieldN"];
|
||||
optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinRepNative {
|
||||
repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"];
|
||||
repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"];
|
||||
repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"];
|
||||
repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"];
|
||||
repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"];
|
||||
repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"];
|
||||
repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"];
|
||||
repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"];
|
||||
repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"];
|
||||
repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"];
|
||||
repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"];
|
||||
}
|
||||
|
||||
message CustomNameNinStruct {
|
||||
optional double Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
optional float Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"];
|
||||
repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"];
|
||||
optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"];
|
||||
optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"];
|
||||
optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"];
|
||||
optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"];
|
||||
optional string Field14 = 14 [(gogoproto.customname) = "FieldI"];
|
||||
optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"];
|
||||
}
|
||||
|
||||
message CustomNameCustomType {
|
||||
optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"];
|
||||
optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"];
|
||||
repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"];
|
||||
}
|
||||
|
||||
message CustomNameNinEmbeddedStructUnion {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional NidOptNative Field1 = 1 [(gogoproto.embed) = true];
|
||||
optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"];
|
||||
optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"];
|
||||
}
|
||||
|
||||
message CustomNameEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"];
|
||||
repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"];
|
||||
}
|
||||
|
||||
message NoExtensionsMap {
|
||||
option (gogoproto.face) = false;
|
||||
option (gogoproto.goproto_extensions_map) = false;
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend NoExtensionsMap {
|
||||
optional double FieldA1 = 100;
|
||||
optional NinOptNative FieldB1 = 101;
|
||||
optional NinEmbeddedStruct FieldC1 = 102;
|
||||
}
|
||||
|
||||
message Unrecognized {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional string Field1 = 1;
|
||||
}
|
||||
|
||||
message UnrecognizedWithInner {
|
||||
message Inner {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 Field1 = 1;
|
||||
}
|
||||
|
||||
repeated Inner embedded = 1;
|
||||
optional string Field2 = 2;
|
||||
}
|
||||
|
||||
message UnrecognizedWithEmbed {
|
||||
message Embedded {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 Field1 = 1;
|
||||
}
|
||||
|
||||
optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
|
||||
optional string Field2 = 2;
|
||||
}
|
||||
|
||||
message Node {
|
||||
optional string Label = 1;
|
||||
repeated Node Children = 2;
|
||||
}
|
||||
|
||||
message NonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message NidOptNonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptNonByteCustomType {
|
||||
optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message NidRepNonByteCustomType {
|
||||
repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepNonByteCustomType {
|
||||
repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"];
|
||||
}
|
||||
|
||||
message ProtoType {
|
||||
optional string Field2 = 1;
|
||||
}
|
||||
+16045
File diff suppressed because it is too large
Load Diff
+43
@@ -0,0 +1,43 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package custom
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUint128(t *testing.T) {
|
||||
var uint128a = Uint128{0, 1}
|
||||
buf := make([]byte, 16)
|
||||
PutLittleEndianUint128(buf, 0, uint128a)
|
||||
uint128b := GetLittleEndianUint128(buf, 0)
|
||||
if !uint128a.Equal(uint128b) {
|
||||
t.Fatalf("%v != %v", uint128a, uint128b)
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. proto.proto)
|
||||
Generated
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package custombytesnonstruct
|
||||
|
||||
import testing "testing"
|
||||
|
||||
func TestCustomBytesNonStruct(t *testing.T) {
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package custombytesnonstruct;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
|
||||
message Object {
|
||||
optional bytes CustomField1 = 1 [(gogoproto.customtype) = "CustomType"];
|
||||
repeated bytes CustomField2 = 2 [(gogoproto.customtype) = "CustomType"];
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package dashfilename;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
|
||||
message test {
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package dashfilename
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//Issue 16 : https://github.com/gogo/protobuf/issues/detail?id=16
|
||||
func TestDashFilename(t *testing.T) {
|
||||
name := "dash-filename"
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", name+".proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("err = %v: %s", err, string(data))
|
||||
}
|
||||
if err := os.Remove(name + ".pb.go"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2016, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-min-version
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc-min-version --version="3.0.0" --gogo_out=. \
|
||||
--proto_path=../../../../../:../../protobuf/:. data.proto
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2016, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package data;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
|
||||
message MyMessage {
|
||||
uint32 my_data = 1;
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: data.proto
|
||||
|
||||
/*
|
||||
Package data is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
data.proto
|
||||
|
||||
It has these top-level messages:
|
||||
MyMessage
|
||||
*/
|
||||
package data
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestMyMessageProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMyMessage(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &MyMessage{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMyMessageMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMyMessage(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &MyMessage{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMyMessageProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*MyMessage, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedMyMessage(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkMyMessageProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedMyMessage(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &MyMessage{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestMyMessageJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMyMessage(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &MyMessage{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestMyMessageProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMyMessage(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &MyMessage{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMyMessageProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMyMessage(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &MyMessage{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMyMessageVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedMyMessage(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &MyMessage{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestMyMessageGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedMyMessage(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestMyMessageSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMyMessage(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMyMessageSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*MyMessage, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedMyMessage(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestMyMessageStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedMyMessage(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package defaultcheck;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
message A {
|
||||
optional int64 Field1 = 1 [default=1234];
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package defaultcheck;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
message A {
|
||||
optional int64 Field1 = 1 [default=1234];
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package defaultcheck;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message A {
|
||||
optional int64 Field1 = 1 [default = 1234, (gogoproto.nullable) = false];;
|
||||
}
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package defaultcheck
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testDefaultConflict(t *testing.T, name string) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", name+".proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") {
|
||||
t.Errorf("Expected error, got: %s", data)
|
||||
if err = os.Remove(name + ".pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
t.Logf("received expected error = %v and output = %v", err, string(data))
|
||||
}
|
||||
|
||||
func TestNullableDefault(t *testing.T) {
|
||||
testDefaultConflict(t, "nc")
|
||||
}
|
||||
|
||||
func TestNullableExtension(t *testing.T) {
|
||||
testDefaultConflict(t, "nx")
|
||||
}
|
||||
|
||||
func TestNullableEnum(t *testing.T) {
|
||||
testDefaultConflict(t, "ne")
|
||||
}
|
||||
|
||||
func TestFaceDefault(t *testing.T) {
|
||||
testDefaultConflict(t, "df")
|
||||
}
|
||||
|
||||
func TestNoGettersDefault(t *testing.T) {
|
||||
testDefaultConflict(t, "dg")
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package defaultcheck;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
enum E {
|
||||
P = 10;
|
||||
Q = 11;
|
||||
}
|
||||
|
||||
message A {
|
||||
optional E Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package defaultcheck;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message A {
|
||||
extensions 1 to max;
|
||||
}
|
||||
|
||||
extend A {
|
||||
optional int64 Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
*.pb.go
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package embedconflict;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message TakesLongTooDebug {
|
||||
optional bytes Field1 = 1;
|
||||
optional bytes Field2 = 2 [(gogoproto.nullable)=false, (gogoproto.embed)=true];
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package embedconflict;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message A {
|
||||
optional int64 Field1 = 1;
|
||||
optional B B = 2 [(gogoproto.embed) = true];
|
||||
}
|
||||
|
||||
message B {
|
||||
optional double Field1 = 1;
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package embedconflict
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmbedConflict(t *testing.T) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "ec.proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") {
|
||||
t.Errorf("Expected error, got: %s", data)
|
||||
if err = os.Remove("ec.pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
t.Logf("received expected error = %v and output = %v", err, string(data))
|
||||
}
|
||||
|
||||
func TestEmbedMarshaler(t *testing.T) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "em.proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
dataStr := string(data)
|
||||
t.Logf("received error = %v and output = %v", err, dataStr)
|
||||
if !strings.Contains(dataStr, "WARNING: found non-") || !strings.Contains(dataStr, "unsafe_marshaler") {
|
||||
t.Errorf("Expected WARNING: found non-[marshaler unsafe_marshaler] C with embedded marshaler D")
|
||||
}
|
||||
if err = os.Remove("em.pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmbedExtend(t *testing.T) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "ee.proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") {
|
||||
t.Errorf("Expected error, got: %s", data)
|
||||
if err = os.Remove("ee.pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
t.Logf("received expected error = %v and output = %v", err, string(data))
|
||||
}
|
||||
|
||||
func TestCustomName(t *testing.T) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "en.proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") {
|
||||
t.Errorf("Expected error, got: %s", data)
|
||||
if err = os.Remove("en.pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
t.Logf("received expected error = %v and output = %v", err, string(data))
|
||||
}
|
||||
|
||||
func TestRepeatedEmbed(t *testing.T) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "er.proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") {
|
||||
t.Errorf("Expected error, got: %s", data)
|
||||
if err = os.Remove("er.pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
dataStr := string(data)
|
||||
t.Logf("received error = %v and output = %v", err, dataStr)
|
||||
warning := "ERROR: found repeated embedded field B in message A"
|
||||
if !strings.Contains(dataStr, warning) {
|
||||
t.Errorf("Expected " + warning)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTakesTooLongToDebug(t *testing.T) {
|
||||
cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "eb.proto")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") {
|
||||
t.Errorf("Expected error, got: %s", data)
|
||||
if err = os.Remove("eb.pb.go"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
dataStr := string(data)
|
||||
t.Logf("received error = %v and output = %v", err, dataStr)
|
||||
warning := "ERROR: found embedded bytes field"
|
||||
if !strings.Contains(dataStr, warning) {
|
||||
t.Errorf("Expected " + warning)
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package embedconflict;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message E {
|
||||
optional int64 Field1 = 1;
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
extend E {
|
||||
optional int64 Field1 = 100 [(gogoproto.embed) = true];
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package embedconflict;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message C {
|
||||
optional int64 Field1 = 1;
|
||||
optional D D = 2 [(gogoproto.embed) = true];
|
||||
}
|
||||
|
||||
message D {
|
||||
option (gogoproto.marshaler) = true;
|
||||
optional double Field2 = 2;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package embedconflict;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message F {
|
||||
optional G G = 2 [(gogoproto.embed) = true, (gogoproto.customname) = "G"];
|
||||
}
|
||||
|
||||
message G {
|
||||
optional int64 Field1 = 1;
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package embedconflict;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message A {
|
||||
optional int64 Field1 = 1;
|
||||
repeated B B = 2 [(gogoproto.embed) = true];
|
||||
}
|
||||
|
||||
message B {
|
||||
optional double Field2 = 2;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. empty.proto)
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax="proto2";
|
||||
|
||||
package empty;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
|
||||
message TestRequest {
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package empty
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmpty(t *testing.T) {
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. enumcustomname.proto)
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
// Package enumcustomname tests the behavior of enum_customname and
|
||||
// enumvalue_customname extensions.
|
||||
package enumcustomname;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
import "github.com/gogo/protobuf/test/thetest.proto";
|
||||
|
||||
enum MyEnum {
|
||||
option (gogoproto.enum_customname) = "MyCustomEnum";
|
||||
|
||||
// The following field will take on the custom name and the prefix, joined
|
||||
// by an underscore.
|
||||
A = 0 [(gogoproto.enumvalue_customname) = "MyBetterNameA"];
|
||||
B = 1; // Should be MyCustomEnum_B
|
||||
}
|
||||
|
||||
enum MyUnprefixedEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
option (gogoproto.goproto_enum_stringer) = false; // ensure it behaves correctly without stringer.
|
||||
option (gogoproto.enum_customname) = "MyCustomUnprefixedEnum"; // no prefix added but type gets name
|
||||
UNPREFIXED_A = 0 [(gogoproto.enumvalue_customname) = "MyBetterNameUnprefixedA"];
|
||||
UNPREFIXED_B = 1 ; // Should not pick up prefix above
|
||||
}
|
||||
|
||||
enum MyEnumWithEnumStringer {
|
||||
option (gogoproto.goproto_enum_stringer) = false; // ensure it behaves correctly without stringer.
|
||||
option (gogoproto.enum_stringer) = true; // ensure it behaves correctly without stringer.
|
||||
STRINGER_A = 0 [(gogoproto.enumvalue_customname) = "EnumValueStringerA"];
|
||||
STRINGER_B = 1;
|
||||
}
|
||||
|
||||
message OnlyEnums {
|
||||
optional MyEnum my_enum = 1;
|
||||
optional MyEnum my_enum_default_a = 2 [default=A];
|
||||
optional MyEnum my_enum_default_b = 3 [default=B];
|
||||
optional MyUnprefixedEnum my_unprefixed_enum = 4;
|
||||
optional MyUnprefixedEnum my_unprefixed_enum_default_a = 5 [default=UNPREFIXED_A];
|
||||
optional MyUnprefixedEnum my_unprefixed_enum_default_b = 6 [default=UNPREFIXED_B];
|
||||
optional test.YetAnotherTestEnum yet_another_test_enum = 7;
|
||||
optional test.YetAnotherTestEnum yet_another_test_enum_default_aa = 8 [default=AA];
|
||||
optional test.YetAnotherTestEnum yet_another_test_enum_default_bb = 9 [default=BB];
|
||||
optional test.YetYetAnotherTestEnum yet_yet_another_test_enum = 10;
|
||||
optional test.YetYetAnotherTestEnum yet_yet_another_test_enum_default_cc = 11 [default=CC];
|
||||
optional test.YetYetAnotherTestEnum yet_yet_another_test_enum_default_dd = 12 [default=DD];
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. enumdecl.proto
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package enumdecl;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
enum MyEnum {
|
||||
option (gogoproto.enumdecl) = false;
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
A = 0;
|
||||
B = 1;
|
||||
}
|
||||
|
||||
message Message {
|
||||
MyEnum enumerated_field = 1;
|
||||
}
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: enumdecl.proto
|
||||
|
||||
/*
|
||||
Package enumdecl is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
enumdecl.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Message
|
||||
*/
|
||||
package enumdecl
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestMessageProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Message{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Message{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Message, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedMessage(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkMessageProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Message{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestMessageJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Message{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestMessageProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Message{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Message{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedMessage(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Message{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestMessageSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Message, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedMessage(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. enumdeclall.proto
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package enumdeclall;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
option (gogoproto.enumdecl_all) = false;
|
||||
|
||||
enum MyEnum {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
A = 0;
|
||||
B = 1;
|
||||
}
|
||||
|
||||
enum MyOtherEnum {
|
||||
option (gogoproto.enumdecl) = true;
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
C = 0;
|
||||
D = 1;
|
||||
}
|
||||
|
||||
message Message {
|
||||
MyEnum enumerated_field = 1;
|
||||
MyOtherEnum otherenumerated_field = 2;
|
||||
}
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: enumdeclall.proto
|
||||
|
||||
/*
|
||||
Package enumdeclall is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
enumdeclall.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Message
|
||||
*/
|
||||
package enumdeclall
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestMessageProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Message{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageMarshalTo(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, false)
|
||||
size := p.Size()
|
||||
dAtA := make([]byte, size)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Message{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Message, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedMessage(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkMessageProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &Message{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestMessageJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Message{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestMessageProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Message{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Message{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedMessage(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Message{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestMessageSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMessage(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*Message, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedMessage(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. enumprefix.proto)
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package enumprefix;
|
||||
|
||||
import "github.com/gogo/protobuf/test/thetest.proto";
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message MyMessage {
|
||||
optional test.TheTestEnum TheField = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. enumstringer.proto)
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package enumstringer;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
|
||||
enum TheTestEnum {
|
||||
A = 0;
|
||||
B = 1;
|
||||
C = 2;
|
||||
}
|
||||
|
||||
message NidOptEnum {
|
||||
optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinOptEnum {
|
||||
optional TheTestEnum Field1 = 1;
|
||||
}
|
||||
|
||||
message NidRepEnum {
|
||||
repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message NinRepEnum {
|
||||
repeated TheTestEnum Field1 = 1;
|
||||
}
|
||||
+449
@@ -0,0 +1,449 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: enumstringer.proto
|
||||
|
||||
/*
|
||||
Package enumstringer is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
enumstringer.proto
|
||||
|
||||
It has these top-level messages:
|
||||
NidOptEnum
|
||||
NinOptEnum
|
||||
NidRepEnum
|
||||
NinRepEnum
|
||||
*/
|
||||
package enumstringer
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestNidOptEnumProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidOptEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NidOptEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNinOptEnumProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinOptEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NinOptEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNidRepEnumProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidRepEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NidRepEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNinRepEnumProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinRepEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NinRepEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNidOptEnumJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidOptEnum(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NidOptEnum{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestNinOptEnumJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinOptEnum(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NinOptEnum{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestNidRepEnumJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidRepEnum(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NidRepEnum{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestNinRepEnumJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinRepEnum(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &NinRepEnum{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestNidOptEnumProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidOptEnum(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &NidOptEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNidOptEnumProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidOptEnum(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &NidOptEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNinOptEnumProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinOptEnum(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &NinOptEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNinOptEnumProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinOptEnum(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &NinOptEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNidRepEnumProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidRepEnum(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &NidRepEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNidRepEnumProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNidRepEnum(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &NidRepEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNinRepEnumProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinRepEnum(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &NinRepEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNinRepEnumProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedNinRepEnum(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &NinRepEnum{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNidOptEnumVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedNidOptEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &NidOptEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestNinOptEnumVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedNinOptEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &NinOptEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestNidRepEnumVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedNidRepEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &NidRepEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestNinRepEnumVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedNinRepEnum(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &NinRepEnum{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc -I=. -I=$(GOPATH)/src -I=$(GOPATH)/src/github.com/gogo/protobuf/protobuf --gogo_out=. example.proto)
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package test;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
|
||||
message A {
|
||||
option (gogoproto.face) = true;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
optional string Description = 1 [(gogoproto.nullable) = false];
|
||||
optional int64 Number = 2 [(gogoproto.nullable) = false];
|
||||
optional bytes Id = 3 [(gogoproto.customtype) = "github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message B {
|
||||
option (gogoproto.description) = true;
|
||||
optional A A = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
|
||||
repeated bytes G = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message C {
|
||||
optional int64 size = 1 [(gogoproto.customname) = "MySize"];
|
||||
}
|
||||
|
||||
message U {
|
||||
option (gogoproto.onlyone) = true;
|
||||
optional A A = 1;
|
||||
optional B B = 2;
|
||||
}
|
||||
|
||||
message E {
|
||||
option (gogoproto.goproto_extensions_map) = false;
|
||||
extensions 1 to max;
|
||||
}
|
||||
|
||||
message R {
|
||||
option (gogoproto.goproto_unrecognized) = false;
|
||||
optional uint32 recognized = 1;
|
||||
}
|
||||
|
||||
message CastType {
|
||||
optional int64 Int32 = 1 [(gogoproto.casttype)="int32"];
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package test
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetterExists(t *testing.T) {
|
||||
_ = (&CastType{}).GetInt32()
|
||||
}
|
||||
+1670
File diff suppressed because it is too large
Load Diff
+164
@@ -0,0 +1,164 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"math"
|
||||
math_rand "math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
//func SetRawExtension(base extendableProto, id int32, b []byte) {
|
||||
//func HasExtension(pb extendableProto, extension *ExtensionDesc) bool {
|
||||
//func ClearExtension(pb extendableProto, extension *ExtensionDesc) {
|
||||
//func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) {
|
||||
//func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
|
||||
//func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error {
|
||||
|
||||
type extendable interface {
|
||||
proto.Message
|
||||
ExtensionRangeArray() []proto.ExtensionRange
|
||||
}
|
||||
|
||||
func check(t *testing.T, m extendable, fieldA float64, ext *proto.ExtensionDesc) {
|
||||
if !proto.HasExtension(m, ext) {
|
||||
t.Fatalf("expected extension to be set")
|
||||
}
|
||||
fieldA2Interface, err := proto.GetExtension(m, ext)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fieldA2 := fieldA2Interface.(*float64)
|
||||
if fieldA != *fieldA2 {
|
||||
t.Fatalf("Expected %f got %f", fieldA, *fieldA2)
|
||||
}
|
||||
fieldA3Interface, err := proto.GetUnsafeExtension(m, ext.Field)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fieldA3 := fieldA3Interface.(*float64)
|
||||
if fieldA != *fieldA3 {
|
||||
t.Fatalf("Expected %f got %f", fieldA, *fieldA3)
|
||||
}
|
||||
proto.ClearExtension(m, ext)
|
||||
if proto.HasExtension(m, ext) {
|
||||
t.Fatalf("expected extension to be cleared")
|
||||
}
|
||||
}
|
||||
|
||||
var fieldA float64
|
||||
var fieldABytes []byte
|
||||
var extr = math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
func init() {
|
||||
fieldA = float64(1.1)
|
||||
fieldABits := math.Float64bits(fieldA)
|
||||
x := uint64(uint32(100)<<3 | uint32(proto.WireFixed64))
|
||||
fieldABytes = encodeVarintPopulateThetest(nil, x)
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>8))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>16))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>24))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>32))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>40))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>48))
|
||||
fieldABytes = append(fieldABytes, uint8(fieldABits>>56))
|
||||
}
|
||||
|
||||
func TestExtensionsMyExtendable(t *testing.T) {
|
||||
m := NewPopulatedMyExtendable(extr, false)
|
||||
err := proto.SetExtension(m, E_FieldA, &fieldA)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
check(t, m, fieldA, E_FieldA)
|
||||
proto.SetRawExtension(m, 100, fieldABytes)
|
||||
check(t, m, fieldA, E_FieldA)
|
||||
}
|
||||
|
||||
func TestExtensionsNoExtensionsMapSetExtension(t *testing.T) {
|
||||
m := NewPopulatedNoExtensionsMap(extr, false)
|
||||
err := proto.SetExtension(m, E_FieldA1, &fieldA)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
check(t, m, fieldA, E_FieldA1)
|
||||
}
|
||||
|
||||
func TestExtensionsNoExtensionsMapSetRawExtension(t *testing.T) {
|
||||
m := NewPopulatedNoExtensionsMap(extr, false)
|
||||
proto.SetRawExtension(m, 100, fieldABytes)
|
||||
check(t, m, fieldA, E_FieldA1)
|
||||
}
|
||||
|
||||
func TestUnsafeExtension(t *testing.T) {
|
||||
m := NewPopulatedMyExtendable(extr, false)
|
||||
err := proto.SetUnsafeExtension(m, E_FieldA.Field, &fieldA)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
check(t, m, fieldA, E_FieldA)
|
||||
}
|
||||
|
||||
//See another version of this test in proto/extensions_test.go
|
||||
func TestGetExtensionStability(t *testing.T) {
|
||||
check := func(m *NoExtensionsMap) bool {
|
||||
ext1, err := proto.GetExtension(m, E_FieldB1)
|
||||
if err != nil {
|
||||
t.Fatalf("GetExtension() failed: %s", err)
|
||||
}
|
||||
ext2, err := proto.GetExtension(m, E_FieldB1)
|
||||
if err != nil {
|
||||
t.Fatalf("GetExtension() failed: %s", err)
|
||||
}
|
||||
return ext1.(*NinOptNative).Equal(ext2)
|
||||
}
|
||||
msg := &NoExtensionsMap{Field1: proto.Int64(2)}
|
||||
ext0 := &NinOptNative{Field1: proto.Float64(1)}
|
||||
if err := proto.SetExtension(msg, E_FieldB1, ext0); err != nil {
|
||||
t.Fatalf("Could not set ext1: %s", ext0)
|
||||
}
|
||||
if !check(msg) {
|
||||
t.Errorf("GetExtension() not stable before marshaling")
|
||||
}
|
||||
bb, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal() failed: %s", err)
|
||||
}
|
||||
msg1 := &NoExtensionsMap{}
|
||||
err = proto.Unmarshal(bb, msg1)
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal() failed: %s", err)
|
||||
}
|
||||
if !check(msg1) {
|
||||
t.Errorf("GetExtension() not stable after unmarshaling")
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2016, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc --gogo_out=. --proto_path=../../../../../:../../protobuf/:. file.dot.proto
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2016, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package filedotname;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.face_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.enum_stringer_all) = true;
|
||||
|
||||
option (gogoproto.unsafe_marshaler_all) = false;
|
||||
option (gogoproto.unsafe_unmarshaler_all) = false;
|
||||
|
||||
message M {
|
||||
optional string a = 1;
|
||||
}
|
||||
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: file.dot.proto
|
||||
|
||||
/*
|
||||
Package filedotname is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
file.dot.proto
|
||||
|
||||
It has these top-level messages:
|
||||
M
|
||||
*/
|
||||
package filedotname
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestMProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &M{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMProtoMarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*M, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedM(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dAtA, err := proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkMProtoUnmarshal(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
dAtA, err := proto.Marshal(NewPopulatedM(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &M{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestMJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &M{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestMProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &M{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &M{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileDotDescription(t *testing.T) {
|
||||
FileDotDescription()
|
||||
}
|
||||
func TestMVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedM(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &M{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestMFace(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedM(popr, true)
|
||||
msg := p.TestProto()
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Face Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestMGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedM(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestMSize(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedM(popr, true)
|
||||
size2 := proto.Size(p)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(dAtA) != size {
|
||||
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||
}
|
||||
size3 := proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMSize(b *testing.B) {
|
||||
popr := rand.New(rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*M, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedM(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestMStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedM(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogofast
|
||||
protoc --proto_path=../../../../../:../../protobuf/:. --gogofast_out=. fuzz.proto
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
syntax = "proto2";
|
||||
package fuzztests;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.gostring_all) = true;
|
||||
|
||||
message Nil {
|
||||
|
||||
}
|
||||
|
||||
message NinRepPackedNative {
|
||||
repeated double Field1 = 1 [packed = true];
|
||||
repeated float Field2 = 2 [packed = true];
|
||||
repeated int32 Field3 = 3 [packed = true];
|
||||
repeated int64 Field4 = 4 [packed = true];
|
||||
repeated uint32 Field5 = 5 [packed = true];
|
||||
repeated uint64 Field6 = 6 [packed = true];
|
||||
repeated sint32 Field7 = 7 [packed = true];
|
||||
repeated sint64 Field8 = 8 [packed = true];
|
||||
repeated fixed32 Field9 = 9 [packed = true];
|
||||
repeated sfixed32 Field10 = 10 [packed = true];
|
||||
repeated fixed64 Field11 = 11 [packed = true];
|
||||
repeated sfixed64 Field12 = 12 [packed = true];
|
||||
repeated bool Field13 = 13 [packed = true];
|
||||
}
|
||||
|
||||
message NinOptNative {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional int32 Field3 = 3;
|
||||
optional int64 Field4 = 4;
|
||||
optional uint32 Field5 = 5;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional sint64 Field8 = 8;
|
||||
optional fixed32 Field9 = 9;
|
||||
optional sfixed32 Field10 = 10;
|
||||
optional fixed64 Field11 = 11;
|
||||
optional sfixed64 Field12 = 12;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
|
||||
message NinOptStruct {
|
||||
optional double Field1 = 1;
|
||||
optional float Field2 = 2;
|
||||
optional NinOptNative Field3 = 3;
|
||||
optional NinOptNative Field4 = 4;
|
||||
optional uint64 Field6 = 6;
|
||||
optional sint32 Field7 = 7;
|
||||
optional NinOptNative Field8 = 8;
|
||||
optional bool Field13 = 13;
|
||||
optional string Field14 = 14;
|
||||
optional bytes Field15 = 15;
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package fuzztests
|
||||
|
||||
import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFuzzUnrecognized(t *testing.T) {
|
||||
msg := &Nil{}
|
||||
input := []byte{0x8, 0xaf, 0x81, 0xc9, 0xb3, 0x97, 0xd1, 0xb5, 0xc2, 0x4f, 0x1a, 0x4a, 0x52, 0x48, 0x4e, 0x44, 0x65, 0x51, 0x4b, 0x46, 0x44, 0x33, 0x5a, 0x44, 0x72, 0x38, 0x58, 0x4c, 0x58, 0x70, 0x59, 0x45, 0x71, 0x45, 0x4f, 0x6d, 0x45, 0x4d, 0x54, 0x59, 0x4c, 0x6b, 0x55, 0x7a, 0x6f, 0x6b, 0x5a, 0x69, 0x56, 0x64, 0x46, 0x45, 0x56, 0x4d, 0x70, 0x6a, 0x39, 0x7a, 0x4b, 0x43, 0x4d, 0x6d, 0x76, 0x63, 0x46, 0x4f, 0x31, 0x4a, 0x5a, 0x6b, 0x66, 0x4a, 0x75, 0x51, 0x38, 0x54, 0x54, 0x30, 0x53, 0x61, 0x36, 0x6e, 0x4f, 0x6b, 0x35, 0x54, 0x95, 0x0, 0x0, 0x0, 0x0, 0x12, 0x38, 0x52, 0x36, 0x66, 0x76, 0x41, 0x74, 0x73, 0x7a, 0x39, 0x43, 0x6a, 0x4f, 0x64, 0x59, 0x77, 0x33, 0x30, 0x36, 0x58, 0x75, 0x65, 0x46, 0x4b, 0x46, 0x55, 0x56, 0x71, 0x6d, 0x49, 0x73, 0x4a, 0x4b, 0x78, 0x76, 0x41, 0x65, 0x42, 0x61, 0x5a, 0x30, 0x41, 0x37, 0x45, 0x76, 0x72, 0x31, 0x30, 0x4e, 0x78, 0x6d, 0x33, 0x63, 0x65, 0x66, 0x6b, 0x30}
|
||||
if err := proto.Unmarshal(input, msg); err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func DisabledTestFuzzPackedIsNotIdempotent(t *testing.T) {
|
||||
msg := &NinRepPackedNative{}
|
||||
//original := []byte{0x9, 0xa3, 0xae, 0xab, 0xd2, 0xbe, 0x1c, 0xed, 0xbf, 0x15, 0x22, 0x1, 0x6e, 0x3f, 0x22, 0x81, 0x1, 0x9, 0x21, 0x84, 0x36, 0x21, 0x6a, 0xff, 0xd3, 0x3f, 0x15, 0x15, 0x71, 0x4b, 0xbd, 0x52, 0x70, 0x49, 0x6e, 0x48, 0x54, 0x6a, 0x61, 0x37, 0x63, 0x78, 0x47, 0x58, 0x31, 0x7a, 0x43, 0x4d, 0x7a, 0x48, 0x58, 0x56, 0xcb, 0x9c, 0x34, 0xdf, 0xc6, 0x3c, 0xa4, 0x33, 0xac, 0xba, 0xa7, 0xeb, 0x4, 0xa8, 0x8a, 0x48, 0x75, 0x67, 0x71, 0x31, 0x4a, 0x5b, 0xe1, 0xcf, 0x21, 0x88, 0xd3, 0xec, 0xac, 0x13, 0x28, 0xec, 0xa9, 0x51, 0xc8, 0xe9, 0x5e, 0xca, 0xbe, 0xea, 0x9c, 0x0, 0x6b, 0x44, 0x63, 0xc4, 0x32, 0xaa, 0x36, 0x4e, 0xfc, 0xbd, 0x7, 0xef, 0x5e, 0x47, 0x2, 0xfc, 0xd8, 0x83, 0x85, 0x9c, 0xca, 0x7c, 0xd2, 0xdb, 0xf5, 0x5d, 0xcc, 0x5a, 0x72, 0x1f, 0x66, 0x55, 0x74, 0x46, 0x47, 0x73, 0x75, 0x54, 0x30, 0x39, 0x53, 0x34, 0x4c, 0x61, 0x78, 0x59, 0x31, 0x51, 0x44, 0x30, 0x53, 0x51, 0x71, 0x44, 0x65, 0x6f, 0x53, 0x30, 0x44, 0x6a, 0x58, 0x7a, 0x1b, 0x65, 0x62, 0x9c, 0x95, 0xc5, 0x41, 0xcb, 0x48, 0xa, 0x47, 0xf6, 0xd8, 0xd2, 0xd5, 0x8d, 0x6, 0x69, 0x8f, 0xbe, 0x7c, 0xf3, 0xe9, 0x79, 0x3c, 0xca, 0x6, 0x5b}
|
||||
input := []byte{0x9, 0xa3, 0xae, 0xab, 0xd2, 0xbe, 0x1c, 0xed, 0xbf, 0x15, 0x22, 0x1, 0x6e, 0x3f, 0x22, 0x81, 0x1, 0x9, 0x21, 0x84, 0x36, 0x21, 0x6a, 0xff, 0xd3, 0x3f, 0x15, 0x15, 0x71, 0x4b, 0xbd, 0x52, 0x70, 0x49, 0x6e, 0x48, 0x54, 0x6a, 0x61, 0x37, 0x63, 0x78, 0x47, 0x58, 0x31, 0x7a, 0x43, 0x4d, 0x7a, 0x48, 0x58, 0x56, 0xcb, 0x9c, 0x34, 0xdf, 0xc6, 0x3c, 0xa4, 0x33, 0xac, 0xba, 0xa7, 0xeb, 0x4, 0xa8, 0x8a, 0x48, 0x75, 0x67, 0x71, 0x31, 0x4a, 0x5b, 0xe1, 0xcf, 0x21, 0x88, 0xd3, 0xec, 0xac, 0x13, 0x28, 0xec, 0xa9, 0x51, 0xc8, 0xe9, 0x5e, 0xca, 0xbe, 0xea, 0x9c, 0x0, 0x6b, 0x44, 0x63, 0xc4, 0x32, 0xaa, 0x36, 0x4e, 0xfc, 0xbd, 0x7, 0xef, 0x5e, 0x47, 0x2, 0xfc, 0xd8, 0x83, 0x85, 0x9c, 0xca, 0x7c, 0xd2, 0xdb, 0xf5, 0x5d, 0xcc, 0x5a, 0x72, 0x1f, 0x66, 0x55, 0x74, 0x46, 0x47, 0x73, 0x75, 0x54, 0x30, 0x39, 0x53, 0x34, 0x4c, 0x61, 0x78, 0x59, 0x31, 0x51, 0x44, 0x30, 0x53, 0x51}
|
||||
if err := proto.Unmarshal(input, msg); err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func DisabledTestFuzzFieldOrder(t *testing.T) {
|
||||
msg := &NinOptStruct{}
|
||||
input := []byte{0x52, 0x57, 0x52, 0x6a, 0x33, 0x56, 0x43, 0x76, 0x32, 0x54, 0x49, 0x4a, 0x55, 0x66, 0x39, 0x52, 0x32, 0x32, 0x73, 0x69, 0x4f, 0x67, 0x66, 0x79, 0x4b, 0x79, 0x5a, 0x55, 0x42, 0x53, 0x38, 0x68, 0x6c, 0x46, 0x79, 0x6b, 0x54, 0x43, 0x63, 0x66, 0x30, 0x6a, 0x33, 0x35, 0x33, 0x7a, 0x41, 0x66, 0x68, 0x57, 0x61, 0x78, 0x51, 0x37, 0x76, 0x52, 0x78, 0x34, 0x56, 0x43, 0x54, 0x31, 0x73, 0x6a, 0x77, 0x63, 0x45, 0x62, 0x62, 0x67, 0x34, 0x6f, 0x64, 0x35, 0x6c, 0x41, 0x45, 0x50, 0x64, 0x6f, 0x46, 0x38, 0x41, 0x4b, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30}
|
||||
if err := proto.Unmarshal(input, msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFuzzSint64Overflow(t *testing.T) {
|
||||
msg := &NinOptNative{}
|
||||
//original := []byte{0x9, 0x65, 0xb4, 0xfd, 0xbc, 0x5, 0xc7, 0xee, 0x3f, 0x15, 0x48, 0xec, 0x67, 0x3f, 0x18, 0xca, 0xa4, 0xe0, 0xa9, 0x5, 0x20, 0x8e, 0xb7, 0x9f, 0xf5, 0xcf, 0xe9, 0xea, 0xad, 0xfd, 0x1, 0x28, 0xc9, 0xf1, 0xbc, 0x88, 0xc, 0x30, 0xeb, 0x99, 0xbd, 0xa8, 0xe, 0x38, 0xc0, 0xd4, 0xb7, 0xba, 0x7, 0x40, 0xc8, 0xe4, 0xf6, 0xe2, 0xb8, 0xdd, 0xa7, 0xf2, 0x82, 0xba, 0x16, 0x9d, 0x59, 0xf9, 0x31, 0xe0, 0x99, 0x0, 0x0, 0x0, 0x0, 0x61, 0x59, 0x5b, 0xb5, 0x57, 0x56, 0x93, 0x70, 0xde, 0x68, 0x0, 0x72, 0x40, 0x64, 0x5a, 0x5a, 0x61, 0x57, 0x78, 0x68, 0x53, 0x65, 0x66, 0x67, 0x38, 0x38, 0x61, 0x48, 0x44, 0x32, 0x6c, 0x36, 0x50, 0x31, 0x4d, 0x43, 0x39, 0x31, 0x6d, 0x37, 0x34, 0x32, 0x48, 0x6b, 0x4d, 0x70, 0x31, 0x45, 0x73, 0x48, 0x71, 0x4a, 0x69, 0x37, 0x56, 0x53, 0x44, 0x6b, 0x48, 0x45, 0x50, 0x4b, 0x7a, 0x52, 0x49, 0x4c, 0x50, 0x69, 0x44, 0x72, 0x42, 0x56, 0x50, 0x78, 0x62, 0x56, 0x55, 0x7a, 0x5b, 0xb3, 0x6c, 0x59, 0x4c, 0xf1, 0x31, 0xeb, 0xb6, 0x25, 0x1a, 0x26, 0x67, 0x66, 0x97, 0x79, 0xb8, 0x37, 0x8, 0xe1, 0x32, 0x45, 0x6e, 0x6, 0x90, 0x4f, 0xde, 0x26, 0x7a, 0xc6, 0x29, 0x65, 0x4a, 0x69, 0xa7, 0x21, 0xfb, 0x42, 0xda, 0x43, 0x89, 0x27, 0x70, 0x71, 0xde, 0x66, 0xa4, 0x75, 0x2b, 0x5c, 0x96, 0x9f, 0x25, 0x3b, 0xc1, 0x64, 0x14, 0x4, 0x60, 0x8c, 0x58, 0x7e, 0xa1, 0x59, 0x7b, 0x47, 0x18, 0xc, 0x5b, 0x18, 0x63, 0x9, 0xb4, 0xc9, 0x7, 0xf9, 0xae, 0x33, 0xae, 0x2, 0x4a, 0x8b, 0x34, 0x92, 0x40, 0xb, 0xd7, 0x80, 0x60, 0xdb, 0x44, 0x5}
|
||||
input := []byte{0x40, 0xc8, 0xe4, 0xf6, 0xe2, 0xb8, 0xdd, 0xa7, 0xf2, 0x82, 0xba, 0x16}
|
||||
if err := proto.Unmarshal(input, msg); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func DisabledTestFuzzOverrideField(t *testing.T) {
|
||||
msg := &NinOptNative{}
|
||||
//original := []byte{0x9, 0x73, 0x78, 0x5a, 0xf2, 0xb4, 0x66, 0xe8, 0x3f, 0x15, 0x71, 0xdc, 0x4, 0x3f, 0x18, 0xe5, 0x8e, 0xab, 0xdb, 0x3, 0x20, 0xbe, 0xed, 0xe6, 0xc0, 0xb9, 0xb8, 0xa7, 0xb5, 0x12, 0x28, 0xcb, 0x8c, 0x91, 0xef, 0xc, 0x30, 0x9a, 0xc1, 0xc3, 0xc0, 0xf, 0x38, 0xe8, 0x9b, 0xf0, 0xca, 0x5, 0x40, 0xd2, 0xd7, 0xdd, 0xa3, 0xea, 0xab, 0xec, 0xc2, 0xaa, 0x1, 0x4d, 0xc9, 0x15, 0x0, 0xea, 0x55, 0x72, 0x3e, 0x92, 0xa8, 0x59, 0x3e, 0x87, 0x7d, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x61, 0xca, 0xe7, 0xdb, 0x57, 0xa1, 0xb6, 0x41, 0xf4, 0x72, 0x3e, 0x63, 0x36, 0x43, 0x73, 0x32, 0x68, 0x64, 0x75, 0x75, 0x70, 0x4f, 0x39, 0x67, 0x77, 0x42, 0x6a, 0x78, 0x63, 0x57, 0x64, 0x77, 0x6b, 0x74, 0x44, 0x4d, 0x79, 0x36, 0x30, 0x68, 0x38, 0x53, 0x31, 0x79, 0x33, 0x38, 0x4b, 0x7a, 0x76, 0x36, 0x48, 0x4a, 0x35, 0x37, 0x59, 0x48, 0x6c, 0x74, 0x72, 0x61, 0x33, 0x4c, 0x74, 0x45, 0x4a, 0x51, 0x68, 0x71, 0x31, 0x70, 0x50, 0x70, 0x6a, 0x4d, 0x15, 0x51, 0xce, 0xea, 0x82, 0x1, 0x23, 0xed, 0x7a, 0x3, 0x78, 0xee, 0x56, 0x46, 0xd0, 0xe1, 0x17, 0x18, 0x30, 0x9d, 0x2f, 0xac, 0x1c, 0xa, 0x30, 0xa9, 0x8d, 0x10, 0xed, 0xb5, 0x44, 0x36, 0x5e, 0x84, 0x73, 0x5d, 0x38, 0x51, 0x2b, 0x6e, 0xc6, 0xb5}
|
||||
input := []byte{0x4d, 0xc9, 0x15, 0x0, 0xea, 0x72, 0x3e, 0x63, 0x36, 0x43, 0x73, 0x32, 0x68, 0x64, 0x75, 0x75, 0x70, 0x4f, 0x39, 0x67, 0x77, 0x42, 0x6a, 0x78, 0x63, 0x57, 0x64, 0x77, 0x6b, 0x74, 0x44, 0x4d, 0x79, 0x36, 0x30, 0x68, 0x38, 0x53, 0x31, 0x79, 0x33, 0x38, 0x4b, 0x7a, 0x76, 0x36, 0x48, 0x4a, 0x35, 0x37, 0x59, 0x48, 0x6c, 0x74, 0x72, 0x61, 0x33, 0x4c, 0x74, 0x45, 0x4a, 0x51, 0x68, 0x71, 0x31, 0x70, 0x50, 0x70, 0x6a, 0x4d, 0x15, 0x51, 0xce, 0xea}
|
||||
if err := proto.Unmarshal(input, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
output, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(input) != len(output) {
|
||||
t.Logf("%#v", msg)
|
||||
msg2 := &NinOptNative{}
|
||||
if err := proto.Unmarshal(output, msg2); err == nil {
|
||||
t.Logf("%#v", msg2)
|
||||
}
|
||||
t.Errorf("expected %#v got %#v", input, output)
|
||||
}
|
||||
}
|
||||
|
||||
//Generated code is correct, non generated returns an incorrect error
|
||||
func DisabledTestFuzzBadWireType(t *testing.T) {
|
||||
msg := &NinRepPackedNative{}
|
||||
//input := []byte("j\x160\xfc0000\xf6\xfa000\xc1\xaf\xf5000\xcf" + "00\xb90z\r0\x850\xd30000'0000")
|
||||
input := []byte{0x6a, 0x16, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0xf6, 0xfa, 0x30, 0x30, 0x30, 0xc1, 0xaf, 0xf5, 0x30, 0x30, 0x30, 0xcf, 0x30, 0x30, 0xb9, 0x30, 0x7a, 0xd, 0x30, 0x85, 0x30, 0xd3, 0x30, 0x30, 0x30, 0x30, 0x27, 0x30, 0x30, 0x30, 0x30}
|
||||
if err := proto.Unmarshal(input, msg); err == nil {
|
||||
t.Fatalf("expected bad wiretype for Field4 error got %#v", msg)
|
||||
} else {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFuzzIntegerOverflow(t *testing.T) {
|
||||
msg := &Nil{}
|
||||
//input := []byte("\x1500000\x8b\x9b\xa3\xa8\xb6\xe1\xe1\xfe\u061c0")
|
||||
input := []byte{0x15, 0x30, 0x30, 0x30, 0x30, 0x30, 0x8b, 0x9b, 0xa3, 0xa8, 0xb6, 0xe1, 0xe1, 0xfe, 0xd8, 0x9c, 0x30}
|
||||
if err := proto.Unmarshal(input, msg); err == nil {
|
||||
t.Fatalf("expected integer overflow error %#v", msg)
|
||||
} else {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
//Generated code is correct, non generated returns an incorrect error
|
||||
func DisabledTestFuzzUnexpectedEOF(t *testing.T) {
|
||||
msg := &NinRepPackedNative{}
|
||||
//input := []byte("j\x16000000000000000000" + "00\xb90")
|
||||
input := []byte{0x6a, 0x16, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xb9, 0x30}
|
||||
if err := proto.Unmarshal(input, msg); err == nil {
|
||||
t.Fatalf("expected unexpected eof error got %#v", msg)
|
||||
} else {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
//Generated code is correct, non generated returns an incorrect error
|
||||
func DisabledTestFuzzCantSkipWireType(t *testing.T) {
|
||||
msg := &NinRepPackedNative{}
|
||||
//input := []byte("j\x160\xfc0000\xf6\xfa000\xc1\xaf\xf5000\xcf" + "00\xb90z\r0\x850\xd3000\xa80\xa7000")
|
||||
input := []byte{0x6a, 0x16, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0xf6, 0xfa, 0x30, 0x30, 0x30, 0xc1, 0xaf, 0xf5, 0x30, 0x30, 0x30, 0xcf, 0x30, 0x30, 0xb9, 0x30, 0x7a, 0xd, 0x30, 0x85, 0x30, 0xd3, 0x30, 0x30, 0x30, 0xa8, 0x30, 0xa7, 0x30, 0x30, 0x30}
|
||||
if err := proto.Unmarshal(input, msg); err == nil {
|
||||
t.Fatalf("expected cant skip wiretype error got %#v", msg)
|
||||
} else {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. group.proto)
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package group;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.description_all) = true;
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
|
||||
option (gogoproto.unmarshaler_all) = false;
|
||||
option (gogoproto.marshaler_all) = false;
|
||||
option (gogoproto.sizer_all) = false;
|
||||
|
||||
message Groups1 {
|
||||
repeated group G = 1 {
|
||||
optional int64 Field1 = 1;
|
||||
optional double Field2 = 2;
|
||||
}
|
||||
}
|
||||
|
||||
message Groups2 {
|
||||
optional group G = 1 {
|
||||
optional int64 Field1 = 1;
|
||||
repeated double Field2 = 2;
|
||||
}
|
||||
}
|
||||
|
||||
+539
@@ -0,0 +1,539 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: group.proto
|
||||
|
||||
/*
|
||||
Package group is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
group.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Groups1
|
||||
Groups2
|
||||
*/
|
||||
package group
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestGroups1Proto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups1{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups1_GProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1_G(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups1_G{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups2Proto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups2{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups2_GProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2_G(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups2_G{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups1JSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups1{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestGroups1_GJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1_G(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups1_G{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestGroups2JSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups2{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestGroups2_GJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2_G(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Groups2_G{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestGroups1ProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Groups1{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups1ProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Groups1{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups1_GProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1_G(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Groups1_G{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups1_GProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups1_G(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Groups1_G{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups2ProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Groups2{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups2ProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Groups2{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups2_GProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2_G(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Groups2_G{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroups2_GProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedGroups2_G(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Groups2_G{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupDescription(t *testing.T) {
|
||||
GroupDescription()
|
||||
}
|
||||
func TestGroups1VerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups1(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Groups1{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestGroups1_GVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups1_G(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Groups1_G{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestGroups2VerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups2(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Groups2{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestGroups2_GVerboseEqual(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups2_G(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &Groups2_G{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestGroups1GoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups1(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestGroups1_GGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups1_G(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestGroups2GoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups2(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestGroups2_GGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups2_G(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestGroups1Stringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups1(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestGroups1_GStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups1_G(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestGroups2Stringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups2(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestGroups2_GStringer(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedGroups2_G(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. proto.proto)
|
||||
(protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. subpkg/subproto.proto)
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package importdedup
|
||||
|
||||
import testing "testing"
|
||||
|
||||
func TestImportDedup(t *testing.T) {
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package importdedup;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
import "github.com/gogo/protobuf/test/importdedup/subpkg/subproto.proto";
|
||||
|
||||
message Object {
|
||||
optional bytes CustomField = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/importdedup/subpkg.CustomType"];
|
||||
optional subpkg.SubObject SubObject = 2;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto2";
|
||||
package subpkg;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message SubObject {
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
# Protocol Buffers for Go with Gadgets
|
||||
#
|
||||
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
# http://github.com/gogo/protobuf
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
regenerate:
|
||||
go install github.com/gogo/protobuf/protoc-min-version
|
||||
go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
protoc-min-version --version="3.0.0" --gogo_out=:. \
|
||||
--proto_path=../../../../../:../../protobuf/:. importduplicate.proto
|
||||
protoc-min-version --version="3.0.0" --gogo_out=:. \
|
||||
--proto_path=../../../../../:../../protobuf/:. sortkeys/sortable.proto
|
||||
protoc-min-version --version="3.0.0" --gogo_out=:. \
|
||||
--proto_path=../../../../../:../../protobuf/:. proto/proto.proto
|
||||
|
||||
test:
|
||||
go test
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
package importduplicate;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
import "github.com/gogo/protobuf/test/importduplicate/sortkeys/sortable.proto";
|
||||
import "github.com/gogo/protobuf/test/importduplicate/proto/proto.proto";
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
|
||||
message MapAndSortKeys {
|
||||
sortkeys.Object key = 1;
|
||||
map<int32,string> keyValue = 2;
|
||||
proto.Subject value = 3;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package importduplicate
|
||||
|
||||
import testing "testing"
|
||||
|
||||
func TestImportDuplicate(t *testing.T) {
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: importduplicate.proto
|
||||
|
||||
/*
|
||||
Package importduplicate is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
importduplicate.proto
|
||||
|
||||
It has these top-level messages:
|
||||
MapAndSortKeys
|
||||
*/
|
||||
package importduplicate
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
import _ "github.com/gogo/protobuf/test/importduplicate/sortkeys"
|
||||
import _ "github.com/gogo/protobuf/test/importduplicate/proto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestMapAndSortKeysProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMapAndSortKeys(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &MapAndSortKeys{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapAndSortKeysJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMapAndSortKeys(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &MapAndSortKeys{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestMapAndSortKeysProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMapAndSortKeys(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &MapAndSortKeys{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapAndSortKeysProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedMapAndSortKeys(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &MapAndSortKeys{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapAndSortKeysGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedMapAndSortKeys(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
package proto;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
|
||||
message Subject {
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: proto/proto.proto
|
||||
|
||||
/*
|
||||
Package proto is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
proto/proto.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Subject
|
||||
*/
|
||||
package proto
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto1 "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto1.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestSubjectProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedSubject(popr, false)
|
||||
dAtA, err := proto1.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Subject{}
|
||||
if err := proto1.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto1.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubjectJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedSubject(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Subject{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestSubjectProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedSubject(popr, true)
|
||||
dAtA := proto1.MarshalTextString(p)
|
||||
msg := &Subject{}
|
||||
if err := proto1.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubjectProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedSubject(popr, true)
|
||||
dAtA := proto1.CompactTextString(p)
|
||||
msg := &Subject{}
|
||||
if err := proto1.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubjectGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedSubject(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2015, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
package sortkeys;
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.gostring_all) = true;
|
||||
|
||||
message Object {
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: sortkeys/sortable.proto
|
||||
|
||||
/*
|
||||
Package sortkeys is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
sortkeys/sortable.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Object
|
||||
*/
|
||||
package sortkeys
|
||||
|
||||
import testing "testing"
|
||||
import rand "math/rand"
|
||||
import time "time"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||
import fmt "fmt"
|
||||
import parser "go/parser"
|
||||
import math "math"
|
||||
import _ "github.com/gogo/protobuf/gogoproto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func TestObjectProto(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedObject(popr, false)
|
||||
dAtA, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Object{}
|
||||
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
littlefuzz := make([]byte, len(dAtA))
|
||||
copy(littlefuzz, dAtA)
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
if len(littlefuzz) > 0 {
|
||||
fuzzamount := 100
|
||||
for i := 0; i < fuzzamount; i++ {
|
||||
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||
}
|
||||
// shouldn't panic
|
||||
_ = proto.Unmarshal(littlefuzz, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestObjectJSON(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedObject(popr, true)
|
||||
marshaler := jsonpb.Marshaler{}
|
||||
jsondata, err := marshaler.MarshalToString(p)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
msg := &Object{}
|
||||
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||
if err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
func TestObjectProtoText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedObject(popr, true)
|
||||
dAtA := proto.MarshalTextString(p)
|
||||
msg := &Object{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestObjectProtoCompactText(t *testing.T) {
|
||||
seed := time.Now().UnixNano()
|
||||
popr := rand.New(rand.NewSource(seed))
|
||||
p := NewPopulatedObject(popr, true)
|
||||
dAtA := proto.CompactTextString(p)
|
||||
msg := &Object{}
|
||||
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestObjectGoString(t *testing.T) {
|
||||
popr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedObject(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user