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