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