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