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