Debian Codegraph @

pdata/internal/generated_proto_exponentialhistogram.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT.
5 // To regenerate this file run "make genpdata".
6
7 package internal
8
9 import (
10 "fmt"
11 "sync"
12
13 "go.opentelemetry.io/collector/pdata/internal/json"
14 "go.opentelemetry.io/collector/pdata/internal/proto"
15 )
16
17 // ExponentialHistogram represents the type of a metric that is calculated by aggregating
18 // as a ExponentialHistogram of all reported double measurements over a time interval.
19 type ExponentialHistogram struct {
20 DataPoints []*ExponentialHistogramDataPoint
21 AggregationTemporality AggregationTemporality
22 }
23
24 var (
25 protoPoolExponentialHistogram = sync.Pool{
26 New: func() any {
27 return &ExponentialHistogram{}
28 },
29 }
30 )
31
32 func NewExponentialHistogram() *ExponentialHistogram {
33 if !UseProtoPooling.IsEnabled() {
34 return &ExponentialHistogram{}
35 }
36 return protoPoolExponentialHistogram.Get().(*ExponentialHistogram)
37 }
38
39 func DeleteExponentialHistogram(orig *ExponentialHistogram, nullable bool) {
40 if orig == nil {
41 return
42 }
43
44 if !UseProtoPooling.IsEnabled() {
45 orig.Reset()
46 return
47 }
48
49 for i := range orig.DataPoints {
50 DeleteExponentialHistogramDataPoint(orig.DataPoints[i], true)
51 }
52
53 orig.Reset()
54 if nullable {
55 protoPoolExponentialHistogram.Put(orig)
56 }
57 }
58
59 func CopyExponentialHistogram(dest, src *ExponentialHistogram) *ExponentialHistogram {
60 // If copying to same object, just return.
61 if src == dest {
62 return dest
63 }
64
65 if src == nil {
66 return nil
67 }
68
69 if dest == nil {
70 dest = NewExponentialHistogram()
71 }
72 dest.DataPoints = CopyExponentialHistogramDataPointPtrSlice(dest.DataPoints, src.DataPoints)
73
74 dest.AggregationTemporality = src.AggregationTemporality
75
76 return dest
77 }
78
79 func CopyExponentialHistogramSlice(dest, src []ExponentialHistogram) []ExponentialHistogram {
80 var newDest []ExponentialHistogram
81 if cap(dest) < len(src) {
82 newDest = make([]ExponentialHistogram, len(src))
83 } else {
84 newDest = dest[:len(src)]
85 // Cleanup the rest of the elements so GC can free the memory.
86 // This can happen when len(src) < len(dest) < cap(dest).
87 for i := len(src); i < len(dest); i++ {
88 DeleteExponentialHistogram(&dest[i], false)
89 }
90 }
91 for i := range src {
92 CopyExponentialHistogram(&newDest[i], &src[i])
93 }
94 return newDest
95 }
96
97 func CopyExponentialHistogramPtrSlice(dest, src []*ExponentialHistogram) []*ExponentialHistogram {
98 var newDest []*ExponentialHistogram
99 if cap(dest) < len(src) {
100 newDest = make([]*ExponentialHistogram, len(src))
101 // Copy old pointers to re-use.
102 copy(newDest, dest)
103 // Add new pointers for missing elements from len(dest) to len(srt).
104 for i := len(dest); i < len(src); i++ {
105 newDest[i] = NewExponentialHistogram()
106 }
107 } else {
108 newDest = dest[:len(src)]
109 // Cleanup the rest of the elements so GC can free the memory.
110 // This can happen when len(src) < len(dest) < cap(dest).
111 for i := len(src); i < len(dest); i++ {
112 DeleteExponentialHistogram(dest[i], true)
113 dest[i] = nil
114 }
115 // Add new pointers for missing elements.
116 // This can happen when len(dest) < len(src) < cap(dest).
117 for i := len(dest); i < len(src); i++ {
118 newDest[i] = NewExponentialHistogram()
119 }
120 }
121 for i := range src {
122 CopyExponentialHistogram(newDest[i], src[i])
123 }
124 return newDest
125 }
126
127 func (orig *ExponentialHistogram) Reset() {
128 *orig = ExponentialHistogram{}
129 }
130
131 // MarshalJSON marshals all properties from the current struct to the destination stream.
132 func (orig *ExponentialHistogram) MarshalJSON(dest *json.Stream) {
133 dest.WriteObjectStart()
134 if len(orig.DataPoints) > 0 {
135 dest.WriteObjectField("dataPoints")
136 dest.WriteArrayStart()
137 orig.DataPoints[0].MarshalJSON(dest)
138 for i := 1; i < len(orig.DataPoints); i++ {
139 dest.WriteMore()
140 orig.DataPoints[i].MarshalJSON(dest)
141 }
142 dest.WriteArrayEnd()
143 }
144
145 if int32(orig.AggregationTemporality) != 0 {
146 dest.WriteObjectField("aggregationTemporality")
147 dest.WriteInt32(int32(orig.AggregationTemporality))
148 }
149 dest.WriteObjectEnd()
150 }
151
152 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
153 func (orig *ExponentialHistogram) UnmarshalJSON(iter *json.Iterator) {
154 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
155 switch f {
156 case "dataPoints", "data_points":
157 for iter.ReadArray() {
158 orig.DataPoints = append(orig.DataPoints, NewExponentialHistogramDataPoint())
159 orig.DataPoints[len(orig.DataPoints)-1].UnmarshalJSON(iter)
160 }
161
162 case "aggregationTemporality", "aggregation_temporality":
163 orig.AggregationTemporality = AggregationTemporality(iter.ReadEnumValue(AggregationTemporality_value))
164 default:
165 iter.Skip()
166 }
167 }
168 }
169
170 func (orig *ExponentialHistogram) SizeProto() int {
171 var n int
172 var l int
173 _ = l
174 for i := range orig.DataPoints {
175 l = orig.DataPoints[i].SizeProto()
176 n += 1 + proto.Sov(uint64(l)) + l
177 }
178 if orig.AggregationTemporality != 0 {
179 n += 1 + proto.Sov(uint64(orig.AggregationTemporality))
180 }
181 return n
182 }
183
184 func (orig *ExponentialHistogram) MarshalProto(buf []byte) int {
185 pos := len(buf)
186 var l int
187 _ = l
188 for i := len(orig.DataPoints) - 1; i >= 0; i-- {
189 l = orig.DataPoints[i].MarshalProto(buf[:pos])
190 pos -= l
191 pos = proto.EncodeVarint(buf, pos, uint64(l))
192 pos--
193 buf[pos] = 0xa
194 }
195 if orig.AggregationTemporality != 0 {
196 pos = proto.EncodeVarint(buf, pos, uint64(orig.AggregationTemporality))
197 pos--
198 buf[pos] = 0x10
199 }
200 return len(buf) - pos
201 }
202
203 func (orig *ExponentialHistogram) UnmarshalProto(buf []byte) error {
204 var err error
205 var fieldNum int32
206 var wireType proto.WireType
207
208 l := len(buf)
209 pos := 0
210 for pos < l {
211 // If in a group parsing, move to the next tag.
212 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
213 if err != nil {
214 return err
215 }
216 switch fieldNum {
217
218 case 1:
219 if wireType != proto.WireTypeLen {
220 return fmt.Errorf("proto: wrong wireType = %d for field DataPoints", wireType)
221 }
222 var length int
223 length, pos, err = proto.ConsumeLen(buf, pos)
224 if err != nil {
225 return err
226 }
227 startPos := pos - length
228 orig.DataPoints = append(orig.DataPoints, NewExponentialHistogramDataPoint())
229 err = orig.DataPoints[len(orig.DataPoints)-1].UnmarshalProto(buf[startPos:pos])
230 if err != nil {
231 return err
232 }
233
234 case 2:
235 if wireType != proto.WireTypeVarint {
236 return fmt.Errorf("proto: wrong wireType = %d for field AggregationTemporality", wireType)
237 }
238 var num uint64
239 num, pos, err = proto.ConsumeVarint(buf, pos)
240 if err != nil {
241 return err
242 }
243
244 orig.AggregationTemporality = AggregationTemporality(num)
245 default:
246 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
247 if err != nil {
248 return err
249 }
250 }
251 }
252 return nil
253 }
254
255 func GenTestExponentialHistogram() *ExponentialHistogram {
256 orig := NewExponentialHistogram()
257 orig.DataPoints = []*ExponentialHistogramDataPoint{{}, GenTestExponentialHistogramDataPoint()}
258 orig.AggregationTemporality = AggregationTemporality(13)
259 return orig
260 }
261
262 func GenTestExponentialHistogramPtrSlice() []*ExponentialHistogram {
263 orig := make([]*ExponentialHistogram, 5)
264 orig[0] = NewExponentialHistogram()
265 orig[1] = GenTestExponentialHistogram()
266 orig[2] = NewExponentialHistogram()
267 orig[3] = GenTestExponentialHistogram()
268 orig[4] = NewExponentialHistogram()
269 return orig
270 }
271
272 func GenTestExponentialHistogramSlice() []ExponentialHistogram {
273 orig := make([]ExponentialHistogram, 5)
274 orig[1] = *GenTestExponentialHistogram()
275 orig[3] = *GenTestExponentialHistogram()
276 return orig
277 }