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