github.com/m3db/m3@v1.5.0/src/metrics/generated/proto/metricpb/custom_unmarshal.go (about) 1 // Copyright (c) 2021 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package metricpb 22 23 import ( 24 "fmt" 25 "io" 26 27 "github.com/m3db/m3/src/metrics/generated/proto/aggregationpb" 28 "github.com/m3db/m3/src/metrics/generated/proto/policypb" 29 ) 30 31 // Unmarshal is a manual copy of the generated Unmarshal that allows reusing slices. 32 func (m *PipelineMetadata) Unmarshal(dAtA []byte) error { 33 l := len(dAtA) 34 iNdEx := 0 35 for iNdEx < l { 36 preIndex := iNdEx 37 var wire uint64 38 for shift := uint(0); ; shift += 7 { 39 if shift >= 64 { 40 return ErrIntOverflowMetadata 41 } 42 if iNdEx >= l { 43 return io.ErrUnexpectedEOF 44 } 45 b := dAtA[iNdEx] 46 iNdEx++ 47 wire |= (uint64(b) & 0x7F) << shift 48 if b < 0x80 { 49 break 50 } 51 } 52 fieldNum := int32(wire >> 3) 53 wireType := int(wire & 0x7) 54 if wireType == 4 { 55 return fmt.Errorf("proto: PipelineMetadata: wiretype end group for non-group") 56 } 57 if fieldNum <= 0 { 58 return fmt.Errorf("proto: PipelineMetadata: illegal tag %d (wire type %d)", fieldNum, wire) 59 } 60 switch fieldNum { 61 case 1: 62 if wireType != 2 { 63 return fmt.Errorf("proto: wrong wireType = %d for field AggregationId", wireType) 64 } 65 var msglen int 66 for shift := uint(0); ; shift += 7 { 67 if shift >= 64 { 68 return ErrIntOverflowMetadata 69 } 70 if iNdEx >= l { 71 return io.ErrUnexpectedEOF 72 } 73 b := dAtA[iNdEx] 74 iNdEx++ 75 msglen |= (int(b) & 0x7F) << shift 76 if b < 0x80 { 77 break 78 } 79 } 80 if msglen < 0 { 81 return ErrInvalidLengthMetadata 82 } 83 postIndex := iNdEx + msglen 84 if postIndex > l { 85 return io.ErrUnexpectedEOF 86 } 87 if err := m.AggregationId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 88 return err 89 } 90 iNdEx = postIndex 91 case 2: 92 if wireType != 2 { 93 return fmt.Errorf("proto: wrong wireType = %d for field StoragePolicies", wireType) 94 } 95 var msglen int 96 for shift := uint(0); ; shift += 7 { 97 if shift >= 64 { 98 return ErrIntOverflowMetadata 99 } 100 if iNdEx >= l { 101 return io.ErrUnexpectedEOF 102 } 103 b := dAtA[iNdEx] 104 iNdEx++ 105 msglen |= (int(b) & 0x7F) << shift 106 if b < 0x80 { 107 break 108 } 109 } 110 if msglen < 0 { 111 return ErrInvalidLengthMetadata 112 } 113 postIndex := iNdEx + msglen 114 if postIndex > l { 115 return io.ErrUnexpectedEOF 116 } 117 if cap(m.StoragePolicies) > len(m.StoragePolicies) { 118 m.StoragePolicies = m.StoragePolicies[0 : len(m.StoragePolicies)+1] 119 } else { 120 m.StoragePolicies = append(m.StoragePolicies, policypb.StoragePolicy{}) 121 } 122 if err := m.StoragePolicies[len(m.StoragePolicies)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 123 return err 124 } 125 iNdEx = postIndex 126 case 3: 127 if wireType != 2 { 128 return fmt.Errorf("proto: wrong wireType = %d for field Pipeline", wireType) 129 } 130 var msglen int 131 for shift := uint(0); ; shift += 7 { 132 if shift >= 64 { 133 return ErrIntOverflowMetadata 134 } 135 if iNdEx >= l { 136 return io.ErrUnexpectedEOF 137 } 138 b := dAtA[iNdEx] 139 iNdEx++ 140 msglen |= (int(b) & 0x7F) << shift 141 if b < 0x80 { 142 break 143 } 144 } 145 if msglen < 0 { 146 return ErrInvalidLengthMetadata 147 } 148 postIndex := iNdEx + msglen 149 if postIndex > l { 150 return io.ErrUnexpectedEOF 151 } 152 if err := m.Pipeline.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 153 return err 154 } 155 iNdEx = postIndex 156 case 4: 157 if wireType != 0 { 158 return fmt.Errorf("proto: wrong wireType = %d for field DropPolicy", wireType) 159 } 160 m.DropPolicy = 0 161 for shift := uint(0); ; shift += 7 { 162 if shift >= 64 { 163 return ErrIntOverflowMetadata 164 } 165 if iNdEx >= l { 166 return io.ErrUnexpectedEOF 167 } 168 b := dAtA[iNdEx] 169 iNdEx++ 170 m.DropPolicy |= (policypb.DropPolicy(b) & 0x7F) << shift 171 if b < 0x80 { 172 break 173 } 174 } 175 case 5: 176 if wireType != 0 { 177 return fmt.Errorf("proto: wrong wireType = %d for field ResendEnabled", wireType) 178 } 179 var v int 180 for shift := uint(0); ; shift += 7 { 181 if shift >= 64 { 182 return ErrIntOverflowMetadata 183 } 184 if iNdEx >= l { 185 return io.ErrUnexpectedEOF 186 } 187 b := dAtA[iNdEx] 188 iNdEx++ 189 v |= (int(b) & 0x7F) << shift 190 if b < 0x80 { 191 break 192 } 193 } 194 m.ResendEnabled = bool(v != 0) 195 default: 196 iNdEx = preIndex 197 skippy, err := skipMetadata(dAtA[iNdEx:]) 198 if err != nil { 199 return err 200 } 201 if skippy < 0 { 202 return ErrInvalidLengthMetadata 203 } 204 if (iNdEx + skippy) > l { 205 return io.ErrUnexpectedEOF 206 } 207 iNdEx += skippy 208 } 209 } 210 211 if iNdEx > l { 212 return io.ErrUnexpectedEOF 213 } 214 return nil 215 } 216 217 // Unmarshal is a manual copy of the generated Unmarshal that allows reusing slices. 218 func (m *Metadata) Unmarshal(dAtA []byte) error { 219 l := len(dAtA) 220 iNdEx := 0 221 for iNdEx < l { 222 preIndex := iNdEx 223 var wire uint64 224 for shift := uint(0); ; shift += 7 { 225 if shift >= 64 { 226 return ErrIntOverflowMetadata 227 } 228 if iNdEx >= l { 229 return io.ErrUnexpectedEOF 230 } 231 b := dAtA[iNdEx] 232 iNdEx++ 233 wire |= (uint64(b) & 0x7F) << shift 234 if b < 0x80 { 235 break 236 } 237 } 238 fieldNum := int32(wire >> 3) 239 wireType := int(wire & 0x7) 240 if wireType == 4 { 241 return fmt.Errorf("proto: Metadata: wiretype end group for non-group") 242 } 243 if fieldNum <= 0 { 244 return fmt.Errorf("proto: Metadata: illegal tag %d (wire type %d)", fieldNum, wire) 245 } 246 switch fieldNum { 247 case 1: 248 if wireType != 2 { 249 return fmt.Errorf("proto: wrong wireType = %d for field Pipelines", wireType) 250 } 251 var msglen int 252 for shift := uint(0); ; shift += 7 { 253 if shift >= 64 { 254 return ErrIntOverflowMetadata 255 } 256 if iNdEx >= l { 257 return io.ErrUnexpectedEOF 258 } 259 b := dAtA[iNdEx] 260 iNdEx++ 261 msglen |= (int(b) & 0x7F) << shift 262 if b < 0x80 { 263 break 264 } 265 } 266 if msglen < 0 { 267 return ErrInvalidLengthMetadata 268 } 269 postIndex := iNdEx + msglen 270 if postIndex > l { 271 return io.ErrUnexpectedEOF 272 } 273 if cap(m.Pipelines) > len(m.Pipelines) { 274 m.Pipelines = m.Pipelines[0 : len(m.Pipelines)+1] 275 } else { 276 m.Pipelines = append(m.Pipelines, PipelineMetadata{}) 277 } 278 if err := m.Pipelines[len(m.Pipelines)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 279 return err 280 } 281 iNdEx = postIndex 282 default: 283 iNdEx = preIndex 284 skippy, err := skipMetadata(dAtA[iNdEx:]) 285 if err != nil { 286 return err 287 } 288 if skippy < 0 { 289 return ErrInvalidLengthMetadata 290 } 291 if (iNdEx + skippy) > l { 292 return io.ErrUnexpectedEOF 293 } 294 iNdEx += skippy 295 } 296 } 297 298 if iNdEx > l { 299 return io.ErrUnexpectedEOF 300 } 301 return nil 302 } 303 304 // Unmarshal is a manual copy of the generated Unmarshal that allows reusing slices. 305 func (m *StagedMetadatas) Unmarshal(dAtA []byte) error { 306 l := len(dAtA) 307 iNdEx := 0 308 for iNdEx < l { 309 preIndex := iNdEx 310 var wire uint64 311 for shift := uint(0); ; shift += 7 { 312 if shift >= 64 { 313 return ErrIntOverflowMetadata 314 } 315 if iNdEx >= l { 316 return io.ErrUnexpectedEOF 317 } 318 b := dAtA[iNdEx] 319 iNdEx++ 320 wire |= (uint64(b) & 0x7F) << shift 321 if b < 0x80 { 322 break 323 } 324 } 325 fieldNum := int32(wire >> 3) 326 wireType := int(wire & 0x7) 327 if wireType == 4 { 328 return fmt.Errorf("proto: StagedMetadatas: wiretype end group for non-group") 329 } 330 if fieldNum <= 0 { 331 return fmt.Errorf("proto: StagedMetadatas: illegal tag %d (wire type %d)", fieldNum, wire) 332 } 333 switch fieldNum { 334 case 1: 335 if wireType != 2 { 336 return fmt.Errorf("proto: wrong wireType = %d for field Metadatas", wireType) 337 } 338 var msglen int 339 for shift := uint(0); ; shift += 7 { 340 if shift >= 64 { 341 return ErrIntOverflowMetadata 342 } 343 if iNdEx >= l { 344 return io.ErrUnexpectedEOF 345 } 346 b := dAtA[iNdEx] 347 iNdEx++ 348 msglen |= (int(b) & 0x7F) << shift 349 if b < 0x80 { 350 break 351 } 352 } 353 if msglen < 0 { 354 return ErrInvalidLengthMetadata 355 } 356 postIndex := iNdEx + msglen 357 if postIndex > l { 358 return io.ErrUnexpectedEOF 359 } 360 if cap(m.Metadatas) > len(m.Metadatas) { 361 m.Metadatas = m.Metadatas[0 : len(m.Metadatas)+1] 362 } else { 363 m.Metadatas = append(m.Metadatas, StagedMetadata{}) 364 } 365 if err := m.Metadatas[len(m.Metadatas)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 366 return err 367 } 368 iNdEx = postIndex 369 default: 370 iNdEx = preIndex 371 skippy, err := skipMetadata(dAtA[iNdEx:]) 372 if err != nil { 373 return err 374 } 375 if skippy < 0 { 376 return ErrInvalidLengthMetadata 377 } 378 if (iNdEx + skippy) > l { 379 return io.ErrUnexpectedEOF 380 } 381 iNdEx += skippy 382 } 383 } 384 385 if iNdEx > l { 386 return io.ErrUnexpectedEOF 387 } 388 return nil 389 } 390 391 func (m *StagedMetadatas) Reuse() { 392 if m == nil { 393 return 394 } 395 for i := range m.Metadatas { 396 m.Metadatas[i].reuse() 397 } 398 m.Metadatas = m.Metadatas[:0] 399 } 400 401 func (m *StagedMetadata) reuse() { 402 if m == nil { 403 return 404 } 405 m.Tombstoned = false 406 m.CutoverNanos = 0 407 m.Metadata.reuse() 408 } 409 410 func (m *Metadata) reuse() { 411 if m == nil { 412 return 413 } 414 for i := range m.Pipelines { 415 m.Pipelines[i].reuse() 416 } 417 m.Pipelines = m.Pipelines[:0] 418 } 419 420 func (m *PipelineMetadata) reuse() { 421 if m == nil { 422 return 423 } 424 m.AggregationId = aggregationpb.AggregationID{} 425 for i := range m.StoragePolicies { 426 m.StoragePolicies[i] = policypb.StoragePolicy{} 427 } 428 m.StoragePolicies = m.StoragePolicies[:0] 429 m.Pipeline.Reuse() 430 m.DropPolicy = 0 431 m.ResendEnabled = false 432 }