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