testing/protopack: make package publicly available

Change-Id: I342ed27df17867f18c58e60880bcac5a31a3096b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/219837
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2020-02-14 18:13:14 -08:00
parent cd108d00a8
commit cfd80493c5
14 changed files with 892 additions and 892 deletions

@ -13,10 +13,10 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
preg "google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/protopack"
fieldmaskpb "google.golang.org/protobuf/internal/testprotos/fieldmaskpb"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
@ -860,8 +860,8 @@ func TestMarshal(t *testing.T) {
m := &pb2.Scalars{
OptString: proto.String("no unknowns"),
}
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{101, pack.BytesType}, pack.String("hello world"),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{101, protopack.BytesType}, protopack.String("hello world"),
}.Marshal())
return m
}(),

@ -12,10 +12,10 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
preg "google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/protopack"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
pb3 "google.golang.org/protobuf/internal/testprotos/textpb3"
@ -826,11 +826,11 @@ req_nested: {}
m := &pb2.Scalars{
OptString: proto.String("this message contains unknown fields"),
}
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{101, pack.VarintType}, pack.Bool(true),
pack.Tag{102, pack.VarintType}, pack.Varint(0xff),
pack.Tag{103, pack.Fixed32Type}, pack.Uint32(47),
pack.Tag{104, pack.Fixed64Type}, pack.Int64(0xdeadbeef),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{101, protopack.VarintType}, protopack.Bool(true),
protopack.Tag{102, protopack.VarintType}, protopack.Varint(0xff),
protopack.Tag{103, protopack.Fixed32Type}, protopack.Uint32(47),
protopack.Tag{104, protopack.Fixed64Type}, protopack.Int64(0xdeadbeef),
}.Marshal())
return m
}(),
@ -843,11 +843,11 @@ req_nested: {}
m := &pb2.Scalars{
OptString: proto.String("this message contains unknown fields"),
}
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{101, pack.VarintType}, pack.Bool(true),
pack.Tag{102, pack.VarintType}, pack.Varint(0xff),
pack.Tag{103, pack.Fixed32Type}, pack.Uint32(0x47),
pack.Tag{104, pack.Fixed64Type}, pack.Int64(0xdeadbeef),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{101, protopack.VarintType}, protopack.Bool(true),
protopack.Tag{102, protopack.VarintType}, protopack.Varint(0xff),
protopack.Tag{103, protopack.Fixed32Type}, protopack.Uint32(0x47),
protopack.Tag{104, protopack.Fixed64Type}, protopack.Int64(0xdeadbeef),
}.Marshal())
return m
}(),
@ -862,10 +862,10 @@ req_nested: {}
mo: prototext.MarshalOptions{EmitUnknown: true},
input: func() proto.Message {
m := new(pb2.Scalars)
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{101, pack.BytesType}, pack.LengthPrefix{pack.Bool(true), pack.Bool(false)},
pack.Tag{102, pack.BytesType}, pack.String("hello world"),
pack.Tag{103, pack.BytesType}, pack.Bytes("\xe4\xb8\x96\xe7\x95\x8c"),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{101, protopack.BytesType}, protopack.LengthPrefix{protopack.Bool(true), protopack.Bool(false)},
protopack.Tag{102, protopack.BytesType}, protopack.String("hello world"),
protopack.Tag{103, protopack.BytesType}, protopack.Bytes("\xe4\xb8\x96\xe7\x95\x8c"),
}.Marshal())
return m
}(),
@ -878,12 +878,12 @@ req_nested: {}
mo: prototext.MarshalOptions{EmitUnknown: true},
input: func() proto.Message {
m := new(pb2.Scalars)
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{101, pack.StartGroupType}, pack.Tag{101, pack.EndGroupType},
pack.Tag{102, pack.StartGroupType},
pack.Tag{101, pack.VarintType}, pack.Bool(false),
pack.Tag{102, pack.BytesType}, pack.String("inside a group"),
pack.Tag{102, pack.EndGroupType},
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{101, protopack.StartGroupType}, protopack.Tag{101, protopack.EndGroupType},
protopack.Tag{102, protopack.StartGroupType},
protopack.Tag{101, protopack.VarintType}, protopack.Bool(false),
protopack.Tag{102, protopack.BytesType}, protopack.String("inside a group"),
protopack.Tag{102, protopack.EndGroupType},
}.Marshal())
return m
}(),
@ -898,11 +898,11 @@ req_nested: {}
mo: prototext.MarshalOptions{EmitUnknown: true},
input: func() proto.Message {
m := new(pb2.Scalars)
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{101, pack.BytesType}, pack.LengthPrefix{pack.Bool(true), pack.Bool(false), pack.Bool(true)},
pack.Tag{102, pack.BytesType}, pack.String("hello"),
pack.Tag{101, pack.VarintType}, pack.Bool(true),
pack.Tag{102, pack.BytesType}, pack.String("世界"),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{101, protopack.BytesType}, protopack.LengthPrefix{protopack.Bool(true), protopack.Bool(false), protopack.Bool(true)},
protopack.Tag{102, protopack.BytesType}, protopack.String("hello"),
protopack.Tag{101, protopack.VarintType}, protopack.Bool(true),
protopack.Tag{102, protopack.BytesType}, protopack.String("世界"),
}.Marshal())
return m
}(),

