blob: 3a878e95290a15b621a4797dd82c71fdf5f4e0df [file] [log] [blame]
Damien Neild0b07492019-12-16 12:59:13 -08001// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style.
3// license that can be found in the LICENSE file.
4
5package proto_test
6
7import (
Damien Neila60e7092020-01-28 14:53:44 -08008 "google.golang.org/protobuf/encoding/prototext"
Damien Neild0b07492019-12-16 12:59:13 -08009 "google.golang.org/protobuf/internal/encoding/pack"
Damien Neilb0c26f12019-12-16 09:37:59 -080010 "google.golang.org/protobuf/internal/encoding/wire"
11 "google.golang.org/protobuf/internal/impl"
Damien Neild0b07492019-12-16 12:59:13 -080012 "google.golang.org/protobuf/proto"
Damien Neila60e7092020-01-28 14:53:44 -080013 "google.golang.org/protobuf/reflect/protoregistry"
Damien Neild0b07492019-12-16 12:59:13 -080014
15 legacypb "google.golang.org/protobuf/internal/testprotos/legacy"
Joe Tsai55f18252020-01-11 00:25:01 -080016 legacy1pb "google.golang.org/protobuf/internal/testprotos/legacy/proto2_20160225_2fc053c5"
Damien Neil6635e7d2020-01-15 15:08:57 -080017 requiredpb "google.golang.org/protobuf/internal/testprotos/required"
Damien Neild0b07492019-12-16 12:59:13 -080018 testpb "google.golang.org/protobuf/internal/testprotos/test"
19 test3pb "google.golang.org/protobuf/internal/testprotos/test3"
20)
21
22type testProto struct {
Damien Neilb0c26f12019-12-16 09:37:59 -080023 desc string
24 decodeTo []proto.Message
25 wire []byte
26 partial bool
27 noEncode bool
Damien Neilc600d6c2020-01-21 15:00:33 -080028 checkFastInit bool
Damien Neila60e7092020-01-28 14:53:44 -080029 unmarshalOptions proto.UnmarshalOptions
Damien Neilb0c26f12019-12-16 09:37:59 -080030 validationStatus impl.ValidationStatus
Damien Neild0b07492019-12-16 12:59:13 -080031}
32
33var testValidMessages = []testProto{
34 {
35 desc: "basic scalar types",
36 decodeTo: []proto.Message{&testpb.TestAllTypes{
37 OptionalInt32: proto.Int32(1001),
38 OptionalInt64: proto.Int64(1002),
39 OptionalUint32: proto.Uint32(1003),
40 OptionalUint64: proto.Uint64(1004),
41 OptionalSint32: proto.Int32(1005),
42 OptionalSint64: proto.Int64(1006),
43 OptionalFixed32: proto.Uint32(1007),
44 OptionalFixed64: proto.Uint64(1008),
45 OptionalSfixed32: proto.Int32(1009),
46 OptionalSfixed64: proto.Int64(1010),
47 OptionalFloat: proto.Float32(1011.5),
48 OptionalDouble: proto.Float64(1012.5),
49 OptionalBool: proto.Bool(true),
50 OptionalString: proto.String("string"),
51 OptionalBytes: []byte("bytes"),
52 OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum(),
53 }, &test3pb.TestAllTypes{
54 OptionalInt32: 1001,
55 OptionalInt64: 1002,
56 OptionalUint32: 1003,
57 OptionalUint64: 1004,
58 OptionalSint32: 1005,
59 OptionalSint64: 1006,
60 OptionalFixed32: 1007,
61 OptionalFixed64: 1008,
62 OptionalSfixed32: 1009,
63 OptionalSfixed64: 1010,
64 OptionalFloat: 1011.5,
65 OptionalDouble: 1012.5,
66 OptionalBool: true,
67 OptionalString: "string",
68 OptionalBytes: []byte("bytes"),
69 OptionalNestedEnum: test3pb.TestAllTypes_BAR,
70 }, build(
71 &testpb.TestAllExtensions{},
72 extend(testpb.E_OptionalInt32Extension, int32(1001)),
73 extend(testpb.E_OptionalInt64Extension, int64(1002)),
74 extend(testpb.E_OptionalUint32Extension, uint32(1003)),
75 extend(testpb.E_OptionalUint64Extension, uint64(1004)),
76 extend(testpb.E_OptionalSint32Extension, int32(1005)),
77 extend(testpb.E_OptionalSint64Extension, int64(1006)),
78 extend(testpb.E_OptionalFixed32Extension, uint32(1007)),
79 extend(testpb.E_OptionalFixed64Extension, uint64(1008)),
80 extend(testpb.E_OptionalSfixed32Extension, int32(1009)),
81 extend(testpb.E_OptionalSfixed64Extension, int64(1010)),
82 extend(testpb.E_OptionalFloatExtension, float32(1011.5)),
83 extend(testpb.E_OptionalDoubleExtension, float64(1012.5)),
84 extend(testpb.E_OptionalBoolExtension, bool(true)),
85 extend(testpb.E_OptionalStringExtension, string("string")),
86 extend(testpb.E_OptionalBytesExtension, []byte("bytes")),
87 extend(testpb.E_OptionalNestedEnumExtension, testpb.TestAllTypes_BAR),
88 )},
89 wire: pack.Message{
90 pack.Tag{1, pack.VarintType}, pack.Varint(1001),
91 pack.Tag{2, pack.VarintType}, pack.Varint(1002),
92 pack.Tag{3, pack.VarintType}, pack.Uvarint(1003),
93 pack.Tag{4, pack.VarintType}, pack.Uvarint(1004),
94 pack.Tag{5, pack.VarintType}, pack.Svarint(1005),
95 pack.Tag{6, pack.VarintType}, pack.Svarint(1006),
96 pack.Tag{7, pack.Fixed32Type}, pack.Uint32(1007),
97 pack.Tag{8, pack.Fixed64Type}, pack.Uint64(1008),
98 pack.Tag{9, pack.Fixed32Type}, pack.Int32(1009),
99 pack.Tag{10, pack.Fixed64Type}, pack.Int64(1010),
100 pack.Tag{11, pack.Fixed32Type}, pack.Float32(1011.5),
101 pack.Tag{12, pack.Fixed64Type}, pack.Float64(1012.5),
102 pack.Tag{13, pack.VarintType}, pack.Bool(true),
103 pack.Tag{14, pack.BytesType}, pack.String("string"),
104 pack.Tag{15, pack.BytesType}, pack.Bytes([]byte("bytes")),
105 pack.Tag{21, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_BAR)),
106 }.Marshal(),
107 },
108 {
109 desc: "zero values",
110 decodeTo: []proto.Message{&testpb.TestAllTypes{
111 OptionalInt32: proto.Int32(0),
112 OptionalInt64: proto.Int64(0),
113 OptionalUint32: proto.Uint32(0),
114 OptionalUint64: proto.Uint64(0),
115 OptionalSint32: proto.Int32(0),
116 OptionalSint64: proto.Int64(0),
117 OptionalFixed32: proto.Uint32(0),
118 OptionalFixed64: proto.Uint64(0),
119 OptionalSfixed32: proto.Int32(0),
120 OptionalSfixed64: proto.Int64(0),
121 OptionalFloat: proto.Float32(0),
122 OptionalDouble: proto.Float64(0),
123 OptionalBool: proto.Bool(false),
124 OptionalString: proto.String(""),
125 OptionalBytes: []byte{},
126 }, &test3pb.TestAllTypes{}, build(
127 &testpb.TestAllExtensions{},
128 extend(testpb.E_OptionalInt32Extension, int32(0)),
129 extend(testpb.E_OptionalInt64Extension, int64(0)),
130 extend(testpb.E_OptionalUint32Extension, uint32(0)),
131 extend(testpb.E_OptionalUint64Extension, uint64(0)),
132 extend(testpb.E_OptionalSint32Extension, int32(0)),
133 extend(testpb.E_OptionalSint64Extension, int64(0)),
134 extend(testpb.E_OptionalFixed32Extension, uint32(0)),
135 extend(testpb.E_OptionalFixed64Extension, uint64(0)),
136 extend(testpb.E_OptionalSfixed32Extension, int32(0)),
137 extend(testpb.E_OptionalSfixed64Extension, int64(0)),
138 extend(testpb.E_OptionalFloatExtension, float32(0)),
139 extend(testpb.E_OptionalDoubleExtension, float64(0)),
140 extend(testpb.E_OptionalBoolExtension, bool(false)),
141 extend(testpb.E_OptionalStringExtension, string("")),
142 extend(testpb.E_OptionalBytesExtension, []byte{}),
143 )},
144 wire: pack.Message{
145 pack.Tag{1, pack.VarintType}, pack.Varint(0),
146 pack.Tag{2, pack.VarintType}, pack.Varint(0),
147 pack.Tag{3, pack.VarintType}, pack.Uvarint(0),
148 pack.Tag{4, pack.VarintType}, pack.Uvarint(0),
149 pack.Tag{5, pack.VarintType}, pack.Svarint(0),
150 pack.Tag{6, pack.VarintType}, pack.Svarint(0),
151 pack.Tag{7, pack.Fixed32Type}, pack.Uint32(0),
152 pack.Tag{8, pack.Fixed64Type}, pack.Uint64(0),
153 pack.Tag{9, pack.Fixed32Type}, pack.Int32(0),
154 pack.Tag{10, pack.Fixed64Type}, pack.Int64(0),
155 pack.Tag{11, pack.Fixed32Type}, pack.Float32(0),
156 pack.Tag{12, pack.Fixed64Type}, pack.Float64(0),
157 pack.Tag{13, pack.VarintType}, pack.Bool(false),
158 pack.Tag{14, pack.BytesType}, pack.String(""),
159 pack.Tag{15, pack.BytesType}, pack.Bytes(nil),
160 }.Marshal(),
161 },
162 {
163 desc: "groups",
164 decodeTo: []proto.Message{&testpb.TestAllTypes{
165 Optionalgroup: &testpb.TestAllTypes_OptionalGroup{
Damien Neil2ae60932020-01-14 11:12:21 -0800166 A: proto.Int32(1017),
167 SameFieldNumber: proto.Int32(1016),
Damien Neild0b07492019-12-16 12:59:13 -0800168 },
169 }, build(
170 &testpb.TestAllExtensions{},
171 extend(testpb.E_OptionalgroupExtension, &testpb.OptionalGroupExtension{
Damien Neil2ae60932020-01-14 11:12:21 -0800172 A: proto.Int32(1017),
173 SameFieldNumber: proto.Int32(1016),
Damien Neild0b07492019-12-16 12:59:13 -0800174 }),
175 )},
176 wire: pack.Message{
177 pack.Tag{16, pack.StartGroupType},
178 pack.Tag{17, pack.VarintType}, pack.Varint(1017),
Damien Neil2ae60932020-01-14 11:12:21 -0800179 pack.Tag{16, pack.VarintType}, pack.Varint(1016),
Damien Neild0b07492019-12-16 12:59:13 -0800180 pack.Tag{16, pack.EndGroupType},
181 }.Marshal(),
182 },
183 {
184 desc: "groups (field overridden)",
185 decodeTo: []proto.Message{&testpb.TestAllTypes{
186 Optionalgroup: &testpb.TestAllTypes_OptionalGroup{
187 A: proto.Int32(2),
188 },
189 }, build(
190 &testpb.TestAllExtensions{},
191 extend(testpb.E_OptionalgroupExtension, &testpb.OptionalGroupExtension{
192 A: proto.Int32(2),
193 }),
194 )},
195 wire: pack.Message{
196 pack.Tag{16, pack.StartGroupType},
197 pack.Tag{17, pack.VarintType}, pack.Varint(1),
198 pack.Tag{16, pack.EndGroupType},
199 pack.Tag{16, pack.StartGroupType},
200 pack.Tag{17, pack.VarintType}, pack.Varint(2),
201 pack.Tag{16, pack.EndGroupType},
202 }.Marshal(),
203 },
204 {
205 desc: "messages",
206 decodeTo: []proto.Message{&testpb.TestAllTypes{
207 OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{
208 A: proto.Int32(42),
209 Corecursive: &testpb.TestAllTypes{
210 OptionalInt32: proto.Int32(43),
211 },
212 },
213 }, &test3pb.TestAllTypes{
214 OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
215 A: 42,
216 Corecursive: &test3pb.TestAllTypes{
217 OptionalInt32: 43,
218 },
219 },
220 }, build(
221 &testpb.TestAllExtensions{},
Damien Neil212b05b2020-01-28 13:11:20 -0800222 extend(testpb.E_OptionalNestedMessageExtension, &testpb.TestAllExtensions_NestedMessage{
Damien Neild0b07492019-12-16 12:59:13 -0800223 A: proto.Int32(42),
Damien Neil212b05b2020-01-28 13:11:20 -0800224 Corecursive: build(
225 &testpb.TestAllExtensions{},
226 extend(testpb.E_OptionalInt32Extension, int32(43)),
227 ).(*testpb.TestAllExtensions),
Damien Neild0b07492019-12-16 12:59:13 -0800228 }),
229 )},
230 wire: pack.Message{
231 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
232 pack.Tag{1, pack.VarintType}, pack.Varint(42),
233 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
234 pack.Tag{1, pack.VarintType}, pack.Varint(43),
235 }),
236 }),
237 }.Marshal(),
238 },
239 {
240 desc: "messages (split across multiple tags)",
241 decodeTo: []proto.Message{&testpb.TestAllTypes{
242 OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{
243 A: proto.Int32(42),
244 Corecursive: &testpb.TestAllTypes{
245 OptionalInt32: proto.Int32(43),
246 },
247 },
248 }, &test3pb.TestAllTypes{
249 OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
250 A: 42,
251 Corecursive: &test3pb.TestAllTypes{
252 OptionalInt32: 43,
253 },
254 },
255 }, build(
256 &testpb.TestAllExtensions{},
Damien Neil212b05b2020-01-28 13:11:20 -0800257 extend(testpb.E_OptionalNestedMessageExtension, &testpb.TestAllExtensions_NestedMessage{
Damien Neild0b07492019-12-16 12:59:13 -0800258 A: proto.Int32(42),
Damien Neil212b05b2020-01-28 13:11:20 -0800259 Corecursive: build(
260 &testpb.TestAllExtensions{},
261 extend(testpb.E_OptionalInt32Extension, int32(43)),
262 ).(*testpb.TestAllExtensions),
Damien Neild0b07492019-12-16 12:59:13 -0800263 }),
264 )},
265 wire: pack.Message{
266 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
267 pack.Tag{1, pack.VarintType}, pack.Varint(42),
268 }),
269 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
270 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
271 pack.Tag{1, pack.VarintType}, pack.Varint(43),
272 }),
273 }),
274 }.Marshal(),
275 },
276 {
277 desc: "messages (field overridden)",
278 decodeTo: []proto.Message{&testpb.TestAllTypes{
279 OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{
280 A: proto.Int32(2),
281 },
282 }, &test3pb.TestAllTypes{
283 OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
284 A: 2,
285 },
286 }, build(
287 &testpb.TestAllExtensions{},
Damien Neil212b05b2020-01-28 13:11:20 -0800288 extend(testpb.E_OptionalNestedMessageExtension, &testpb.TestAllExtensions_NestedMessage{
Damien Neild0b07492019-12-16 12:59:13 -0800289 A: proto.Int32(2),
290 }),
291 )},
292 wire: pack.Message{
293 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
294 pack.Tag{1, pack.VarintType}, pack.Varint(1),
295 }),
296 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
297 pack.Tag{1, pack.VarintType}, pack.Varint(2),
298 }),
299 }.Marshal(),
300 },
301 {
302 desc: "basic repeated types",
303 decodeTo: []proto.Message{&testpb.TestAllTypes{
304 RepeatedInt32: []int32{1001, 2001},
305 RepeatedInt64: []int64{1002, 2002},
306 RepeatedUint32: []uint32{1003, 2003},
307 RepeatedUint64: []uint64{1004, 2004},
308 RepeatedSint32: []int32{1005, 2005},
309 RepeatedSint64: []int64{1006, 2006},
310 RepeatedFixed32: []uint32{1007, 2007},
311 RepeatedFixed64: []uint64{1008, 2008},
312 RepeatedSfixed32: []int32{1009, 2009},
313 RepeatedSfixed64: []int64{1010, 2010},
314 RepeatedFloat: []float32{1011.5, 2011.5},
315 RepeatedDouble: []float64{1012.5, 2012.5},
316 RepeatedBool: []bool{true, false},
317 RepeatedString: []string{"foo", "bar"},
318 RepeatedBytes: [][]byte{[]byte("FOO"), []byte("BAR")},
319 RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{
320 testpb.TestAllTypes_FOO,
321 testpb.TestAllTypes_BAR,
322 },
323 }, &test3pb.TestAllTypes{
324 RepeatedInt32: []int32{1001, 2001},
325 RepeatedInt64: []int64{1002, 2002},
326 RepeatedUint32: []uint32{1003, 2003},
327 RepeatedUint64: []uint64{1004, 2004},
328 RepeatedSint32: []int32{1005, 2005},
329 RepeatedSint64: []int64{1006, 2006},
330 RepeatedFixed32: []uint32{1007, 2007},
331 RepeatedFixed64: []uint64{1008, 2008},
332 RepeatedSfixed32: []int32{1009, 2009},
333 RepeatedSfixed64: []int64{1010, 2010},
334 RepeatedFloat: []float32{1011.5, 2011.5},
335 RepeatedDouble: []float64{1012.5, 2012.5},
336 RepeatedBool: []bool{true, false},
337 RepeatedString: []string{"foo", "bar"},
338 RepeatedBytes: [][]byte{[]byte("FOO"), []byte("BAR")},
339 RepeatedNestedEnum: []test3pb.TestAllTypes_NestedEnum{
340 test3pb.TestAllTypes_FOO,
341 test3pb.TestAllTypes_BAR,
342 },
343 }, build(
344 &testpb.TestAllExtensions{},
345 extend(testpb.E_RepeatedInt32Extension, []int32{1001, 2001}),
346 extend(testpb.E_RepeatedInt64Extension, []int64{1002, 2002}),
347 extend(testpb.E_RepeatedUint32Extension, []uint32{1003, 2003}),
348 extend(testpb.E_RepeatedUint64Extension, []uint64{1004, 2004}),
349 extend(testpb.E_RepeatedSint32Extension, []int32{1005, 2005}),
350 extend(testpb.E_RepeatedSint64Extension, []int64{1006, 2006}),
351 extend(testpb.E_RepeatedFixed32Extension, []uint32{1007, 2007}),
352 extend(testpb.E_RepeatedFixed64Extension, []uint64{1008, 2008}),
353 extend(testpb.E_RepeatedSfixed32Extension, []int32{1009, 2009}),
354 extend(testpb.E_RepeatedSfixed64Extension, []int64{1010, 2010}),
355 extend(testpb.E_RepeatedFloatExtension, []float32{1011.5, 2011.5}),
356 extend(testpb.E_RepeatedDoubleExtension, []float64{1012.5, 2012.5}),
357 extend(testpb.E_RepeatedBoolExtension, []bool{true, false}),
358 extend(testpb.E_RepeatedStringExtension, []string{"foo", "bar"}),
359 extend(testpb.E_RepeatedBytesExtension, [][]byte{[]byte("FOO"), []byte("BAR")}),
360 extend(testpb.E_RepeatedNestedEnumExtension, []testpb.TestAllTypes_NestedEnum{
361 testpb.TestAllTypes_FOO,
362 testpb.TestAllTypes_BAR,
363 }),
364 )},
365 wire: pack.Message{
366 pack.Tag{31, pack.VarintType}, pack.Varint(1001),
367 pack.Tag{31, pack.VarintType}, pack.Varint(2001),
368 pack.Tag{32, pack.VarintType}, pack.Varint(1002),
369 pack.Tag{32, pack.VarintType}, pack.Varint(2002),
370 pack.Tag{33, pack.VarintType}, pack.Uvarint(1003),
371 pack.Tag{33, pack.VarintType}, pack.Uvarint(2003),
372 pack.Tag{34, pack.VarintType}, pack.Uvarint(1004),
373 pack.Tag{34, pack.VarintType}, pack.Uvarint(2004),
374 pack.Tag{35, pack.VarintType}, pack.Svarint(1005),
375 pack.Tag{35, pack.VarintType}, pack.Svarint(2005),
376 pack.Tag{36, pack.VarintType}, pack.Svarint(1006),
377 pack.Tag{36, pack.VarintType}, pack.Svarint(2006),
378 pack.Tag{37, pack.Fixed32Type}, pack.Uint32(1007),
379 pack.Tag{37, pack.Fixed32Type}, pack.Uint32(2007),
380 pack.Tag{38, pack.Fixed64Type}, pack.Uint64(1008),
381 pack.Tag{38, pack.Fixed64Type}, pack.Uint64(2008),
382 pack.Tag{39, pack.Fixed32Type}, pack.Int32(1009),
383 pack.Tag{39, pack.Fixed32Type}, pack.Int32(2009),
384 pack.Tag{40, pack.Fixed64Type}, pack.Int64(1010),
385 pack.Tag{40, pack.Fixed64Type}, pack.Int64(2010),
386 pack.Tag{41, pack.Fixed32Type}, pack.Float32(1011.5),
387 pack.Tag{41, pack.Fixed32Type}, pack.Float32(2011.5),
388 pack.Tag{42, pack.Fixed64Type}, pack.Float64(1012.5),
389 pack.Tag{42, pack.Fixed64Type}, pack.Float64(2012.5),
390 pack.Tag{43, pack.VarintType}, pack.Bool(true),
391 pack.Tag{43, pack.VarintType}, pack.Bool(false),
392 pack.Tag{44, pack.BytesType}, pack.String("foo"),
393 pack.Tag{44, pack.BytesType}, pack.String("bar"),
394 pack.Tag{45, pack.BytesType}, pack.Bytes([]byte("FOO")),
395 pack.Tag{45, pack.BytesType}, pack.Bytes([]byte("BAR")),
396 pack.Tag{51, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_FOO)),
397 pack.Tag{51, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_BAR)),
398 }.Marshal(),
399 },
400 {
401 desc: "basic repeated types (packed encoding)",
402 decodeTo: []proto.Message{&testpb.TestAllTypes{
403 RepeatedInt32: []int32{1001, 2001},
404 RepeatedInt64: []int64{1002, 2002},
405 RepeatedUint32: []uint32{1003, 2003},
406 RepeatedUint64: []uint64{1004, 2004},
407 RepeatedSint32: []int32{1005, 2005},
408 RepeatedSint64: []int64{1006, 2006},
409 RepeatedFixed32: []uint32{1007, 2007},
410 RepeatedFixed64: []uint64{1008, 2008},
411 RepeatedSfixed32: []int32{1009, 2009},
412 RepeatedSfixed64: []int64{1010, 2010},
413 RepeatedFloat: []float32{1011.5, 2011.5},
414 RepeatedDouble: []float64{1012.5, 2012.5},
415 RepeatedBool: []bool{true, false},
416 RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{
417 testpb.TestAllTypes_FOO,
418 testpb.TestAllTypes_BAR,
419 },
420 }, &test3pb.TestAllTypes{
421 RepeatedInt32: []int32{1001, 2001},
422 RepeatedInt64: []int64{1002, 2002},
423 RepeatedUint32: []uint32{1003, 2003},
424 RepeatedUint64: []uint64{1004, 2004},
425 RepeatedSint32: []int32{1005, 2005},
426 RepeatedSint64: []int64{1006, 2006},
427 RepeatedFixed32: []uint32{1007, 2007},
428 RepeatedFixed64: []uint64{1008, 2008},
429 RepeatedSfixed32: []int32{1009, 2009},
430 RepeatedSfixed64: []int64{1010, 2010},
431 RepeatedFloat: []float32{1011.5, 2011.5},
432 RepeatedDouble: []float64{1012.5, 2012.5},
433 RepeatedBool: []bool{true, false},
434 RepeatedNestedEnum: []test3pb.TestAllTypes_NestedEnum{
435 test3pb.TestAllTypes_FOO,
436 test3pb.TestAllTypes_BAR,
437 },
438 }, build(
439 &testpb.TestAllExtensions{},
440 extend(testpb.E_RepeatedInt32Extension, []int32{1001, 2001}),
441 extend(testpb.E_RepeatedInt64Extension, []int64{1002, 2002}),
442 extend(testpb.E_RepeatedUint32Extension, []uint32{1003, 2003}),
443 extend(testpb.E_RepeatedUint64Extension, []uint64{1004, 2004}),
444 extend(testpb.E_RepeatedSint32Extension, []int32{1005, 2005}),
445 extend(testpb.E_RepeatedSint64Extension, []int64{1006, 2006}),
446 extend(testpb.E_RepeatedFixed32Extension, []uint32{1007, 2007}),
447 extend(testpb.E_RepeatedFixed64Extension, []uint64{1008, 2008}),
448 extend(testpb.E_RepeatedSfixed32Extension, []int32{1009, 2009}),
449 extend(testpb.E_RepeatedSfixed64Extension, []int64{1010, 2010}),
450 extend(testpb.E_RepeatedFloatExtension, []float32{1011.5, 2011.5}),
451 extend(testpb.E_RepeatedDoubleExtension, []float64{1012.5, 2012.5}),
452 extend(testpb.E_RepeatedBoolExtension, []bool{true, false}),
453 extend(testpb.E_RepeatedNestedEnumExtension, []testpb.TestAllTypes_NestedEnum{
454 testpb.TestAllTypes_FOO,
455 testpb.TestAllTypes_BAR,
456 }),
457 )},
458 wire: pack.Message{
459 pack.Tag{31, pack.BytesType}, pack.LengthPrefix{
460 pack.Varint(1001), pack.Varint(2001),
461 },
462 pack.Tag{32, pack.BytesType}, pack.LengthPrefix{
463 pack.Varint(1002), pack.Varint(2002),
464 },
465 pack.Tag{33, pack.BytesType}, pack.LengthPrefix{
466 pack.Uvarint(1003), pack.Uvarint(2003),
467 },
468 pack.Tag{34, pack.BytesType}, pack.LengthPrefix{
469 pack.Uvarint(1004), pack.Uvarint(2004),
470 },
471 pack.Tag{35, pack.BytesType}, pack.LengthPrefix{
472 pack.Svarint(1005), pack.Svarint(2005),
473 },
474 pack.Tag{36, pack.BytesType}, pack.LengthPrefix{
475 pack.Svarint(1006), pack.Svarint(2006),
476 },
477 pack.Tag{37, pack.BytesType}, pack.LengthPrefix{
478 pack.Uint32(1007), pack.Uint32(2007),
479 },
480 pack.Tag{38, pack.BytesType}, pack.LengthPrefix{
481 pack.Uint64(1008), pack.Uint64(2008),
482 },
483 pack.Tag{39, pack.BytesType}, pack.LengthPrefix{
484 pack.Int32(1009), pack.Int32(2009),
485 },
486 pack.Tag{40, pack.BytesType}, pack.LengthPrefix{
487 pack.Int64(1010), pack.Int64(2010),
488 },
489 pack.Tag{41, pack.BytesType}, pack.LengthPrefix{
490 pack.Float32(1011.5), pack.Float32(2011.5),
491 },
492 pack.Tag{42, pack.BytesType}, pack.LengthPrefix{
493 pack.Float64(1012.5), pack.Float64(2012.5),
494 },
495 pack.Tag{43, pack.BytesType}, pack.LengthPrefix{
496 pack.Bool(true), pack.Bool(false),
497 },
498 pack.Tag{51, pack.BytesType}, pack.LengthPrefix{
499 pack.Varint(int(testpb.TestAllTypes_FOO)),
500 pack.Varint(int(testpb.TestAllTypes_BAR)),
501 },
502 }.Marshal(),
503 },
504 {
505 desc: "basic repeated types (zero-length packed encoding)",
506 decodeTo: []proto.Message{
507 &testpb.TestAllTypes{},
508 &test3pb.TestAllTypes{},
Damien Neil2c0824b2019-12-20 12:21:25 -0800509 build(
510 &testpb.TestAllExtensions{},
511 extend(testpb.E_RepeatedInt32Extension, []int32{}),
512 extend(testpb.E_RepeatedInt64Extension, []int64{}),
513 extend(testpb.E_RepeatedUint32Extension, []uint32{}),
514 extend(testpb.E_RepeatedUint64Extension, []uint64{}),
515 extend(testpb.E_RepeatedSint32Extension, []int32{}),
516 extend(testpb.E_RepeatedSint64Extension, []int64{}),
517 extend(testpb.E_RepeatedFixed32Extension, []uint32{}),
518 extend(testpb.E_RepeatedFixed64Extension, []uint64{}),
519 extend(testpb.E_RepeatedSfixed32Extension, []int32{}),
520 extend(testpb.E_RepeatedSfixed64Extension, []int64{}),
521 extend(testpb.E_RepeatedFloatExtension, []float32{}),
522 extend(testpb.E_RepeatedDoubleExtension, []float64{}),
523 extend(testpb.E_RepeatedBoolExtension, []bool{}),
524 extend(testpb.E_RepeatedNestedEnumExtension, []testpb.TestAllTypes_NestedEnum{}),
525 )},
Damien Neild0b07492019-12-16 12:59:13 -0800526 wire: pack.Message{
527 pack.Tag{31, pack.BytesType}, pack.LengthPrefix{},
528 pack.Tag{32, pack.BytesType}, pack.LengthPrefix{},
529 pack.Tag{33, pack.BytesType}, pack.LengthPrefix{},
530 pack.Tag{34, pack.BytesType}, pack.LengthPrefix{},
531 pack.Tag{35, pack.BytesType}, pack.LengthPrefix{},
532 pack.Tag{36, pack.BytesType}, pack.LengthPrefix{},
533 pack.Tag{37, pack.BytesType}, pack.LengthPrefix{},
534 pack.Tag{38, pack.BytesType}, pack.LengthPrefix{},
535 pack.Tag{39, pack.BytesType}, pack.LengthPrefix{},
536 pack.Tag{40, pack.BytesType}, pack.LengthPrefix{},
537 pack.Tag{41, pack.BytesType}, pack.LengthPrefix{},
538 pack.Tag{42, pack.BytesType}, pack.LengthPrefix{},
539 pack.Tag{43, pack.BytesType}, pack.LengthPrefix{},
540 pack.Tag{51, pack.BytesType}, pack.LengthPrefix{},
541 }.Marshal(),
542 },
543 {
544 desc: "packed repeated types",
545 decodeTo: []proto.Message{&testpb.TestPackedTypes{
546 PackedInt32: []int32{1001, 2001},
547 PackedInt64: []int64{1002, 2002},
548 PackedUint32: []uint32{1003, 2003},
549 PackedUint64: []uint64{1004, 2004},
550 PackedSint32: []int32{1005, 2005},
551 PackedSint64: []int64{1006, 2006},
552 PackedFixed32: []uint32{1007, 2007},
553 PackedFixed64: []uint64{1008, 2008},
554 PackedSfixed32: []int32{1009, 2009},
555 PackedSfixed64: []int64{1010, 2010},
556 PackedFloat: []float32{1011.5, 2011.5},
557 PackedDouble: []float64{1012.5, 2012.5},
558 PackedBool: []bool{true, false},
559 PackedEnum: []testpb.ForeignEnum{
560 testpb.ForeignEnum_FOREIGN_FOO,
561 testpb.ForeignEnum_FOREIGN_BAR,
562 },
563 }, build(
564 &testpb.TestPackedExtensions{},
565 extend(testpb.E_PackedInt32Extension, []int32{1001, 2001}),
566 extend(testpb.E_PackedInt64Extension, []int64{1002, 2002}),
567 extend(testpb.E_PackedUint32Extension, []uint32{1003, 2003}),
568 extend(testpb.E_PackedUint64Extension, []uint64{1004, 2004}),
569 extend(testpb.E_PackedSint32Extension, []int32{1005, 2005}),
570 extend(testpb.E_PackedSint64Extension, []int64{1006, 2006}),
571 extend(testpb.E_PackedFixed32Extension, []uint32{1007, 2007}),
572 extend(testpb.E_PackedFixed64Extension, []uint64{1008, 2008}),
573 extend(testpb.E_PackedSfixed32Extension, []int32{1009, 2009}),
574 extend(testpb.E_PackedSfixed64Extension, []int64{1010, 2010}),
575 extend(testpb.E_PackedFloatExtension, []float32{1011.5, 2011.5}),
576 extend(testpb.E_PackedDoubleExtension, []float64{1012.5, 2012.5}),
577 extend(testpb.E_PackedBoolExtension, []bool{true, false}),
578 extend(testpb.E_PackedEnumExtension, []testpb.ForeignEnum{
579 testpb.ForeignEnum_FOREIGN_FOO,
580 testpb.ForeignEnum_FOREIGN_BAR,
581 }),
582 )},
583 wire: pack.Message{
584 pack.Tag{90, pack.BytesType}, pack.LengthPrefix{
585 pack.Varint(1001), pack.Varint(2001),
586 },
587 pack.Tag{91, pack.BytesType}, pack.LengthPrefix{
588 pack.Varint(1002), pack.Varint(2002),
589 },
590 pack.Tag{92, pack.BytesType}, pack.LengthPrefix{
591 pack.Uvarint(1003), pack.Uvarint(2003),
592 },
593 pack.Tag{93, pack.BytesType}, pack.LengthPrefix{
594 pack.Uvarint(1004), pack.Uvarint(2004),
595 },
596 pack.Tag{94, pack.BytesType}, pack.LengthPrefix{
597 pack.Svarint(1005), pack.Svarint(2005),
598 },
599 pack.Tag{95, pack.BytesType}, pack.LengthPrefix{
600 pack.Svarint(1006), pack.Svarint(2006),
601 },
602 pack.Tag{96, pack.BytesType}, pack.LengthPrefix{
603 pack.Uint32(1007), pack.Uint32(2007),
604 },
605 pack.Tag{97, pack.BytesType}, pack.LengthPrefix{
606 pack.Uint64(1008), pack.Uint64(2008),
607 },
608 pack.Tag{98, pack.BytesType}, pack.LengthPrefix{
609 pack.Int32(1009), pack.Int32(2009),
610 },
611 pack.Tag{99, pack.BytesType}, pack.LengthPrefix{
612 pack.Int64(1010), pack.Int64(2010),
613 },
614 pack.Tag{100, pack.BytesType}, pack.LengthPrefix{
615 pack.Float32(1011.5), pack.Float32(2011.5),
616 },
617 pack.Tag{101, pack.BytesType}, pack.LengthPrefix{
618 pack.Float64(1012.5), pack.Float64(2012.5),
619 },
620 pack.Tag{102, pack.BytesType}, pack.LengthPrefix{
621 pack.Bool(true), pack.Bool(false),
622 },
623 pack.Tag{103, pack.BytesType}, pack.LengthPrefix{
624 pack.Varint(int(testpb.ForeignEnum_FOREIGN_FOO)),
625 pack.Varint(int(testpb.ForeignEnum_FOREIGN_BAR)),
626 },
627 }.Marshal(),
628 },
629 {
630 desc: "packed repeated types (zero length)",
631 decodeTo: []proto.Message{
632 &testpb.TestPackedTypes{},
Damien Neil2c0824b2019-12-20 12:21:25 -0800633 build(
634 &testpb.TestPackedExtensions{},
635 extend(testpb.E_PackedInt32Extension, []int32{}),
636 extend(testpb.E_PackedInt64Extension, []int64{}),
637 extend(testpb.E_PackedUint32Extension, []uint32{}),
638 extend(testpb.E_PackedUint64Extension, []uint64{}),
639 extend(testpb.E_PackedSint32Extension, []int32{}),
640 extend(testpb.E_PackedSint64Extension, []int64{}),
641 extend(testpb.E_PackedFixed32Extension, []uint32{}),
642 extend(testpb.E_PackedFixed64Extension, []uint64{}),
643 extend(testpb.E_PackedSfixed32Extension, []int32{}),
644 extend(testpb.E_PackedSfixed64Extension, []int64{}),
645 extend(testpb.E_PackedFloatExtension, []float32{}),
646 extend(testpb.E_PackedDoubleExtension, []float64{}),
647 extend(testpb.E_PackedBoolExtension, []bool{}),
648 extend(testpb.E_PackedEnumExtension, []testpb.ForeignEnum{}),
649 )},
Damien Neild0b07492019-12-16 12:59:13 -0800650 wire: pack.Message{
651 pack.Tag{90, pack.BytesType}, pack.LengthPrefix{},
652 pack.Tag{91, pack.BytesType}, pack.LengthPrefix{},
653 pack.Tag{92, pack.BytesType}, pack.LengthPrefix{},
654 pack.Tag{93, pack.BytesType}, pack.LengthPrefix{},
655 pack.Tag{94, pack.BytesType}, pack.LengthPrefix{},
656 pack.Tag{95, pack.BytesType}, pack.LengthPrefix{},
657 pack.Tag{96, pack.BytesType}, pack.LengthPrefix{},
658 pack.Tag{97, pack.BytesType}, pack.LengthPrefix{},
659 pack.Tag{98, pack.BytesType}, pack.LengthPrefix{},
660 pack.Tag{99, pack.BytesType}, pack.LengthPrefix{},
661 pack.Tag{100, pack.BytesType}, pack.LengthPrefix{},
662 pack.Tag{101, pack.BytesType}, pack.LengthPrefix{},
663 pack.Tag{102, pack.BytesType}, pack.LengthPrefix{},
664 pack.Tag{103, pack.BytesType}, pack.LengthPrefix{},
665 }.Marshal(),
666 },
667 {
668 desc: "repeated messages",
669 decodeTo: []proto.Message{&testpb.TestAllTypes{
670 RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{
671 {A: proto.Int32(1)},
672 nil,
673 {A: proto.Int32(2)},
674 },
675 }, &test3pb.TestAllTypes{
676 RepeatedNestedMessage: []*test3pb.TestAllTypes_NestedMessage{
677 {A: 1},
678 nil,
679 {A: 2},
680 },
681 }, build(
682 &testpb.TestAllExtensions{},
Damien Neil212b05b2020-01-28 13:11:20 -0800683 extend(testpb.E_RepeatedNestedMessageExtension, []*testpb.TestAllExtensions_NestedMessage{
Damien Neild0b07492019-12-16 12:59:13 -0800684 {A: proto.Int32(1)},
685 nil,
686 {A: proto.Int32(2)},
687 }),
688 )},
689 wire: pack.Message{
690 pack.Tag{48, pack.BytesType}, pack.LengthPrefix(pack.Message{
691 pack.Tag{1, pack.VarintType}, pack.Varint(1),
692 }),
693 pack.Tag{48, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
694 pack.Tag{48, pack.BytesType}, pack.LengthPrefix(pack.Message{
695 pack.Tag{1, pack.VarintType}, pack.Varint(2),
696 }),
697 }.Marshal(),
698 },
699 {
700 desc: "repeated groups",
701 decodeTo: []proto.Message{&testpb.TestAllTypes{
702 Repeatedgroup: []*testpb.TestAllTypes_RepeatedGroup{
703 {A: proto.Int32(1017)},
704 nil,
705 {A: proto.Int32(2017)},
706 },
707 }, build(
708 &testpb.TestAllExtensions{},
709 extend(testpb.E_RepeatedgroupExtension, []*testpb.RepeatedGroupExtension{
710 {A: proto.Int32(1017)},
711 nil,
712 {A: proto.Int32(2017)},
713 }),
714 )},
715 wire: pack.Message{
716 pack.Tag{46, pack.StartGroupType},
717 pack.Tag{47, pack.VarintType}, pack.Varint(1017),
718 pack.Tag{46, pack.EndGroupType},
719 pack.Tag{46, pack.StartGroupType},
720 pack.Tag{46, pack.EndGroupType},
721 pack.Tag{46, pack.StartGroupType},
722 pack.Tag{47, pack.VarintType}, pack.Varint(2017),
723 pack.Tag{46, pack.EndGroupType},
724 }.Marshal(),
725 },
726 {
727 desc: "maps",
728 decodeTo: []proto.Message{&testpb.TestAllTypes{
729 MapInt32Int32: map[int32]int32{1056: 1156, 2056: 2156},
730 MapInt64Int64: map[int64]int64{1057: 1157, 2057: 2157},
731 MapUint32Uint32: map[uint32]uint32{1058: 1158, 2058: 2158},
732 MapUint64Uint64: map[uint64]uint64{1059: 1159, 2059: 2159},
733 MapSint32Sint32: map[int32]int32{1060: 1160, 2060: 2160},
734 MapSint64Sint64: map[int64]int64{1061: 1161, 2061: 2161},
735 MapFixed32Fixed32: map[uint32]uint32{1062: 1162, 2062: 2162},
736 MapFixed64Fixed64: map[uint64]uint64{1063: 1163, 2063: 2163},
737 MapSfixed32Sfixed32: map[int32]int32{1064: 1164, 2064: 2164},
738 MapSfixed64Sfixed64: map[int64]int64{1065: 1165, 2065: 2165},
739 MapInt32Float: map[int32]float32{1066: 1166.5, 2066: 2166.5},
740 MapInt32Double: map[int32]float64{1067: 1167.5, 2067: 2167.5},
741 MapBoolBool: map[bool]bool{true: false, false: true},
742 MapStringString: map[string]string{"69.1.key": "69.1.val", "69.2.key": "69.2.val"},
743 MapStringBytes: map[string][]byte{"70.1.key": []byte("70.1.val"), "70.2.key": []byte("70.2.val")},
744 MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{
745 "71.1.key": {A: proto.Int32(1171)},
746 "71.2.key": {A: proto.Int32(2171)},
747 },
748 MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{
749 "73.1.key": testpb.TestAllTypes_FOO,
750 "73.2.key": testpb.TestAllTypes_BAR,
751 },
752 }, &test3pb.TestAllTypes{
753 MapInt32Int32: map[int32]int32{1056: 1156, 2056: 2156},
754 MapInt64Int64: map[int64]int64{1057: 1157, 2057: 2157},
755 MapUint32Uint32: map[uint32]uint32{1058: 1158, 2058: 2158},
756 MapUint64Uint64: map[uint64]uint64{1059: 1159, 2059: 2159},
757 MapSint32Sint32: map[int32]int32{1060: 1160, 2060: 2160},
758 MapSint64Sint64: map[int64]int64{1061: 1161, 2061: 2161},
759 MapFixed32Fixed32: map[uint32]uint32{1062: 1162, 2062: 2162},
760 MapFixed64Fixed64: map[uint64]uint64{1063: 1163, 2063: 2163},
761 MapSfixed32Sfixed32: map[int32]int32{1064: 1164, 2064: 2164},
762 MapSfixed64Sfixed64: map[int64]int64{1065: 1165, 2065: 2165},
763 MapInt32Float: map[int32]float32{1066: 1166.5, 2066: 2166.5},
764 MapInt32Double: map[int32]float64{1067: 1167.5, 2067: 2167.5},
765 MapBoolBool: map[bool]bool{true: false, false: true},
766 MapStringString: map[string]string{"69.1.key": "69.1.val", "69.2.key": "69.2.val"},
767 MapStringBytes: map[string][]byte{"70.1.key": []byte("70.1.val"), "70.2.key": []byte("70.2.val")},
768 MapStringNestedMessage: map[string]*test3pb.TestAllTypes_NestedMessage{
769 "71.1.key": {A: 1171},
770 "71.2.key": {A: 2171},
771 },
772 MapStringNestedEnum: map[string]test3pb.TestAllTypes_NestedEnum{
773 "73.1.key": test3pb.TestAllTypes_FOO,
774 "73.2.key": test3pb.TestAllTypes_BAR,
775 },
776 }},
777 wire: pack.Message{
778 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
779 pack.Tag{1, pack.VarintType}, pack.Varint(1056),
780 pack.Tag{2, pack.VarintType}, pack.Varint(1156),
781 }),
782 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
783 pack.Tag{1, pack.VarintType}, pack.Varint(2056),
784 pack.Tag{2, pack.VarintType}, pack.Varint(2156),
785 }),
786 pack.Tag{57, pack.BytesType}, pack.LengthPrefix(pack.Message{
787 pack.Tag{1, pack.VarintType}, pack.Varint(1057),
788 pack.Tag{2, pack.VarintType}, pack.Varint(1157),
789 }),
790 pack.Tag{57, pack.BytesType}, pack.LengthPrefix(pack.Message{
791 pack.Tag{1, pack.VarintType}, pack.Varint(2057),
792 pack.Tag{2, pack.VarintType}, pack.Varint(2157),
793 }),
794 pack.Tag{58, pack.BytesType}, pack.LengthPrefix(pack.Message{
795 pack.Tag{1, pack.VarintType}, pack.Varint(1058),
796 pack.Tag{2, pack.VarintType}, pack.Varint(1158),
797 }),
798 pack.Tag{58, pack.BytesType}, pack.LengthPrefix(pack.Message{
799 pack.Tag{1, pack.VarintType}, pack.Varint(2058),
800 pack.Tag{2, pack.VarintType}, pack.Varint(2158),
801 }),
802 pack.Tag{59, pack.BytesType}, pack.LengthPrefix(pack.Message{
803 pack.Tag{1, pack.VarintType}, pack.Varint(1059),
804 pack.Tag{2, pack.VarintType}, pack.Varint(1159),
805 }),
806 pack.Tag{59, pack.BytesType}, pack.LengthPrefix(pack.Message{
807 pack.Tag{1, pack.VarintType}, pack.Varint(2059),
808 pack.Tag{2, pack.VarintType}, pack.Varint(2159),
809 }),
810 pack.Tag{60, pack.BytesType}, pack.LengthPrefix(pack.Message{
811 pack.Tag{1, pack.VarintType}, pack.Svarint(1060),
812 pack.Tag{2, pack.VarintType}, pack.Svarint(1160),
813 }),
814 pack.Tag{60, pack.BytesType}, pack.LengthPrefix(pack.Message{
815 pack.Tag{1, pack.VarintType}, pack.Svarint(2060),
816 pack.Tag{2, pack.VarintType}, pack.Svarint(2160),
817 }),
818 pack.Tag{61, pack.BytesType}, pack.LengthPrefix(pack.Message{
819 pack.Tag{1, pack.VarintType}, pack.Svarint(1061),
820 pack.Tag{2, pack.VarintType}, pack.Svarint(1161),
821 }),
822 pack.Tag{61, pack.BytesType}, pack.LengthPrefix(pack.Message{
823 pack.Tag{1, pack.VarintType}, pack.Svarint(2061),
824 pack.Tag{2, pack.VarintType}, pack.Svarint(2161),
825 }),
826 pack.Tag{62, pack.BytesType}, pack.LengthPrefix(pack.Message{
827 pack.Tag{1, pack.Fixed32Type}, pack.Int32(1062),
828 pack.Tag{2, pack.Fixed32Type}, pack.Int32(1162),
829 }),
830 pack.Tag{62, pack.BytesType}, pack.LengthPrefix(pack.Message{
831 pack.Tag{1, pack.Fixed32Type}, pack.Int32(2062),
832 pack.Tag{2, pack.Fixed32Type}, pack.Int32(2162),
833 }),
834 pack.Tag{63, pack.BytesType}, pack.LengthPrefix(pack.Message{
835 pack.Tag{1, pack.Fixed64Type}, pack.Int64(1063),
836 pack.Tag{2, pack.Fixed64Type}, pack.Int64(1163),
837 }),
838 pack.Tag{63, pack.BytesType}, pack.LengthPrefix(pack.Message{
839 pack.Tag{1, pack.Fixed64Type}, pack.Int64(2063),
840 pack.Tag{2, pack.Fixed64Type}, pack.Int64(2163),
841 }),
842 pack.Tag{64, pack.BytesType}, pack.LengthPrefix(pack.Message{
843 pack.Tag{1, pack.Fixed32Type}, pack.Int32(1064),
844 pack.Tag{2, pack.Fixed32Type}, pack.Int32(1164),
845 }),
846 pack.Tag{64, pack.BytesType}, pack.LengthPrefix(pack.Message{
847 pack.Tag{1, pack.Fixed32Type}, pack.Int32(2064),
848 pack.Tag{2, pack.Fixed32Type}, pack.Int32(2164),
849 }),
850 pack.Tag{65, pack.BytesType}, pack.LengthPrefix(pack.Message{
851 pack.Tag{1, pack.Fixed64Type}, pack.Int64(1065),
852 pack.Tag{2, pack.Fixed64Type}, pack.Int64(1165),
853 }),
854 pack.Tag{65, pack.BytesType}, pack.LengthPrefix(pack.Message{
855 pack.Tag{1, pack.Fixed64Type}, pack.Int64(2065),
856 pack.Tag{2, pack.Fixed64Type}, pack.Int64(2165),
857 }),
858 pack.Tag{66, pack.BytesType}, pack.LengthPrefix(pack.Message{
859 pack.Tag{1, pack.VarintType}, pack.Varint(1066),
860 pack.Tag{2, pack.Fixed32Type}, pack.Float32(1166.5),
861 }),
862 pack.Tag{66, pack.BytesType}, pack.LengthPrefix(pack.Message{
863 pack.Tag{1, pack.VarintType}, pack.Varint(2066),
864 pack.Tag{2, pack.Fixed32Type}, pack.Float32(2166.5),
865 }),
866 pack.Tag{67, pack.BytesType}, pack.LengthPrefix(pack.Message{
867 pack.Tag{1, pack.VarintType}, pack.Varint(1067),
868 pack.Tag{2, pack.Fixed64Type}, pack.Float64(1167.5),
869 }),
870 pack.Tag{67, pack.BytesType}, pack.LengthPrefix(pack.Message{
871 pack.Tag{1, pack.VarintType}, pack.Varint(2067),
872 pack.Tag{2, pack.Fixed64Type}, pack.Float64(2167.5),
873 }),
874 pack.Tag{68, pack.BytesType}, pack.LengthPrefix(pack.Message{
875 pack.Tag{1, pack.VarintType}, pack.Bool(true),
876 pack.Tag{2, pack.VarintType}, pack.Bool(false),
877 }),
878 pack.Tag{68, pack.BytesType}, pack.LengthPrefix(pack.Message{
879 pack.Tag{1, pack.VarintType}, pack.Bool(false),
880 pack.Tag{2, pack.VarintType}, pack.Bool(true),
881 }),
882 pack.Tag{69, pack.BytesType}, pack.LengthPrefix(pack.Message{
883 pack.Tag{1, pack.BytesType}, pack.String("69.1.key"),
884 pack.Tag{2, pack.BytesType}, pack.String("69.1.val"),
885 }),
886 pack.Tag{69, pack.BytesType}, pack.LengthPrefix(pack.Message{
887 pack.Tag{1, pack.BytesType}, pack.String("69.2.key"),
888 pack.Tag{2, pack.BytesType}, pack.String("69.2.val"),
889 }),
890 pack.Tag{70, pack.BytesType}, pack.LengthPrefix(pack.Message{
891 pack.Tag{1, pack.BytesType}, pack.String("70.1.key"),
892 pack.Tag{2, pack.BytesType}, pack.String("70.1.val"),
893 }),
894 pack.Tag{70, pack.BytesType}, pack.LengthPrefix(pack.Message{
895 pack.Tag{1, pack.BytesType}, pack.String("70.2.key"),
896 pack.Tag{2, pack.BytesType}, pack.String("70.2.val"),
897 }),
898 pack.Tag{71, pack.BytesType}, pack.LengthPrefix(pack.Message{
899 pack.Tag{1, pack.BytesType}, pack.String("71.1.key"),
900 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
901 pack.Tag{1, pack.VarintType}, pack.Varint(1171),
902 }),
903 }),
904 pack.Tag{71, pack.BytesType}, pack.LengthPrefix(pack.Message{
905 pack.Tag{1, pack.BytesType}, pack.String("71.2.key"),
906 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
907 pack.Tag{1, pack.VarintType}, pack.Varint(2171),
908 }),
909 }),
910 pack.Tag{73, pack.BytesType}, pack.LengthPrefix(pack.Message{
911 pack.Tag{1, pack.BytesType}, pack.String("73.1.key"),
912 pack.Tag{2, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_FOO)),
913 }),
914 pack.Tag{73, pack.BytesType}, pack.LengthPrefix(pack.Message{
915 pack.Tag{1, pack.BytesType}, pack.String("73.2.key"),
916 pack.Tag{2, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_BAR)),
917 }),
918 }.Marshal(),
919 },
920 {
Damien Neil7e690b52019-12-18 09:35:01 -0800921 desc: "map with value before key",
922 decodeTo: []proto.Message{&testpb.TestAllTypes{
923 MapInt32Int32: map[int32]int32{1056: 1156},
924 MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{
925 "71.1.key": {A: proto.Int32(1171)},
926 },
927 }},
928 wire: pack.Message{
929 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
930 pack.Tag{2, pack.VarintType}, pack.Varint(1156),
931 pack.Tag{1, pack.VarintType}, pack.Varint(1056),
932 }),
933 pack.Tag{71, pack.BytesType}, pack.LengthPrefix(pack.Message{
934 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
935 pack.Tag{1, pack.VarintType}, pack.Varint(1171),
936 }),
937 pack.Tag{1, pack.BytesType}, pack.String("71.1.key"),
938 }),
939 }.Marshal(),
940 },
941 {
942 desc: "map with repeated key and value",
943 decodeTo: []proto.Message{&testpb.TestAllTypes{
944 MapInt32Int32: map[int32]int32{1056: 1156},
945 MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{
946 "71.1.key": {A: proto.Int32(1171)},
947 },
948 }},
949 wire: pack.Message{
950 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
951 pack.Tag{1, pack.VarintType}, pack.Varint(0),
952 pack.Tag{2, pack.VarintType}, pack.Varint(0),
953 pack.Tag{1, pack.VarintType}, pack.Varint(1056),
954 pack.Tag{2, pack.VarintType}, pack.Varint(1156),
955 }),
956 pack.Tag{71, pack.BytesType}, pack.LengthPrefix(pack.Message{
957 pack.Tag{1, pack.BytesType}, pack.String(0),
958 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
959 pack.Tag{1, pack.BytesType}, pack.String("71.1.key"),
960 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
961 pack.Tag{1, pack.VarintType}, pack.Varint(1171),
962 }),
963 }),
964 }.Marshal(),
965 },
966 {
Damien Neild0b07492019-12-16 12:59:13 -0800967 desc: "oneof (uint32)",
968 decodeTo: []proto.Message{
969 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1111}},
970 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint32{1111}},
971 },
972 wire: pack.Message{pack.Tag{111, pack.VarintType}, pack.Varint(1111)}.Marshal(),
973 },
974 {
975 desc: "oneof (message)",
976 decodeTo: []proto.Message{
977 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
978 &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1112)},
979 }}, &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofNestedMessage{
980 &test3pb.TestAllTypes_NestedMessage{A: 1112},
981 }},
982 },
983 wire: pack.Message{pack.Tag{112, pack.BytesType}, pack.LengthPrefix(pack.Message{
984 pack.Message{pack.Tag{1, pack.VarintType}, pack.Varint(1112)},
985 })}.Marshal(),
986 },
987 {
988 desc: "oneof (empty message)",
989 decodeTo: []proto.Message{
990 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
991 &testpb.TestAllTypes_NestedMessage{},
992 }},
993 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofNestedMessage{
994 &test3pb.TestAllTypes_NestedMessage{},
995 }},
996 },
997 wire: pack.Message{pack.Tag{112, pack.BytesType}, pack.LengthPrefix(pack.Message{})}.Marshal(),
998 },
999 {
1000 desc: "oneof (merged message)",
1001 decodeTo: []proto.Message{
1002 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
1003 &testpb.TestAllTypes_NestedMessage{
1004 A: proto.Int32(1),
1005 Corecursive: &testpb.TestAllTypes{
1006 OptionalInt32: proto.Int32(43),
1007 },
1008 },
1009 }}, &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofNestedMessage{
1010 &test3pb.TestAllTypes_NestedMessage{
1011 A: 1,
1012 Corecursive: &test3pb.TestAllTypes{
1013 OptionalInt32: 43,
1014 },
1015 },
1016 }}},
1017 wire: pack.Message{
1018 pack.Tag{112, pack.BytesType}, pack.LengthPrefix(pack.Message{
1019 pack.Message{pack.Tag{1, pack.VarintType}, pack.Varint(1)},
1020 }),
1021 pack.Tag{112, pack.BytesType}, pack.LengthPrefix(pack.Message{
1022 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1023 pack.Tag{1, pack.VarintType}, pack.Varint(43),
1024 }),
1025 }),
1026 }.Marshal(),
1027 },
1028 {
1029 desc: "oneof (string)",
1030 decodeTo: []proto.Message{
1031 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofString{"1113"}},
1032 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofString{"1113"}},
1033 },
1034 wire: pack.Message{pack.Tag{113, pack.BytesType}, pack.String("1113")}.Marshal(),
1035 },
1036 {
1037 desc: "oneof (bytes)",
1038 decodeTo: []proto.Message{
1039 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofBytes{[]byte("1114")}},
1040 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofBytes{[]byte("1114")}},
1041 },
1042 wire: pack.Message{pack.Tag{114, pack.BytesType}, pack.String("1114")}.Marshal(),
1043 },
1044 {
1045 desc: "oneof (bool)",
1046 decodeTo: []proto.Message{
1047 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofBool{true}},
1048 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofBool{true}},
1049 },
1050 wire: pack.Message{pack.Tag{115, pack.VarintType}, pack.Bool(true)}.Marshal(),
1051 },
1052 {
1053 desc: "oneof (uint64)",
1054 decodeTo: []proto.Message{
1055 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{116}},
1056 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint64{116}},
1057 },
1058 wire: pack.Message{pack.Tag{116, pack.VarintType}, pack.Varint(116)}.Marshal(),
1059 },
1060 {
1061 desc: "oneof (float)",
1062 decodeTo: []proto.Message{
1063 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofFloat{117.5}},
1064 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofFloat{117.5}},
1065 },
1066 wire: pack.Message{pack.Tag{117, pack.Fixed32Type}, pack.Float32(117.5)}.Marshal(),
1067 },
1068 {
1069 desc: "oneof (double)",
1070 decodeTo: []proto.Message{
1071 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofDouble{118.5}},
1072 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofDouble{118.5}},
1073 },
1074 wire: pack.Message{pack.Tag{118, pack.Fixed64Type}, pack.Float64(118.5)}.Marshal(),
1075 },
1076 {
1077 desc: "oneof (enum)",
1078 decodeTo: []proto.Message{
1079 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofEnum{testpb.TestAllTypes_BAR}},
1080 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofEnum{test3pb.TestAllTypes_BAR}},
1081 },
1082 wire: pack.Message{pack.Tag{119, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_BAR))}.Marshal(),
1083 },
1084 {
1085 desc: "oneof (zero)",
1086 decodeTo: []proto.Message{
1087 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{0}},
1088 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint64{0}},
1089 },
1090 wire: pack.Message{pack.Tag{116, pack.VarintType}, pack.Varint(0)}.Marshal(),
1091 },
1092 {
1093 desc: "oneof (overridden value)",
1094 decodeTo: []proto.Message{
1095 &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{2}},
1096 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint64{2}},
1097 },
1098 wire: pack.Message{
1099 pack.Tag{111, pack.VarintType}, pack.Varint(1),
1100 pack.Tag{116, pack.VarintType}, pack.Varint(2),
1101 }.Marshal(),
1102 },
1103 // TODO: More unknown field tests for ordering, repeated fields, etc.
1104 //
1105 // It is currently impossible to produce results that the v1 Equal
1106 // considers equivalent to those of the v1 decoder. Figure out if
1107 // that's a problem or not.
1108 {
1109 desc: "unknown fields",
1110 decodeTo: []proto.Message{build(
1111 &testpb.TestAllTypes{},
1112 unknown(pack.Message{
1113 pack.Tag{100000, pack.VarintType}, pack.Varint(1),
1114 }.Marshal()),
1115 ), build(
1116 &test3pb.TestAllTypes{},
1117 unknown(pack.Message{
1118 pack.Tag{100000, pack.VarintType}, pack.Varint(1),
1119 }.Marshal()),
1120 )},
1121 wire: pack.Message{
1122 pack.Tag{100000, pack.VarintType}, pack.Varint(1),
1123 }.Marshal(),
1124 },
1125 {
Damien Neila60e7092020-01-28 14:53:44 -08001126 desc: "discarded unknown fields",
1127 unmarshalOptions: proto.UnmarshalOptions{
1128 DiscardUnknown: true,
1129 },
1130 decodeTo: []proto.Message{
1131 &testpb.TestAllTypes{},
1132 &test3pb.TestAllTypes{},
1133 },
1134 wire: pack.Message{
1135 pack.Tag{100000, pack.VarintType}, pack.Varint(1),
1136 }.Marshal(),
1137 },
1138 {
Damien Neild0b07492019-12-16 12:59:13 -08001139 desc: "field type mismatch",
1140 decodeTo: []proto.Message{build(
1141 &testpb.TestAllTypes{},
1142 unknown(pack.Message{
1143 pack.Tag{1, pack.BytesType}, pack.String("string"),
1144 }.Marshal()),
1145 ), build(
1146 &test3pb.TestAllTypes{},
1147 unknown(pack.Message{
1148 pack.Tag{1, pack.BytesType}, pack.String("string"),
1149 }.Marshal()),
1150 )},
1151 wire: pack.Message{
1152 pack.Tag{1, pack.BytesType}, pack.String("string"),
1153 }.Marshal(),
1154 },
1155 {
1156 desc: "map field element mismatch",
1157 decodeTo: []proto.Message{
1158 &testpb.TestAllTypes{
1159 MapInt32Int32: map[int32]int32{1: 0},
1160 }, &test3pb.TestAllTypes{
1161 MapInt32Int32: map[int32]int32{1: 0},
1162 },
1163 },
1164 wire: pack.Message{
1165 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
1166 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1167 pack.Tag{2, pack.BytesType}, pack.String("string"),
1168 }),
1169 }.Marshal(),
1170 },
1171 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001172 desc: "required field in nil message unset",
1173 checkFastInit: true,
1174 partial: true,
1175 decodeTo: []proto.Message{(*testpb.TestRequired)(nil)},
Damien Neild0b07492019-12-16 12:59:13 -08001176 },
1177 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001178 desc: "required int32 unset",
1179 checkFastInit: true,
1180 partial: true,
1181 decodeTo: []proto.Message{&requiredpb.Int32{}},
Damien Neild0b07492019-12-16 12:59:13 -08001182 },
1183 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001184 desc: "required int32 set",
1185 checkFastInit: true,
Damien Neil6635e7d2020-01-15 15:08:57 -08001186 decodeTo: []proto.Message{&requiredpb.Int32{
1187 V: proto.Int32(1),
Damien Neild0b07492019-12-16 12:59:13 -08001188 }},
1189 wire: pack.Message{
1190 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1191 }.Marshal(),
1192 },
1193 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001194 desc: "required fixed32 unset",
1195 checkFastInit: true,
1196 partial: true,
1197 decodeTo: []proto.Message{&requiredpb.Fixed32{}},
Damien Neil6635e7d2020-01-15 15:08:57 -08001198 },
1199 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001200 desc: "required fixed32 set",
1201 checkFastInit: true,
Damien Neil6635e7d2020-01-15 15:08:57 -08001202 decodeTo: []proto.Message{&requiredpb.Fixed32{
1203 V: proto.Uint32(1),
1204 }},
1205 wire: pack.Message{
1206 pack.Tag{1, pack.Fixed32Type}, pack.Int32(1),
1207 }.Marshal(),
1208 },
1209 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001210 desc: "required fixed64 unset",
1211 checkFastInit: true,
1212 partial: true,
1213 decodeTo: []proto.Message{&requiredpb.Fixed64{}},
Damien Neil6635e7d2020-01-15 15:08:57 -08001214 },
1215 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001216 desc: "required fixed64 set",
1217 checkFastInit: true,
Damien Neil6635e7d2020-01-15 15:08:57 -08001218 decodeTo: []proto.Message{&requiredpb.Fixed64{
1219 V: proto.Uint64(1),
1220 }},
1221 wire: pack.Message{
1222 pack.Tag{1, pack.Fixed64Type}, pack.Int64(1),
1223 }.Marshal(),
1224 },
1225 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001226 desc: "required bytes unset",
1227 checkFastInit: true,
1228 partial: true,
1229 decodeTo: []proto.Message{&requiredpb.Bytes{}},
Damien Neil6635e7d2020-01-15 15:08:57 -08001230 },
1231 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001232 desc: "required bytes set",
1233 checkFastInit: true,
Damien Neil6635e7d2020-01-15 15:08:57 -08001234 decodeTo: []proto.Message{&requiredpb.Bytes{
1235 V: []byte{},
1236 }},
1237 wire: pack.Message{
1238 pack.Tag{1, pack.BytesType}, pack.Bytes(nil),
1239 }.Marshal(),
1240 },
1241 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001242 desc: "required field with incompatible wire type",
1243 checkFastInit: true,
1244 partial: true,
Damien Neilb0c26f12019-12-16 09:37:59 -08001245 decodeTo: []proto.Message{build(
1246 &testpb.TestRequired{},
1247 unknown(pack.Message{
1248 pack.Tag{1, pack.Fixed32Type}, pack.Int32(2),
1249 }.Marshal()),
1250 )},
1251 wire: pack.Message{
1252 pack.Tag{1, pack.Fixed32Type}, pack.Int32(2),
1253 }.Marshal(),
1254 },
1255 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001256 desc: "required field in optional message unset",
1257 checkFastInit: true,
1258 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001259 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1260 OptionalMessage: &testpb.TestRequired{},
1261 }},
1262 wire: pack.Message{
1263 pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
1264 }.Marshal(),
1265 },
1266 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001267 desc: "required field in optional message set",
1268 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001269 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1270 OptionalMessage: &testpb.TestRequired{
1271 RequiredField: proto.Int32(1),
1272 },
1273 }},
1274 wire: pack.Message{
1275 pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
1276 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1277 }),
1278 }.Marshal(),
1279 },
1280 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001281 desc: "required field in optional message set (split across multiple tags)",
1282 checkFastInit: false, // fast init checks don't handle split messages
Damien Neild0b07492019-12-16 12:59:13 -08001283 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1284 OptionalMessage: &testpb.TestRequired{
1285 RequiredField: proto.Int32(1),
1286 },
1287 }},
1288 wire: pack.Message{
1289 pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
1290 pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
1291 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1292 }),
1293 }.Marshal(),
Damien Neilb0c26f12019-12-16 09:37:59 -08001294 validationStatus: impl.ValidationValidMaybeUninitalized,
Damien Neild0b07492019-12-16 12:59:13 -08001295 },
1296 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001297 desc: "required field in repeated message unset",
1298 checkFastInit: true,
1299 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001300 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1301 RepeatedMessage: []*testpb.TestRequired{
1302 {RequiredField: proto.Int32(1)},
1303 {},
1304 },
1305 }},
1306 wire: pack.Message{
1307 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1308 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1309 }),
1310 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
1311 }.Marshal(),
1312 },
1313 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001314 desc: "required field in repeated message set",
1315 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001316 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1317 RepeatedMessage: []*testpb.TestRequired{
1318 {RequiredField: proto.Int32(1)},
1319 {RequiredField: proto.Int32(2)},
1320 },
1321 }},
1322 wire: pack.Message{
1323 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1324 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1325 }),
1326 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1327 pack.Tag{1, pack.VarintType}, pack.Varint(2),
1328 }),
1329 }.Marshal(),
1330 },
1331 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001332 desc: "required field in map message unset",
1333 checkFastInit: true,
1334 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001335 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1336 MapMessage: map[int32]*testpb.TestRequired{
1337 1: {RequiredField: proto.Int32(1)},
1338 2: {},
1339 },
1340 }},
1341 wire: pack.Message{
1342 pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
1343 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1344 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1345 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1346 }),
1347 }),
1348 pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
1349 pack.Tag{1, pack.VarintType}, pack.Varint(2),
1350 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
1351 }),
1352 }.Marshal(),
1353 },
1354 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001355 desc: "required field in absent map message value",
1356 checkFastInit: true,
1357 partial: true,
Damien Neil54a0a042020-01-08 17:53:16 -08001358 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1359 MapMessage: map[int32]*testpb.TestRequired{
1360 2: {},
1361 },
1362 }},
1363 wire: pack.Message{
1364 pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
1365 pack.Tag{1, pack.VarintType}, pack.Varint(2),
1366 }),
1367 }.Marshal(),
1368 },
1369 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001370 desc: "required field in map message set",
1371 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001372 decodeTo: []proto.Message{&testpb.TestRequiredForeign{
1373 MapMessage: map[int32]*testpb.TestRequired{
1374 1: {RequiredField: proto.Int32(1)},
1375 2: {RequiredField: proto.Int32(2)},
1376 },
1377 }},
1378 wire: pack.Message{
1379 pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
1380 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1381 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1382 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1383 }),
1384 }),
1385 pack.Tag{3, pack.BytesType}, pack.LengthPrefix(pack.Message{
1386 pack.Tag{1, pack.VarintType}, pack.Varint(2),
1387 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1388 pack.Tag{1, pack.VarintType}, pack.Varint(2),
1389 }),
1390 }),
1391 }.Marshal(),
1392 },
1393 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001394 desc: "required field in optional group unset",
1395 checkFastInit: true,
1396 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001397 decodeTo: []proto.Message{&testpb.TestRequiredGroupFields{
1398 Optionalgroup: &testpb.TestRequiredGroupFields_OptionalGroup{},
1399 }},
1400 wire: pack.Message{
1401 pack.Tag{1, pack.StartGroupType},
1402 pack.Tag{1, pack.EndGroupType},
1403 }.Marshal(),
1404 },
1405 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001406 desc: "required field in optional group set",
1407 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001408 decodeTo: []proto.Message{&testpb.TestRequiredGroupFields{
1409 Optionalgroup: &testpb.TestRequiredGroupFields_OptionalGroup{
1410 A: proto.Int32(1),
1411 },
1412 }},
1413 wire: pack.Message{
1414 pack.Tag{1, pack.StartGroupType},
1415 pack.Tag{2, pack.VarintType}, pack.Varint(1),
1416 pack.Tag{1, pack.EndGroupType},
1417 }.Marshal(),
1418 },
1419 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001420 desc: "required field in repeated group unset",
1421 checkFastInit: true,
1422 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001423 decodeTo: []proto.Message{&testpb.TestRequiredGroupFields{
1424 Repeatedgroup: []*testpb.TestRequiredGroupFields_RepeatedGroup{
1425 {A: proto.Int32(1)},
1426 {},
1427 },
1428 }},
1429 wire: pack.Message{
1430 pack.Tag{3, pack.StartGroupType},
1431 pack.Tag{4, pack.VarintType}, pack.Varint(1),
1432 pack.Tag{3, pack.EndGroupType},
1433 pack.Tag{3, pack.StartGroupType},
1434 pack.Tag{3, pack.EndGroupType},
1435 }.Marshal(),
1436 },
1437 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001438 desc: "required field in repeated group set",
1439 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001440 decodeTo: []proto.Message{&testpb.TestRequiredGroupFields{
1441 Repeatedgroup: []*testpb.TestRequiredGroupFields_RepeatedGroup{
1442 {A: proto.Int32(1)},
1443 {A: proto.Int32(2)},
1444 },
1445 }},
1446 wire: pack.Message{
1447 pack.Tag{3, pack.StartGroupType},
1448 pack.Tag{4, pack.VarintType}, pack.Varint(1),
1449 pack.Tag{3, pack.EndGroupType},
1450 pack.Tag{3, pack.StartGroupType},
1451 pack.Tag{4, pack.VarintType}, pack.Varint(2),
1452 pack.Tag{3, pack.EndGroupType},
1453 }.Marshal(),
1454 },
1455 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001456 desc: "required field in oneof message unset",
1457 checkFastInit: true,
1458 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001459 decodeTo: []proto.Message{
1460 &testpb.TestRequiredForeign{OneofField: &testpb.TestRequiredForeign_OneofMessage{
1461 &testpb.TestRequired{},
1462 }},
1463 },
1464 wire: pack.Message{pack.Tag{4, pack.BytesType}, pack.LengthPrefix(pack.Message{})}.Marshal(),
1465 },
1466 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001467 desc: "required field in oneof message set",
1468 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001469 decodeTo: []proto.Message{
1470 &testpb.TestRequiredForeign{OneofField: &testpb.TestRequiredForeign_OneofMessage{
1471 &testpb.TestRequired{
1472 RequiredField: proto.Int32(1),
1473 },
1474 }},
1475 },
1476 wire: pack.Message{pack.Tag{4, pack.BytesType}, pack.LengthPrefix(pack.Message{
1477 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1478 })}.Marshal(),
1479 },
1480 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001481 desc: "required field in extension message unset",
1482 checkFastInit: true,
1483 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001484 decodeTo: []proto.Message{build(
1485 &testpb.TestAllExtensions{},
1486 extend(testpb.E_TestRequired_Single, &testpb.TestRequired{}),
1487 )},
1488 wire: pack.Message{
1489 pack.Tag{1000, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
1490 }.Marshal(),
1491 },
1492 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001493 desc: "required field in extension message set",
1494 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001495 decodeTo: []proto.Message{build(
1496 &testpb.TestAllExtensions{},
1497 extend(testpb.E_TestRequired_Single, &testpb.TestRequired{
1498 RequiredField: proto.Int32(1),
1499 }),
1500 )},
1501 wire: pack.Message{
1502 pack.Tag{1000, pack.BytesType}, pack.LengthPrefix(pack.Message{
1503 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1504 }),
1505 }.Marshal(),
1506 },
1507 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001508 desc: "required field in repeated extension message unset",
1509 checkFastInit: true,
1510 partial: true,
Damien Neild0b07492019-12-16 12:59:13 -08001511 decodeTo: []proto.Message{build(
1512 &testpb.TestAllExtensions{},
1513 extend(testpb.E_TestRequired_Multi, []*testpb.TestRequired{
1514 {RequiredField: proto.Int32(1)},
1515 {},
1516 }),
1517 )},
1518 wire: pack.Message{
1519 pack.Tag{1001, pack.BytesType}, pack.LengthPrefix(pack.Message{
1520 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1521 }),
1522 pack.Tag{1001, pack.BytesType}, pack.LengthPrefix(pack.Message{}),
1523 }.Marshal(),
1524 },
1525 {
Damien Neilc600d6c2020-01-21 15:00:33 -08001526 desc: "required field in repeated extension message set",
1527 checkFastInit: true,
Damien Neild0b07492019-12-16 12:59:13 -08001528 decodeTo: []proto.Message{build(
1529 &testpb.TestAllExtensions{},
1530 extend(testpb.E_TestRequired_Multi, []*testpb.TestRequired{
1531 {RequiredField: proto.Int32(1)},
1532 {RequiredField: proto.Int32(2)},
1533 }),
1534 )},
1535 wire: pack.Message{
1536 pack.Tag{1001, pack.BytesType}, pack.LengthPrefix(pack.Message{
1537 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1538 }),
1539 pack.Tag{1001, pack.BytesType}, pack.LengthPrefix(pack.Message{
1540 pack.Tag{1, pack.VarintType}, pack.Varint(2),
1541 }),
1542 }.Marshal(),
1543 },
1544 {
1545 desc: "nil messages",
1546 decodeTo: []proto.Message{
1547 (*testpb.TestAllTypes)(nil),
1548 (*test3pb.TestAllTypes)(nil),
1549 (*testpb.TestAllExtensions)(nil),
1550 },
1551 },
1552 {
1553 desc: "legacy",
1554 partial: true,
1555 decodeTo: []proto.Message{
1556 &legacypb.Legacy{
1557 F1: &legacy1pb.Message{
1558 OptionalInt32: proto.Int32(1),
1559 OptionalChildEnum: legacy1pb.Message_ALPHA.Enum(),
1560 OptionalChildMessage: &legacy1pb.Message_ChildMessage{
1561 F1: proto.String("x"),
1562 },
1563 Optionalgroup: &legacy1pb.Message_OptionalGroup{
1564 F1: proto.String("x"),
1565 },
1566 RepeatedChildMessage: []*legacy1pb.Message_ChildMessage{
1567 {F1: proto.String("x")},
1568 },
1569 Repeatedgroup: []*legacy1pb.Message_RepeatedGroup{
1570 {F1: proto.String("x")},
1571 },
1572 MapBoolChildMessage: map[bool]*legacy1pb.Message_ChildMessage{
1573 true: {F1: proto.String("x")},
1574 },
1575 OneofUnion: &legacy1pb.Message_OneofChildMessage{
1576 &legacy1pb.Message_ChildMessage{
1577 F1: proto.String("x"),
1578 },
1579 },
1580 },
1581 },
1582 },
1583 wire: pack.Message{
1584 pack.Tag{1, pack.BytesType}, pack.LengthPrefix(pack.Message{
1585 pack.Tag{101, pack.VarintType}, pack.Varint(1),
1586 pack.Tag{115, pack.VarintType}, pack.Varint(0),
1587 pack.Tag{116, pack.BytesType}, pack.LengthPrefix(pack.Message{
1588 pack.Tag{1, pack.BytesType}, pack.String("x"),
1589 }),
1590 pack.Tag{120, pack.StartGroupType},
1591 pack.Tag{1, pack.BytesType}, pack.String("x"),
1592 pack.Tag{120, pack.EndGroupType},
1593 pack.Tag{516, pack.BytesType}, pack.LengthPrefix(pack.Message{
1594 pack.Tag{1, pack.BytesType}, pack.String("x"),
1595 }),
1596 pack.Tag{520, pack.StartGroupType},
1597 pack.Tag{1, pack.BytesType}, pack.String("x"),
1598 pack.Tag{520, pack.EndGroupType},
1599 pack.Tag{616, pack.BytesType}, pack.LengthPrefix(pack.Message{
1600 pack.Tag{1, pack.VarintType}, pack.Varint(1),
1601 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1602 pack.Tag{1, pack.BytesType}, pack.String("x"),
1603 }),
1604 }),
1605 pack.Tag{716, pack.BytesType}, pack.LengthPrefix(pack.Message{
1606 pack.Tag{1, pack.BytesType}, pack.String("x"),
1607 }),
1608 }),
1609 }.Marshal(),
Damien Neilb0c26f12019-12-16 09:37:59 -08001610 validationStatus: impl.ValidationUnknown,
Damien Neild0b07492019-12-16 12:59:13 -08001611 },
1612 {
1613 desc: "first reserved field number",
1614 decodeTo: []proto.Message{build(
1615 &testpb.TestAllTypes{},
1616 unknown(pack.Message{
1617 pack.Tag{pack.FirstReservedNumber, pack.VarintType}, pack.Varint(1004),
1618 }.Marshal()),
1619 )},
1620 wire: pack.Message{
1621 pack.Tag{pack.FirstReservedNumber, pack.VarintType}, pack.Varint(1004),
1622 }.Marshal(),
1623 },
1624 {
1625 desc: "last reserved field number",
1626 decodeTo: []proto.Message{build(
1627 &testpb.TestAllTypes{},
1628 unknown(pack.Message{
1629 pack.Tag{pack.LastReservedNumber, pack.VarintType}, pack.Varint(1005),
1630 }.Marshal()),
1631 )},
1632 wire: pack.Message{
1633 pack.Tag{pack.LastReservedNumber, pack.VarintType}, pack.Varint(1005),
1634 }.Marshal(),
1635 },
Damien Neila60e7092020-01-28 14:53:44 -08001636 {
1637 desc: "nested unknown extension",
1638 unmarshalOptions: proto.UnmarshalOptions{
1639 DiscardUnknown: true,
1640 Resolver: func() protoregistry.ExtensionTypeResolver {
1641 types := &protoregistry.Types{}
1642 types.RegisterExtension(testpb.E_OptionalNestedMessageExtension)
1643 types.RegisterExtension(testpb.E_OptionalInt32Extension)
1644 return types
1645 }(),
1646 },
1647 decodeTo: []proto.Message{func() proto.Message {
1648 m := &testpb.TestAllExtensions{}
1649 if err := prototext.Unmarshal([]byte(`
1650 [goproto.proto.test.optional_nested_message_extension]: {
1651 corecursive: {
1652 [goproto.proto.test.optional_nested_message_extension]: {
1653 corecursive: {
1654 [goproto.proto.test.optional_int32_extension]: 42
1655 }
1656 }
1657 }
1658 }`), m); err != nil {
1659 panic(err)
1660 }
1661 return m
1662 }()},
1663 wire: pack.Message{
1664 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
1665 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1666 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
1667 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1668 pack.Tag{1, pack.VarintType}, pack.Varint(42),
1669 pack.Tag{2, pack.VarintType}, pack.Varint(43),
1670 }),
1671 }),
1672 }),
1673 }),
1674 }.Marshal(),
1675 },
Damien Neild0b07492019-12-16 12:59:13 -08001676}
1677
1678var testInvalidMessages = []testProto{
1679 {
1680 desc: "invalid UTF-8 in optional string field",
1681 decodeTo: []proto.Message{&test3pb.TestAllTypes{
1682 OptionalString: "abc\xff",
1683 }},
1684 wire: pack.Message{
1685 pack.Tag{14, pack.BytesType}, pack.String("abc\xff"),
1686 }.Marshal(),
1687 },
1688 {
1689 desc: "invalid UTF-8 in repeated string field",
1690 decodeTo: []proto.Message{&test3pb.TestAllTypes{
1691 RepeatedString: []string{"foo", "abc\xff"},
1692 }},
1693 wire: pack.Message{
1694 pack.Tag{44, pack.BytesType}, pack.String("foo"),
1695 pack.Tag{44, pack.BytesType}, pack.String("abc\xff"),
1696 }.Marshal(),
1697 },
1698 {
1699 desc: "invalid UTF-8 in nested message",
1700 decodeTo: []proto.Message{&test3pb.TestAllTypes{
1701 OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
1702 Corecursive: &test3pb.TestAllTypes{
1703 OptionalString: "abc\xff",
1704 },
1705 },
1706 }},
1707 wire: pack.Message{
1708 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
1709 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1710 pack.Tag{14, pack.BytesType}, pack.String("abc\xff"),
1711 }),
1712 }),
1713 }.Marshal(),
1714 },
1715 {
1716 desc: "invalid UTF-8 in oneof field",
1717 decodeTo: []proto.Message{
1718 &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofString{"abc\xff"}},
1719 },
1720 wire: pack.Message{pack.Tag{113, pack.BytesType}, pack.String("abc\xff")}.Marshal(),
1721 },
1722 {
1723 desc: "invalid UTF-8 in map key",
1724 decodeTo: []proto.Message{&test3pb.TestAllTypes{
1725 MapStringString: map[string]string{"key\xff": "val"},
1726 }},
1727 wire: pack.Message{
1728 pack.Tag{69, pack.BytesType}, pack.LengthPrefix(pack.Message{
1729 pack.Tag{1, pack.BytesType}, pack.String("key\xff"),
1730 pack.Tag{2, pack.BytesType}, pack.String("val"),
1731 }),
1732 }.Marshal(),
1733 },
1734 {
1735 desc: "invalid UTF-8 in map value",
1736 decodeTo: []proto.Message{&test3pb.TestAllTypes{
1737 MapStringString: map[string]string{"key": "val\xff"},
1738 }},
1739 wire: pack.Message{
1740 pack.Tag{69, pack.BytesType}, pack.LengthPrefix(pack.Message{
1741 pack.Tag{1, pack.BytesType}, pack.String("key"),
1742 pack.Tag{2, pack.BytesType}, pack.String("val\xff"),
1743 }),
1744 }.Marshal(),
1745 },
1746 {
Damien Neilb0c26f12019-12-16 09:37:59 -08001747 desc: "invalid field number zero",
1748 decodeTo: []proto.Message{
1749 (*testpb.TestAllTypes)(nil),
1750 (*testpb.TestAllExtensions)(nil),
1751 },
Damien Neild0b07492019-12-16 12:59:13 -08001752 wire: pack.Message{
1753 pack.Tag{pack.MinValidNumber - 1, pack.VarintType}, pack.Varint(1001),
1754 }.Marshal(),
1755 },
1756 {
Damien Neilb0c26f12019-12-16 09:37:59 -08001757 desc: "invalid field numbers zero and one",
1758 decodeTo: []proto.Message{
1759 (*testpb.TestAllTypes)(nil),
1760 (*testpb.TestAllExtensions)(nil),
1761 },
Damien Neild0b07492019-12-16 12:59:13 -08001762 wire: pack.Message{
1763 pack.Tag{pack.MinValidNumber - 1, pack.VarintType}, pack.Varint(1002),
1764 pack.Tag{pack.MinValidNumber, pack.VarintType}, pack.Varint(1003),
1765 }.Marshal(),
1766 },
1767 {
Damien Neilb0c26f12019-12-16 09:37:59 -08001768 desc: "invalid field numbers max and max+1",
1769 decodeTo: []proto.Message{
1770 (*testpb.TestAllTypes)(nil),
1771 (*testpb.TestAllExtensions)(nil),
1772 },
Damien Neild0b07492019-12-16 12:59:13 -08001773 wire: pack.Message{
1774 pack.Tag{pack.MaxValidNumber, pack.VarintType}, pack.Varint(1006),
1775 pack.Tag{pack.MaxValidNumber + 1, pack.VarintType}, pack.Varint(1007),
1776 }.Marshal(),
1777 },
1778 {
Damien Neilb0c26f12019-12-16 09:37:59 -08001779 desc: "invalid field number max+1",
1780 decodeTo: []proto.Message{
1781 (*testpb.TestAllTypes)(nil),
1782 (*testpb.TestAllExtensions)(nil),
1783 },
Damien Neild0b07492019-12-16 12:59:13 -08001784 wire: pack.Message{
1785 pack.Tag{pack.MaxValidNumber + 1, pack.VarintType}, pack.Varint(1008),
1786 }.Marshal(),
1787 },
Damien Neilf2427c02019-12-20 09:43:20 -08001788 {
1789 desc: "invalid field number in map",
1790 decodeTo: []proto.Message{(*testpb.TestAllTypes)(nil)},
1791 wire: pack.Message{
1792 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
1793 pack.Tag{1, pack.VarintType}, pack.Varint(1056),
1794 pack.Tag{2, pack.VarintType}, pack.Varint(1156),
1795 pack.Tag{pack.MaxValidNumber + 1, pack.VarintType}, pack.Varint(0),
1796 }),
1797 }.Marshal(),
1798 },
Damien Neilb0c26f12019-12-16 09:37:59 -08001799 {
1800 desc: "invalid tag varint",
1801 decodeTo: []proto.Message{
1802 (*testpb.TestAllTypes)(nil),
1803 (*testpb.TestAllExtensions)(nil),
1804 },
1805 wire: []byte{0xff},
1806 },
1807 {
1808 desc: "field number too small",
1809 decodeTo: []proto.Message{
1810 (*testpb.TestAllTypes)(nil),
1811 (*testpb.TestAllExtensions)(nil),
1812 },
1813 wire: pack.Message{
1814 pack.Tag{0, pack.VarintType}, pack.Varint(0),
1815 }.Marshal(),
1816 },
1817 {
1818 desc: "field number too large",
1819 decodeTo: []proto.Message{
1820 (*testpb.TestAllTypes)(nil),
1821 (*testpb.TestAllExtensions)(nil),
1822 },
1823 wire: pack.Message{
1824 pack.Tag{wire.MaxValidNumber + 1, pack.VarintType}, pack.Varint(0),
1825 }.Marshal(),
1826 },
1827 {
1828 desc: "invalid tag varint in message field",
1829 decodeTo: []proto.Message{
1830 (*testpb.TestAllTypes)(nil),
1831 (*testpb.TestAllExtensions)(nil),
1832 },
1833 wire: pack.Message{
1834 pack.Tag{18, pack.BytesType}, pack.LengthPrefix(pack.Message{
1835 pack.Raw{0xff},
1836 }),
1837 }.Marshal(),
1838 },
1839 {
1840 desc: "invalid tag varint in repeated message field",
1841 decodeTo: []proto.Message{
1842 (*testpb.TestAllTypes)(nil),
1843 (*testpb.TestAllExtensions)(nil),
1844 },
1845 wire: pack.Message{
1846 pack.Tag{48, pack.BytesType}, pack.LengthPrefix(pack.Message{
1847 pack.Raw{0xff},
1848 }),
1849 }.Marshal(),
1850 },
1851 {
1852 desc: "invalid varint in group field",
1853 decodeTo: []proto.Message{
1854 (*testpb.TestAllTypes)(nil),
1855 (*testpb.TestAllExtensions)(nil),
1856 },
1857 wire: pack.Message{
1858 pack.Tag{16, pack.StartGroupType},
1859 pack.Tag{1000, pack.BytesType}, pack.LengthPrefix(pack.Message{
1860 pack.Raw{0xff},
1861 }),
1862 pack.Tag{16, pack.EndGroupType},
1863 }.Marshal(),
1864 },
1865 {
1866 desc: "invalid varint in repeated group field",
1867 decodeTo: []proto.Message{
1868 (*testpb.TestAllTypes)(nil),
1869 (*testpb.TestAllExtensions)(nil),
1870 },
1871 wire: pack.Message{
1872 pack.Tag{46, pack.StartGroupType},
1873 pack.Tag{1001, pack.BytesType}, pack.LengthPrefix(pack.Message{
1874 pack.Raw{0xff},
1875 }),
1876 pack.Tag{46, pack.EndGroupType},
1877 }.Marshal(),
1878 },
1879 {
1880 desc: "unterminated repeated group field",
1881 decodeTo: []proto.Message{
1882 (*testpb.TestAllTypes)(nil),
1883 (*testpb.TestAllExtensions)(nil),
1884 },
1885 wire: pack.Message{
1886 pack.Tag{46, pack.StartGroupType},
1887 }.Marshal(),
1888 },
1889 {
1890 desc: "invalid tag varint in map item",
1891 decodeTo: []proto.Message{
1892 (*testpb.TestAllTypes)(nil),
1893 },
1894 wire: pack.Message{
1895 pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
1896 pack.Tag{1, pack.VarintType}, pack.Varint(0),
1897 pack.Tag{2, pack.VarintType}, pack.Varint(0),
1898 pack.Raw{0xff},
1899 }),
1900 }.Marshal(),
1901 },
1902 {
1903 desc: "invalid tag varint in map message value",
1904 decodeTo: []proto.Message{
1905 (*testpb.TestAllTypes)(nil),
1906 },
1907 wire: pack.Message{
1908 pack.Tag{71, pack.BytesType}, pack.LengthPrefix(pack.Message{
1909 pack.Tag{1, pack.VarintType}, pack.Varint(0),
1910 pack.Tag{2, pack.BytesType}, pack.LengthPrefix(pack.Message{
1911 pack.Raw{0xff},
1912 }),
1913 }),
1914 }.Marshal(),
1915 },
1916 {
1917 desc: "invalid packed int32 field",
1918 decodeTo: []proto.Message{
1919 (*testpb.TestAllTypes)(nil),
1920 (*testpb.TestAllExtensions)(nil),
1921 },
1922 wire: pack.Message{
1923 pack.Tag{31, pack.BytesType}, pack.Bytes{0xff},
1924 }.Marshal(),
1925 },
1926 {
1927 desc: "invalid packed int64 field",
1928 decodeTo: []proto.Message{
1929 (*testpb.TestAllTypes)(nil),
1930 (*testpb.TestAllExtensions)(nil),
1931 },
1932 wire: pack.Message{
1933 pack.Tag{32, pack.BytesType}, pack.Bytes{0xff},
1934 }.Marshal(),
1935 },
1936 {
1937 desc: "invalid packed uint32 field",
1938 decodeTo: []proto.Message{
1939 (*testpb.TestAllTypes)(nil),
1940 (*testpb.TestAllExtensions)(nil),
1941 },
1942 wire: pack.Message{
1943 pack.Tag{33, pack.BytesType}, pack.Bytes{0xff},
1944 }.Marshal(),
1945 },
1946 {
1947 desc: "invalid packed uint64 field",
1948 decodeTo: []proto.Message{
1949 (*testpb.TestAllTypes)(nil),
1950 (*testpb.TestAllExtensions)(nil),
1951 },
1952 wire: pack.Message{
1953 pack.Tag{34, pack.BytesType}, pack.Bytes{0xff},
1954 }.Marshal(),
1955 },
1956 {
1957 desc: "invalid packed sint32 field",
1958 decodeTo: []proto.Message{
1959 (*testpb.TestAllTypes)(nil),
1960 (*testpb.TestAllExtensions)(nil),
1961 },
1962 wire: pack.Message{
1963 pack.Tag{35, pack.BytesType}, pack.Bytes{0xff},
1964 }.Marshal(),
1965 },
1966 {
1967 desc: "invalid packed sint64 field",
1968 decodeTo: []proto.Message{
1969 (*testpb.TestAllTypes)(nil),
1970 (*testpb.TestAllExtensions)(nil),
1971 },
1972 wire: pack.Message{
1973 pack.Tag{36, pack.BytesType}, pack.Bytes{0xff},
1974 }.Marshal(),
1975 },
1976 {
1977 desc: "invalid packed fixed32 field",
1978 decodeTo: []proto.Message{
1979 (*testpb.TestAllTypes)(nil),
1980 (*testpb.TestAllExtensions)(nil),
1981 },
1982 wire: pack.Message{
1983 pack.Tag{37, pack.BytesType}, pack.Bytes{0x00},
1984 }.Marshal(),
1985 },
1986 {
1987 desc: "invalid packed fixed64 field",
1988 decodeTo: []proto.Message{
1989 (*testpb.TestAllTypes)(nil),
1990 (*testpb.TestAllExtensions)(nil),
1991 },
1992 wire: pack.Message{
1993 pack.Tag{38, pack.BytesType}, pack.Bytes{0x00},
1994 }.Marshal(),
1995 },
1996 {
1997 desc: "invalid packed sfixed32 field",
1998 decodeTo: []proto.Message{
1999 (*testpb.TestAllTypes)(nil),
2000 (*testpb.TestAllExtensions)(nil),
2001 },
2002 wire: pack.Message{
2003 pack.Tag{39, pack.BytesType}, pack.Bytes{0x00},
2004 }.Marshal(),
2005 },
2006 {
2007 desc: "invalid packed sfixed64 field",
2008 decodeTo: []proto.Message{
2009 (*testpb.TestAllTypes)(nil),
2010 (*testpb.TestAllExtensions)(nil),
2011 },
2012 wire: pack.Message{
2013 pack.Tag{40, pack.BytesType}, pack.Bytes{0x00},
2014 }.Marshal(),
2015 },
2016 {
2017 desc: "invalid packed float field",
2018 decodeTo: []proto.Message{
2019 (*testpb.TestAllTypes)(nil),
2020 (*testpb.TestAllExtensions)(nil),
2021 },
2022 wire: pack.Message{
2023 pack.Tag{41, pack.BytesType}, pack.Bytes{0x00},
2024 }.Marshal(),
2025 },
2026 {
2027 desc: "invalid packed double field",
2028 decodeTo: []proto.Message{
2029 (*testpb.TestAllTypes)(nil),
2030 (*testpb.TestAllExtensions)(nil),
2031 },
2032 wire: pack.Message{
2033 pack.Tag{42, pack.BytesType}, pack.Bytes{0x00},
2034 }.Marshal(),
2035 },
2036 {
2037 desc: "invalid packed bool field",
2038 decodeTo: []proto.Message{
2039 (*testpb.TestAllTypes)(nil),
2040 (*testpb.TestAllExtensions)(nil),
2041 },
2042 wire: pack.Message{
2043 pack.Tag{43, pack.BytesType}, pack.Bytes{0xff},
2044 }.Marshal(),
2045 },
2046 {
2047 desc: "bytes field overruns message",
2048 decodeTo: []proto.Message{
2049 (*testpb.TestAllTypes)(nil),
2050 (*testpb.TestAllExtensions)(nil),
2051 },
2052 wire: pack.Message{
2053 pack.Tag{18, pack.BytesType}, pack.LengthPrefix{pack.Message{
2054 pack.Tag{2, pack.BytesType}, pack.LengthPrefix{pack.Message{
2055 pack.Tag{15, pack.BytesType}, pack.Varint(2),
2056 }},
2057 pack.Tag{1, pack.VarintType}, pack.Varint(0),
2058 }},
2059 }.Marshal(),
2060 },
Damien Neild0b07492019-12-16 12:59:13 -08002061}