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