@ -18,11 +18,11 @@ import (
"strings"
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/testing/protopack"
"google.golang.org/protobuf/types/descriptorpb"
)
@ -127,7 +127,7 @@ func main() {
// Parse and print message structure.
defer log.Printf("fatal input: %q", buf) // debug printout if panic occurs
var m pack.Message
var m protopack.Message
m.UnmarshalDescriptor(buf, desc)
if *printSource {
fmt.Printf("%#v\n", m)

@ -11,9 +11,9 @@ import (
"testing"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/testing/protopack"
testpb "google.golang.org/protobuf/internal/testprotos/test"
test3pb "google.golang.org/protobuf/internal/testprotos/test3"
@ -91,8 +91,8 @@ func TestDecodeInvalidMessages(t *testing.T) {
func TestDecodeZeroLengthBytes(t *testing.T) {
// Verify that proto3 bytes fields don't give the mistaken
// impression that they preserve presence.
wire := pack.Message{
pack.Tag{15, pack.BytesType}, pack.Bytes(nil),
wire := protopack.Message{
protopack.Tag{15, protopack.BytesType}, protopack.Bytes(nil),
}.Marshal()
m := &test3pb.TestAllTypes{}
if err := proto.Unmarshal(wire, m); err != nil {
@ -104,8 +104,8 @@ func TestDecodeZeroLengthBytes(t *testing.T) {
}
func TestDecodeOneofNilWrapper(t *testing.T) {
wire := pack.Message{
pack.Tag{111, pack.VarintType}, pack.Varint(1111),
wire := protopack.Message{
protopack.Tag{111, protopack.VarintType}, protopack.Varint(1111),
}.Marshal()
m := &testpb.TestAllTypes{OneofField: (*testpb.TestAllTypes_OneofUint32)(nil)}
if err := proto.Unmarshal(wire, m); err != nil {
@ -121,8 +121,8 @@ func TestDecodeEmptyBytes(t *testing.T) {
// but we take care to produce non-nil []bytes for zero-length
// byte strings, so test for it.
m := &testpb.TestAllTypes{}
b := pack.Message{
pack.Tag{45, pack.BytesType}, pack.Bytes(nil),
b := protopack.Message{
protopack.Tag{45, protopack.BytesType}, protopack.Bytes(nil),
}.Marshal()
if err := proto.Unmarshal(b, m); err != nil {
t.Fatal(err)

@ -9,8 +9,8 @@ import (
"testing"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protopack"
testpb "google.golang.org/protobuf/internal/testprotos/test"
test3pb "google.golang.org/protobuf/internal/testprotos/test3"
@ -416,15 +416,15 @@ func TestEqual(t *testing.T) {
// Unknown fields.
{
x: build(&testpb.TestAllTypes{}, unknown(pack.Message{
pack.Tag{100000, pack.VarintType}, pack.Varint(1),
x: build(&testpb.TestAllTypes{}, unknown(protopack.Message{
protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1),
}.Marshal())),
y: build(&testpb.TestAllTypes{}, unknown(pack.Message{
pack.Tag{100000, pack.VarintType}, pack.Varint(2),
y: build(&testpb.TestAllTypes{}, unknown(protopack.Message{
protopack.Tag{100000, protopack.VarintType}, protopack.Varint(2),
}.Marshal())),
}, {
x: build(&testpb.TestAllTypes{}, unknown(pack.Message{
pack.Tag{100000, pack.VarintType}, pack.Varint(1),
x: build(&testpb.TestAllTypes{}, unknown(protopack.Message{
protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1),
}.Marshal())),
y: &testpb.TestAllTypes{},
},

@ -13,11 +13,11 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/protobuild"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/testing/protopack"
"google.golang.org/protobuf/types/dynamicpb"
legacypb "google.golang.org/protobuf/internal/testprotos/legacy"
@ -511,19 +511,19 @@ var testMerges = []testMerge{{
}, {
desc: "merge unknown fields",
dst: protobuild.Message{
protobuild.Unknown: pack.Message{
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Svarint(-5),
protobuild.Unknown: protopack.Message{
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Svarint(-5),
}.Marshal(),
},
src: protobuild.Message{
protobuild.Unknown: pack.Message{
pack.Tag{Number: 500000, Type: pack.VarintType}, pack.Svarint(-50),
protobuild.Unknown: protopack.Message{
protopack.Tag{Number: 500000, Type: protopack.VarintType}, protopack.Svarint(-50),
}.Marshal(),
},
want: protobuild.Message{
protobuild.Unknown: pack.Message{
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Svarint(-5),
pack.Tag{Number: 500000, Type: pack.VarintType}, pack.Svarint(-50),
protobuild.Unknown: protopack.Message{
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Svarint(-5),
protopack.Tag{Number: 500000, Type: protopack.VarintType}, protopack.Svarint(-50),
}.Marshal(),
},
}, {
@ -786,8 +786,8 @@ func TestMergeRace(t *testing.T) {
}},
func() *testpb.TestAllTypes {
m := new(testpb.TestAllTypes)
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Svarint(-5),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Svarint(-5),
}.Marshal())
return m
}(),
@ -816,8 +816,8 @@ func TestMergeSelf(t *testing.T) {
A: proto.Int32(5),
},
}
got.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Svarint(-5),
got.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Svarint(-5),
}.Marshal())
proto.Merge(got, got)
@ -833,9 +833,9 @@ func TestMergeSelf(t *testing.T) {
A: proto.Int32(5),
},
}
want.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Svarint(-5),
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Svarint(-5),
want.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Svarint(-5),
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Svarint(-5),
}.Marshal())
if !proto.Equal(got, want) {

@ -6,9 +6,9 @@ package proto_test
import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protopack"
messagesetpb "google.golang.org/protobuf/internal/testprotos/messageset/messagesetpb"
msetextpb "google.golang.org/protobuf/internal/testprotos/messageset/msetextpb"
@ -31,14 +31,14 @@ var messageSetTestProtos = []testProto{
})
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -51,14 +51,14 @@ var messageSetTestProtos = []testProto{
})
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -70,34 +70,34 @@ var messageSetTestProtos = []testProto{
Ext1Field1: proto.Int32(10),
}),
)},
wire: pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
// Unknown field
pack.Tag{4, pack.VarintType}, pack.Varint(30),
protopack.Tag{4, protopack.VarintType}, protopack.Varint(30),
}.Marshal(),
},
{
desc: "MessageSet with unknown type_id",
decodeTo: []proto.Message{build(
&messagesetpb.MessageSet{},
unknown(pack.Message{
pack.Tag{999, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
unknown(protopack.Message{
protopack.Tag{999, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
}.Marshal()),
)},
wire: pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(999),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(999),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
}.Marshal(),
},
{
@ -109,16 +109,16 @@ var messageSetTestProtos = []testProto{
Ext1Field2: proto.Int32(20),
}),
)},
wire: pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{2, pack.VarintType}, pack.Varint(20),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{2, protopack.VarintType}, protopack.Varint(20),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
}.Marshal(),
},
{
@ -133,28 +133,28 @@ var messageSetTestProtos = []testProto{
Ext2Field1: proto.Int32(30),
}),
)},
wire: pack.Message{
wire: protopack.Message{
// Ext1, field1
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
// Ext2, field1
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1001),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(30),
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1001),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(30),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
// Ext2, field2
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{2, pack.VarintType}, pack.Varint(20),
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{2, protopack.VarintType}, protopack.Varint(20),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
}.Marshal(),
},
{
@ -162,12 +162,12 @@ var messageSetTestProtos = []testProto{
decodeTo: []proto.Message{build(
&messagesetpb.MessageSet{},
)},
wire: pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
}.Marshal(),
},
{
@ -176,10 +176,10 @@ var messageSetTestProtos = []testProto{
&messagesetpb.MessageSet{},
extend(msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{}),
)},
wire: pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{1, pack.EndGroupType},
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{1, protopack.EndGroupType},
}.Marshal(),
},
{
@ -189,12 +189,12 @@ var messageSetTestProtos = []testProto{
proto.SetExtension(m.MessageSet, msetextpb.E_ExtLargeNumber_MessageSetExtension, &msetextpb.ExtLargeNumber{})
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(protowire.MaxValidNumber + 1),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
pack.Tag{1, pack.EndGroupType},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(protowire.MaxValidNumber + 1),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -203,18 +203,18 @@ var messageSetTestProtos = []testProto{
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
m.MessageSet.ProtoReflect().SetUnknown(
pack.Message{
pack.Tag{protowire.MaxValidNumber + 2, pack.BytesType}, pack.LengthPrefix{},
protopack.Message{
protopack.Tag{protowire.MaxValidNumber + 2, protopack.BytesType}, protopack.LengthPrefix{},
}.Marshal(),
)
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(protowire.MaxValidNumber + 2),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
pack.Tag{1, pack.EndGroupType},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(protowire.MaxValidNumber + 2),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -227,15 +227,15 @@ var messageSetTestProtos = []testProto{
})
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(10),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
pack.Tag{4, pack.VarintType}, pack.Varint(0),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{4, protopack.VarintType}, protopack.Varint(0),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -249,14 +249,14 @@ var messageSetTestProtos = []testProto{
})
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1002),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(1),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1002),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
}),
pack.Tag{1, pack.EndGroupType},
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -269,12 +269,12 @@ var messageSetTestProtos = []testProto{
proto.SetExtension(m.MessageSet, msetextpb.E_ExtRequired_MessageSetExtension, &msetextpb.ExtRequired{})
return m
}()},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Varint(1002),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
pack.Tag{1, pack.EndGroupType},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1002),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -286,12 +286,12 @@ var messageSetInvalidTestProtos = []testProto{
decodeTo: []proto.Message{
(*messagesetpb.MessageSetContainer)(nil),
},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Uvarint(0),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
pack.Tag{1, pack.EndGroupType},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Uvarint(0),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},
@ -300,12 +300,12 @@ var messageSetInvalidTestProtos = []testProto{
decodeTo: []proto.Message{
(*messagesetpb.MessageSetContainer)(nil),
},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.StartGroupType},
pack.Tag{2, pack.VarintType}, pack.Uvarint(0x80000000),
pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
pack.Tag{1, pack.EndGroupType},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Uvarint(0x80000000),
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
protopack.Tag{1, protopack.EndGroupType},
}),
}.Marshal(),
},

