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