github.com/m3db/m3@v1.5.0/src/metrics/generated/proto/pipelinepb/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 pipelinepb 22 23 import ( 24 "fmt" 25 "io" 26 27 "github.com/m3db/m3/src/metrics/generated/proto/aggregationpb" 28 ) 29 30 // Unmarshal is a manual copy of the generated Unmarshal that allows reusing slices. 31 func (m *AppliedPipeline) Unmarshal(dAtA []byte) error { 32 l := len(dAtA) 33 iNdEx := 0 34 for iNdEx < l { 35 preIndex := iNdEx 36 var wire uint64 37 for shift := uint(0); ; shift += 7 { 38 if shift >= 64 { 39 return ErrIntOverflowPipeline 40 } 41 if iNdEx >= l { 42 return io.ErrUnexpectedEOF 43 } 44 b := dAtA[iNdEx] 45 iNdEx++ 46 wire |= (uint64(b) & 0x7F) << shift 47 if b < 0x80 { 48 break 49 } 50 } 51 fieldNum := int32(wire >> 3) 52 wireType := int(wire & 0x7) 53 if wireType == 4 { 54 return fmt.Errorf("proto: AppliedPipeline: wiretype end group for non-group") 55 } 56 if fieldNum <= 0 { 57 return fmt.Errorf("proto: AppliedPipeline: illegal tag %d (wire type %d)", fieldNum, wire) 58 } 59 switch fieldNum { 60 case 1: 61 if wireType != 2 { 62 return fmt.Errorf("proto: wrong wireType = %d for field Ops", wireType) 63 } 64 var msglen int 65 for shift := uint(0); ; shift += 7 { 66 if shift >= 64 { 67 return ErrIntOverflowPipeline 68 } 69 if iNdEx >= l { 70 return io.ErrUnexpectedEOF 71 } 72 b := dAtA[iNdEx] 73 iNdEx++ 74 msglen |= (int(b) & 0x7F) << shift 75 if b < 0x80 { 76 break 77 } 78 } 79 if msglen < 0 { 80 return ErrInvalidLengthPipeline 81 } 82 postIndex := iNdEx + msglen 83 if postIndex > l { 84 return io.ErrUnexpectedEOF 85 } 86 if cap(m.Ops) > len(m.Ops) { 87 m.Ops = m.Ops[0 : len(m.Ops)+1] 88 } else { 89 m.Ops = append(m.Ops, AppliedPipelineOp{}) 90 } 91 if err := m.Ops[len(m.Ops)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 92 return err 93 } 94 iNdEx = postIndex 95 default: 96 iNdEx = preIndex 97 skippy, err := skipPipeline(dAtA[iNdEx:]) 98 if err != nil { 99 return err 100 } 101 if skippy < 0 { 102 return ErrInvalidLengthPipeline 103 } 104 if (iNdEx + skippy) > l { 105 return io.ErrUnexpectedEOF 106 } 107 iNdEx += skippy 108 } 109 } 110 111 if iNdEx > l { 112 return io.ErrUnexpectedEOF 113 } 114 return nil 115 } 116 117 func (m *AppliedPipeline) Reuse() { 118 if m == nil { 119 return 120 } 121 for i := range m.Ops { 122 m.Ops[i].reuse() 123 } 124 m.Ops = m.Ops[:0] 125 } 126 127 func (m *AppliedPipelineOp) reuse() { 128 m.Type = 0 129 m.Transformation = TransformationOp{} 130 m.Rollup.reuse() 131 } 132 133 func (m *AppliedRollupOp) reuse() { 134 m.Id = m.Id[:0] 135 m.AggregationId = aggregationpb.AggregationID{} 136 }