@ -8,13 +8,13 @@ import (
"reflect"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoimpl"
"google.golang.org/protobuf/testing/protopack"
"google.golang.org/protobuf/types/descriptorpb"
)
@ -33,8 +33,8 @@ var noEnforceUTF8TestProtos = []testProto{
decodeTo: []proto.Message{&TestNoEnforceUTF8{
OptionalString: string("abc\xff"),
}},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.String("abc\xff"),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.String("abc\xff"),
}.Marshal(),
},
{
@ -42,8 +42,8 @@ var noEnforceUTF8TestProtos = []testProto{
decodeTo: []proto.Message{&TestNoEnforceUTF8{
OptionalBytes: []byte("abc\xff"),
}},
wire: pack.Message{
pack.Tag{2, pack.BytesType}, pack.String("abc\xff"),
wire: protopack.Message{
protopack.Tag{2, protopack.BytesType}, protopack.String("abc\xff"),
}.Marshal(),
},
{
@ -51,9 +51,9 @@ var noEnforceUTF8TestProtos = []testProto{
decodeTo: []proto.Message{&TestNoEnforceUTF8{
RepeatedString: []string{string("foo"), string("abc\xff")},
}},
wire: pack.Message{
pack.Tag{3, pack.BytesType}, pack.String("foo"),
pack.Tag{3, pack.BytesType}, pack.String("abc\xff"),
wire: protopack.Message{
protopack.Tag{3, protopack.BytesType}, protopack.String("foo"),
protopack.Tag{3, protopack.BytesType}, protopack.String("abc\xff"),
}.Marshal(),
},
{
@ -61,9 +61,9 @@ var noEnforceUTF8TestProtos = []testProto{
decodeTo: []proto.Message{&TestNoEnforceUTF8{
RepeatedBytes: [][]byte{[]byte("foo"), []byte("abc\xff")},
}},
wire: pack.Message{
pack.Tag{4, pack.BytesType}, pack.String("foo"),
pack.Tag{4, pack.BytesType}, pack.String("abc\xff"),
wire: protopack.Message{
protopack.Tag{4, protopack.BytesType}, protopack.String("foo"),
protopack.Tag{4, protopack.BytesType}, protopack.String("abc\xff"),
}.Marshal(),
},
{
@ -71,14 +71,14 @@ var noEnforceUTF8TestProtos = []testProto{
decodeTo: []proto.Message{
&TestNoEnforceUTF8{OneofField: &TestNoEnforceUTF8_OneofString{string("abc\xff")}},
},
wire: pack.Message{pack.Tag{5, pack.BytesType}, pack.String("abc\xff")}.Marshal(),
wire: protopack.Message{protopack.Tag{5, protopack.BytesType}, protopack.String("abc\xff")}.Marshal(),
},
{
desc: "invalid UTF-8 in oneof string field of Go bytes",
decodeTo: []proto.Message{
&TestNoEnforceUTF8{OneofField: &TestNoEnforceUTF8_OneofBytes{[]byte("abc\xff")}},
},
wire: pack.Message{pack.Tag{6, pack.BytesType}, pack.String("abc\xff")}.Marshal(),
wire: protopack.Message{protopack.Tag{6, protopack.BytesType}, protopack.String("abc\xff")}.Marshal(),
},
}

File diff suppressed because it is too large Load Diff

@ -7,10 +7,10 @@ package proto_test
import (
"testing"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/internal/protobuild"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protopack"
testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
@ -36,20 +36,20 @@ var testWeakValidMessages = []testProto{
m.SetWeakMessage1(&weakpb.WeakImportMessage1{
A: proto.Int32(1000),
})
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(2000),
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(2000),
}),
}.Marshal())
return m
}(),
},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(1000),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1000),
}),
pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{1, pack.VarintType}, pack.Varint(2000),
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(2000),
}),
}.Marshal(),
},
@ -59,9 +59,9 @@ var testWeakInvalidMessages = []testProto{
{
desc: "invalid field number 0 in weak message",
decodeTo: []proto.Message{(*testpb.TestWeak)(nil)},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{0, pack.VarintType}, pack.Varint(1000),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{0, protopack.VarintType}, protopack.Varint(1000),
}),
}.Marshal(),
},

@ -12,9 +12,9 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/testing/protopack"
"google.golang.org/protobuf/types/dynamicpb"
testpb "google.golang.org/protobuf/internal/testprotos/test"
@ -208,8 +208,8 @@ func TestEqual(t *testing.T) {
}}...)
// Test IgnoreUnknown.
raw := pack.Message{
pack.Tag{1, pack.BytesType}, pack.String("Hello, goodbye!"),
raw := protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.String("Hello, goodbye!"),
}.Marshal()
tests = append(tests, []test{{
x: apply(&testpb.TestAllTypes{OptionalSint64: proto.Int64(5)}, setUnknown{raw}),

@ -10,9 +10,9 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/testing/protopack"
testpb "google.golang.org/protobuf/internal/testprotos/test"
)
@ -210,51 +210,51 @@ func TestTransform(t *testing.T) {
}, {
in: func() proto.Message {
m := &testpb.TestAllTypes{}
m.ProtoReflect().SetUnknown(pack.Message{
pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Uvarint(100),
pack.Tag{Number: 50001, Type: pack.Fixed32Type}, pack.Uint32(200),
pack.Tag{Number: 50002, Type: pack.Fixed64Type}, pack.Uint64(300),
pack.Tag{Number: 50003, Type: pack.BytesType}, pack.String("hello"),
pack.Message{
pack.Tag{Number: 50004, Type: pack.StartGroupType},
pack.Tag{Number: 1, Type: pack.VarintType}, pack.Uvarint(100),
pack.Tag{Number: 1, Type: pack.Fixed32Type}, pack.Uint32(200),
pack.Tag{Number: 1, Type: pack.Fixed64Type}, pack.Uint64(300),
pack.Tag{Number: 1, Type: pack.BytesType}, pack.String("hello"),
pack.Message{
pack.Tag{Number: 1, Type: pack.StartGroupType},
pack.Tag{Number: 1, Type: pack.VarintType}, pack.Uvarint(100),
pack.Tag{Number: 1, Type: pack.Fixed32Type}, pack.Uint32(200),
pack.Tag{Number: 1, Type: pack.Fixed64Type}, pack.Uint64(300),
pack.Tag{Number: 1, Type: pack.BytesType}, pack.String("hello"),
pack.Tag{Number: 1, Type: pack.EndGroupType},
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Uvarint(100),
protopack.Tag{Number: 50001, Type: protopack.Fixed32Type}, protopack.Uint32(200),
protopack.Tag{Number: 50002, Type: protopack.Fixed64Type}, protopack.Uint64(300),
protopack.Tag{Number: 50003, Type: protopack.BytesType}, protopack.String("hello"),
protopack.Message{
protopack.Tag{Number: 50004, Type: protopack.StartGroupType},
protopack.Tag{Number: 1, Type: protopack.VarintType}, protopack.Uvarint(100),
protopack.Tag{Number: 1, Type: protopack.Fixed32Type}, protopack.Uint32(200),
protopack.Tag{Number: 1, Type: protopack.Fixed64Type}, protopack.Uint64(300),
protopack.Tag{Number: 1, Type: protopack.BytesType}, protopack.String("hello"),
protopack.Message{
protopack.Tag{Number: 1, Type: protopack.StartGroupType},
protopack.Tag{Number: 1, Type: protopack.VarintType}, protopack.Uvarint(100),
protopack.Tag{Number: 1, Type: protopack.Fixed32Type}, protopack.Uint32(200),
protopack.Tag{Number: 1, Type: protopack.Fixed64Type}, protopack.Uint64(300),
protopack.Tag{Number: 1, Type: protopack.BytesType}, protopack.String("hello"),
protopack.Tag{Number: 1, Type: protopack.EndGroupType},
},
pack.Tag{Number: 50004, Type: pack.EndGroupType},
protopack.Tag{Number: 50004, Type: protopack.EndGroupType},
},
}.Marshal())
return m
}(),
want: Message{
messageTypeKey: messageTypeOf(&testpb.TestAllTypes{}),
"50000": protoreflect.RawFields(pack.Message{pack.Tag{Number: 50000, Type: pack.VarintType}, pack.Uvarint(100)}.Marshal()),
"50001": protoreflect.RawFields(pack.Message{pack.Tag{Number: 50001, Type: pack.Fixed32Type}, pack.Uint32(200)}.Marshal()),
"50002": protoreflect.RawFields(pack.Message{pack.Tag{Number: 50002, Type: pack.Fixed64Type}, pack.Uint64(300)}.Marshal()),
"50003": protoreflect.RawFields(pack.Message{pack.Tag{Number: 50003, Type: pack.BytesType}, pack.String("hello")}.Marshal()),
"50004": protoreflect.RawFields(pack.Message{
pack.Tag{Number: 50004, Type: pack.StartGroupType},
pack.Tag{Number: 1, Type: pack.VarintType}, pack.Uvarint(100),
pack.Tag{Number: 1, Type: pack.Fixed32Type}, pack.Uint32(200),
pack.Tag{Number: 1, Type: pack.Fixed64Type}, pack.Uint64(300),
pack.Tag{Number: 1, Type: pack.BytesType}, pack.String("hello"),
pack.Message{
pack.Tag{Number: 1, Type: pack.StartGroupType},
pack.Tag{Number: 1, Type: pack.VarintType}, pack.Uvarint(100),
pack.Tag{Number: 1, Type: pack.Fixed32Type}, pack.Uint32(200),
pack.Tag{Number: 1, Type: pack.Fixed64Type}, pack.Uint64(300),
pack.Tag{Number: 1, Type: pack.BytesType}, pack.String("hello"),
pack.Tag{Number: 1, Type: pack.EndGroupType},
"50000": protoreflect.RawFields(protopack.Message{protopack.Tag{Number: 50000, Type: protopack.VarintType}, protopack.Uvarint(100)}.Marshal()),
"50001": protoreflect.RawFields(protopack.Message{protopack.Tag{Number: 50001, Type: protopack.Fixed32Type}, protopack.Uint32(200)}.Marshal()),
"50002": protoreflect.RawFields(protopack.Message{protopack.Tag{Number: 50002, Type: protopack.Fixed64Type}, protopack.Uint64(300)}.Marshal()),
"50003": protoreflect.RawFields(protopack.Message{protopack.Tag{Number: 50003, Type: protopack.BytesType}, protopack.String("hello")}.Marshal()),
"50004": protoreflect.RawFields(protopack.Message{
protopack.Tag{Number: 50004, Type: protopack.StartGroupType},
protopack.Tag{Number: 1, Type: protopack.VarintType}, protopack.Uvarint(100),
protopack.Tag{Number: 1, Type: protopack.Fixed32Type}, protopack.Uint32(200),
protopack.Tag{Number: 1, Type: protopack.Fixed64Type}, protopack.Uint64(300),
protopack.Tag{Number: 1, Type: protopack.BytesType}, protopack.String("hello"),
protopack.Message{
protopack.Tag{Number: 1, Type: protopack.StartGroupType},
protopack.Tag{Number: 1, Type: protopack.VarintType}, protopack.Uvarint(100),
protopack.Tag{Number: 1, Type: protopack.Fixed32Type}, protopack.Uint32(200),
protopack.Tag{Number: 1, Type: protopack.Fixed64Type}, protopack.Uint64(300),
protopack.Tag{Number: 1, Type: protopack.BytesType}, protopack.String("hello"),
protopack.Tag{Number: 1, Type: protopack.EndGroupType},
},
pack.Tag{Number: 50004, Type: pack.EndGroupType},
protopack.Tag{Number: 50004, Type: protopack.EndGroupType},
}.Marshal()),
},
wantString: `{50000:100, 50001:200, 50002:300, 50003:"hello", 50004:{1:[100, 200, 300, "hello", {1:[100, 200, 300, "hello"]}]}}`,

@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package pack enables manual encoding and decoding of protobuf wire data.
// Package protopack enables manual encoding and decoding of protobuf wire data.
//
// This package is intended for use in debugging and/or creation of test data.
// Proper usage of this package requires knowledge of the wire format.
//
// See https://developers.google.com/protocol-buffers/docs/encoding.
package pack
package protopack
import (
"fmt"
@ -25,10 +25,10 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
)
// Number is the field number; aliased from the wire package for convenience.
// Number is the field number; aliased from the protowire package for convenience.
type Number = protowire.Number
// Number type constants; copied from the wire package for convenience.
// Number type constants; copied from the protowire package for convenience.
const (
MinValidNumber Number = protowire.MinValidNumber
FirstReservedNumber Number = protowire.FirstReservedNumber
@ -36,10 +36,10 @@ const (
MaxValidNumber Number = protowire.MaxValidNumber
)
// Type is the wire type; aliased from the wire package for convenience.
// Type is the wire type; aliased from the protowire package for convenience.
type Type = protowire.Type
// Wire type constants; copied from the wire package for convenience.
// Wire type constants; copied from the protowire package for convenience.
const (
VarintType Type = protowire.VarintType
Fixed32Type Type = protowire.Fixed32Type

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pack
package protopack
import (
"bytes"
@ -81,11 +81,11 @@ func TestPack(t *testing.T) {
Tag{1, VarintType}, Denormalized{5, Uvarint(2)},
Tag{1, BytesType}, LengthPrefix{Bool(true), Bool(false), Uvarint(2), Denormalized{5, Uvarint(2)}},
},
wantOutSource: `pack.Message{
pack.Tag{1, pack.VarintType}, pack.Bool(false),
pack.Denormalized{+5, pack.Tag{1, pack.VarintType}}, pack.Uvarint(2),
pack.Tag{1, pack.VarintType}, pack.Denormalized{+5, pack.Uvarint(2)},
pack.Tag{1, pack.BytesType}, pack.LengthPrefix{pack.Bool(true), pack.Bool(false), pack.Uvarint(2), pack.Denormalized{+5, pack.Uvarint(2)}},
wantOutSource: `protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Bool(false),
protopack.Denormalized{+5, protopack.Tag{1, protopack.VarintType}}, protopack.Uvarint(2),
protopack.Tag{1, protopack.VarintType}, protopack.Denormalized{+5, protopack.Uvarint(2)},
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix{protopack.Bool(true), protopack.Bool(false), protopack.Uvarint(2), protopack.Denormalized{+5, protopack.Uvarint(2)}},
}`,
}, {
raw: dhex("100010828080808000121980808080808080808001ffffffffffffffff7f828080808000"),
@ -114,10 +114,10 @@ func TestPack(t *testing.T) {
Tag{4, VarintType}, Denormalized{5, Uvarint(+1)},
Tag{4, BytesType}, LengthPrefix{Uvarint(0), Uvarint(math.MaxUint64), Denormalized{5, Uvarint(+1)}},
},
wantOutSource: `pack.Message{
pack.Tag{4, pack.VarintType}, pack.Uvarint(1),
pack.Tag{4, pack.VarintType}, pack.Denormalized{+5, pack.Uvarint(1)},
pack.Tag{4, pack.BytesType}, pack.LengthPrefix{pack.Uvarint(0), pack.Uvarint(18446744073709551615), pack.Denormalized{+5, pack.Uvarint(1)}},
wantOutSource: `protopack.Message{
protopack.Tag{4, protopack.VarintType}, protopack.Uvarint(1),
protopack.Tag{4, protopack.VarintType}, protopack.Denormalized{+5, protopack.Uvarint(1)},
protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix{protopack.Uvarint(0), protopack.Uvarint(18446744073709551615), protopack.Denormalized{+5, protopack.Uvarint(1)}},
}`,
}, {
raw: dhex("2d010000002a0800000000ffffffff"),
@ -142,9 +142,9 @@ func TestPack(t *testing.T) {
Tag{7, Fixed32Type}, Float32(math.Pi),
Tag{7, BytesType}, LengthPrefix{Float32(math.SmallestNonzeroFloat32), Float32(math.MaxFloat32), Float32(math.Inf(+1)), Float32(math.Inf(-1))},
},
wantOutSource: `pack.Message{
pack.Tag{7, pack.Fixed32Type}, pack.Float32(3.1415927),
pack.Tag{7, pack.BytesType}, pack.LengthPrefix{pack.Float32(1e-45), pack.Float32(3.4028235e+38), pack.Float32(math.Inf(+1)), pack.Float32(math.Inf(-1))},
wantOutSource: `protopack.Message{
protopack.Tag{7, protopack.Fixed32Type}, protopack.Float32(3.1415927),
protopack.Tag{7, protopack.BytesType}, protopack.LengthPrefix{protopack.Float32(1e-45), protopack.Float32(3.4028235e+38), protopack.Float32(math.Inf(+1)), protopack.Float32(math.Inf(-1))},
}`,
}, {
raw: dhex("41010000000000000042100000000000000000ffffffffffffffff"),
@ -201,14 +201,14 @@ func TestPack(t *testing.T) {
Tag{100, StartGroupType}, Tag{100, EndGroupType},
}),
},
wantOutSource: `pack.Message{
pack.Tag{13, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Tag{100, pack.VarintType}, pack.Uvarint(18446744073709551615),
pack.Tag{100, pack.Fixed32Type}, pack.Uint32(4294967295),
pack.Tag{100, pack.Fixed64Type}, pack.Uint64(18446744073709551615),
pack.Tag{100, pack.BytesType}, pack.Bytes("bytes"),
pack.Tag{100, pack.StartGroupType},
pack.Tag{100, pack.EndGroupType},
wantOutSource: `protopack.Message{
protopack.Tag{13, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{100, protopack.VarintType}, protopack.Uvarint(18446744073709551615),
protopack.Tag{100, protopack.Fixed32Type}, protopack.Uint32(4294967295),
protopack.Tag{100, protopack.Fixed64Type}, protopack.Uint64(18446744073709551615),
protopack.Tag{100, protopack.BytesType}, protopack.Bytes("bytes"),
protopack.Tag{100, protopack.StartGroupType},
protopack.Tag{100, protopack.EndGroupType},
}),
}`,
}, {
@ -269,16 +269,16 @@ func TestPack(t *testing.T) {
func() uint32 { return 0x7fe5d008 }(),
)),
},
wantOutSource: `pack.Message{
pack.Tag{7, pack.Fixed32Type}, pack.Float32(math.Float32frombits(0x7fe5d008)),
wantOutSource: `protopack.Message{
protopack.Tag{7, protopack.Fixed32Type}, protopack.Float32(math.Float32frombits(0x7fe5d008)),
}`,
}, {
raw: dhex("51a8d65110771bf97f"),
msg: Message{
Tag{10, Fixed64Type}, Float64(math.Float64frombits(0x7ff91b771051d6a8)),
},
wantOutSource: `pack.Message{
pack.Tag{10, pack.Fixed64Type}, pack.Float64(math.Float64frombits(0x7ff91b771051d6a8)),
wantOutSource: `protopack.Message{
protopack.Tag{10, protopack.Fixed64Type}, protopack.Float64(math.Float64frombits(0x7ff91b771051d6a8)),
}`,
}, {
raw: dhex("ab2c14481ab3e9a76d937fb4dd5e6c616ef311f62b7fe888785fca5609ffe81c1064e50dd7a9edb408d317e2891c0d54c719446938d41ab0ccf8e61dc28b0ebb"),