Debian Codegraph @

pdata/internal/generated_proto_summarydatapoint.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 "encoding/binary"
11 "fmt"
12 "math"
13 "sync"
14
15 "go.opentelemetry.io/collector/pdata/internal/json"
16 "go.opentelemetry.io/collector/pdata/internal/proto"
17 )
18
19 // SummaryDataPoint is a single data point in a timeseries that describes the time-varying values of a Summary of double values.
20 type SummaryDataPoint struct {
21 Attributes []KeyValue
22 StartTimeUnixNano uint64
23 TimeUnixNano uint64
24 Count uint64
25 Sum float64
26 QuantileValues []*SummaryDataPointValueAtQuantile
27 Flags uint32
28 }
29
30 var (
31 protoPoolSummaryDataPoint = sync.Pool{
32 New: func() any {
33 return &SummaryDataPoint{}
34 },
35 }
36 )
37
38 func NewSummaryDataPoint() *SummaryDataPoint {
39 if !UseProtoPooling.IsEnabled() {
40 return &SummaryDataPoint{}
41 }
42 return protoPoolSummaryDataPoint.Get().(*SummaryDataPoint)
43 }
44
45 func DeleteSummaryDataPoint(orig *SummaryDataPoint, nullable bool) {
46 if orig == nil {
47 return
48 }
49
50 if !UseProtoPooling.IsEnabled() {
51 orig.Reset()
52 return
53 }
54
55 for i := range orig.Attributes {
56 DeleteKeyValue(&orig.Attributes[i], false)
57 }
58 for i := range orig.QuantileValues {
59 DeleteSummaryDataPointValueAtQuantile(orig.QuantileValues[i], true)
60 }
61
62 orig.Reset()
63 if nullable {
64 protoPoolSummaryDataPoint.Put(orig)
65 }
66 }
67
68 func CopySummaryDataPoint(dest, src *SummaryDataPoint) *SummaryDataPoint {
69 // If copying to same object, just return.
70 if src == dest {
71 return dest
72 }
73
74 if src == nil {
75 return nil
76 }
77
78 if dest == nil {
79 dest = NewSummaryDataPoint()
80 }
81 dest.Attributes = CopyKeyValueSlice(dest.Attributes, src.Attributes)
82
83 dest.StartTimeUnixNano = src.StartTimeUnixNano
84
85 dest.TimeUnixNano = src.TimeUnixNano
86
87 dest.Count = src.Count
88
89 dest.Sum = src.Sum
90
91 dest.QuantileValues = CopySummaryDataPointValueAtQuantilePtrSlice(dest.QuantileValues, src.QuantileValues)
92
93 dest.Flags = src.Flags
94
95 return dest
96 }
97
98 func CopySummaryDataPointSlice(dest, src []SummaryDataPoint) []SummaryDataPoint {
99 var newDest []SummaryDataPoint
100 if cap(dest) < len(src) {
101 newDest = make([]SummaryDataPoint, len(src))
102 } else {
103 newDest = dest[:len(src)]
104 // Cleanup the rest of the elements so GC can free the memory.
105 // This can happen when len(src) < len(dest) < cap(dest).
106 for i := len(src); i < len(dest); i++ {
107 DeleteSummaryDataPoint(&dest[i], false)
108 }
109 }
110 for i := range src {
111 CopySummaryDataPoint(&newDest[i], &src[i])
112 }
113 return newDest
114 }
115
116 func CopySummaryDataPointPtrSlice(dest, src []*SummaryDataPoint) []*SummaryDataPoint {
117 var newDest []*SummaryDataPoint
118 if cap(dest) < len(src) {
119 newDest = make([]*SummaryDataPoint, len(src))
120 // Copy old pointers to re-use.
121 copy(newDest, dest)
122 // Add new pointers for missing elements from len(dest) to len(srt).
123 for i := len(dest); i < len(src); i++ {
124 newDest[i] = NewSummaryDataPoint()
125 }
126 } else {
127 newDest = dest[:len(src)]
128 // Cleanup the rest of the elements so GC can free the memory.
129 // This can happen when len(src) < len(dest) < cap(dest).
130 for i := len(src); i < len(dest); i++ {
131 DeleteSummaryDataPoint(dest[i], true)
132 dest[i] = nil
133 }
134 // Add new pointers for missing elements.
135 // This can happen when len(dest) < len(src) < cap(dest).
136 for i := len(dest); i < len(src); i++ {
137 newDest[i] = NewSummaryDataPoint()
138 }
139 }
140 for i := range src {
141 CopySummaryDataPoint(newDest[i], src[i])
142 }
143 return newDest
144 }
145
146 func (orig *SummaryDataPoint) Reset() {
147 *orig = SummaryDataPoint{}
148 }
149
150 // MarshalJSON marshals all properties from the current struct to the destination stream.
151 func (orig *SummaryDataPoint) MarshalJSON(dest *json.Stream) {
152 dest.WriteObjectStart()
153 if len(orig.Attributes) > 0 {
154 dest.WriteObjectField("attributes")
155 dest.WriteArrayStart()
156 orig.Attributes[0].MarshalJSON(dest)
157 for i := 1; i < len(orig.Attributes); i++ {
158 dest.WriteMore()
159 orig.Attributes[i].MarshalJSON(dest)
160 }
161 dest.WriteArrayEnd()
162 }
163 if orig.StartTimeUnixNano != uint64(0) {
164 dest.WriteObjectField("startTimeUnixNano")
165 dest.WriteUint64(orig.StartTimeUnixNano)
166 }
167 if orig.TimeUnixNano != uint64(0) {
168 dest.WriteObjectField("timeUnixNano")
169 dest.WriteUint64(orig.TimeUnixNano)
170 }
171 if orig.Count != uint64(0) {
172 dest.WriteObjectField("count")
173 dest.WriteUint64(orig.Count)
174 }
175 if orig.Sum != float64(0) {
176 dest.WriteObjectField("sum")
177 dest.WriteFloat64(orig.Sum)
178 }
179 if len(orig.QuantileValues) > 0 {
180 dest.WriteObjectField("quantileValues")
181 dest.WriteArrayStart()
182 orig.QuantileValues[0].MarshalJSON(dest)
183 for i := 1; i < len(orig.QuantileValues); i++ {
184 dest.WriteMore()
185 orig.QuantileValues[i].MarshalJSON(dest)
186 }
187 dest.WriteArrayEnd()
188 }
189 if orig.Flags != uint32(0) {
190 dest.WriteObjectField("flags")
191 dest.WriteUint32(orig.Flags)
192 }
193 dest.WriteObjectEnd()
194 }
195
196 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
197 func (orig *SummaryDataPoint) UnmarshalJSON(iter *json.Iterator) {
198 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
199 switch f {
200 case "attributes":
201 for iter.ReadArray() {
202 orig.Attributes = append(orig.Attributes, KeyValue{})
203 orig.Attributes[len(orig.Attributes)-1].UnmarshalJSON(iter)
204 }
205
206 case "startTimeUnixNano", "start_time_unix_nano":
207 orig.StartTimeUnixNano = iter.ReadUint64()
208 case "timeUnixNano", "time_unix_nano":
209 orig.TimeUnixNano = iter.ReadUint64()
210 case "count":
211 orig.Count = iter.ReadUint64()
212 case "sum":
213 orig.Sum = iter.ReadFloat64()
214 case "quantileValues", "quantile_values":
215 for iter.ReadArray() {
216 orig.QuantileValues = append(orig.QuantileValues, NewSummaryDataPointValueAtQuantile())
217 orig.QuantileValues[len(orig.QuantileValues)-1].UnmarshalJSON(iter)
218 }
219
220 case "flags":
221 orig.Flags = iter.ReadUint32()
222 default:
223 iter.Skip()
224 }
225 }
226 }
227
228 func (orig *SummaryDataPoint) SizeProto() int {
229 var n int
230 var l int
231 _ = l
232 for i := range orig.Attributes {
233 l = orig.Attributes[i].SizeProto()
234 n += 1 + proto.Sov(uint64(l)) + l
235 }
236 if orig.StartTimeUnixNano != 0 {
237 n += 9
238 }
239 if orig.TimeUnixNano != 0 {
240 n += 9
241 }
242 if orig.Count != 0 {
243 n += 9
244 }
245 if orig.Sum != 0 {
246 n += 9
247 }
248 for i := range orig.QuantileValues {
249 l = orig.QuantileValues[i].SizeProto()
250 n += 1 + proto.Sov(uint64(l)) + l
251 }
252 if orig.Flags != 0 {
253 n += 1 + proto.Sov(uint64(orig.Flags))
254 }
255 return n
256 }
257
258 func (orig *SummaryDataPoint) MarshalProto(buf []byte) int {
259 pos := len(buf)
260 var l int
261 _ = l
262 for i := len(orig.Attributes) - 1; i >= 0; i-- {
263 l = orig.Attributes[i].MarshalProto(buf[:pos])
264 pos -= l
265 pos = proto.EncodeVarint(buf, pos, uint64(l))
266 pos--
267 buf[pos] = 0x3a
268 }
269 if orig.StartTimeUnixNano != 0 {
270 pos -= 8
271 binary.LittleEndian.PutUint64(buf[pos:], uint64(orig.StartTimeUnixNano))
272 pos--
273 buf[pos] = 0x11
274 }
275 if orig.TimeUnixNano != 0 {
276 pos -= 8
277 binary.LittleEndian.PutUint64(buf[pos:], uint64(orig.TimeUnixNano))
278 pos--
279 buf[pos] = 0x19
280 }
281 if orig.Count != 0 {
282 pos -= 8
283 binary.LittleEndian.PutUint64(buf[pos:], uint64(orig.Count))
284 pos--
285 buf[pos] = 0x21
286 }
287 if orig.Sum != 0 {
288 pos -= 8
289 binary.LittleEndian.PutUint64(buf[pos:], math.Float64bits(orig.Sum))
290 pos--
291 buf[pos] = 0x29
292 }
293 for i := len(orig.QuantileValues) - 1; i >= 0; i-- {
294 l = orig.QuantileValues[i].MarshalProto(buf[:pos])
295 pos -= l
296 pos = proto.EncodeVarint(buf, pos, uint64(l))
297 pos--
298 buf[pos] = 0x32
299 }
300 if orig.Flags != 0 {
301 pos = proto.EncodeVarint(buf, pos, uint64(orig.Flags))
302 pos--
303 buf[pos] = 0x40
304 }
305 return len(buf) - pos
306 }
307
308 func (orig *SummaryDataPoint) UnmarshalProto(buf []byte) error {
309 var err error
310 var fieldNum int32
311 var wireType proto.WireType
312
313 l := len(buf)
314 pos := 0
315 for pos < l {
316 // If in a group parsing, move to the next tag.
317 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
318 if err != nil {
319 return err
320 }
321 switch fieldNum {
322
323 case 7:
324 if wireType != proto.WireTypeLen {
325 return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType)
326 }
327 var length int
328 length, pos, err = proto.ConsumeLen(buf, pos)
329 if err != nil {
330 return err
331 }
332 startPos := pos - length
333 orig.Attributes = append(orig.Attributes, KeyValue{})
334 err = orig.Attributes[len(orig.Attributes)-1].UnmarshalProto(buf[startPos:pos])
335 if err != nil {
336 return err
337 }
338
339 case 2:
340 if wireType != proto.WireTypeI64 {
341 return fmt.Errorf("proto: wrong wireType = %d for field StartTimeUnixNano", wireType)
342 }
343 var num uint64
344 num, pos, err = proto.ConsumeI64(buf, pos)
345 if err != nil {
346 return err
347 }
348
349 orig.StartTimeUnixNano = uint64(num)
350
351 case 3:
352 if wireType != proto.WireTypeI64 {
353 return fmt.Errorf("proto: wrong wireType = %d for field TimeUnixNano", wireType)
354 }
355 var num uint64
356 num, pos, err = proto.ConsumeI64(buf, pos)
357 if err != nil {
358 return err
359 }
360
361 orig.TimeUnixNano = uint64(num)
362
363 case 4:
364 if wireType != proto.WireTypeI64 {
365 return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType)
366 }
367 var num uint64
368 num, pos, err = proto.ConsumeI64(buf, pos)
369 if err != nil {
370 return err
371 }
372
373 orig.Count = uint64(num)
374
375 case 5:
376 if wireType != proto.WireTypeI64 {
377 return fmt.Errorf("proto: wrong wireType = %d for field Sum", wireType)
378 }
379 var num uint64
380 num, pos, err = proto.ConsumeI64(buf, pos)
381 if err != nil {
382 return err
383 }
384
385 orig.Sum = math.Float64frombits(num)
386
387 case 6:
388 if wireType != proto.WireTypeLen {
389 return fmt.Errorf("proto: wrong wireType = %d for field QuantileValues", wireType)
390 }
391 var length int
392 length, pos, err = proto.ConsumeLen(buf, pos)
393 if err != nil {
394 return err
395 }
396 startPos := pos - length
397 orig.QuantileValues = append(orig.QuantileValues, NewSummaryDataPointValueAtQuantile())
398 err = orig.QuantileValues[len(orig.QuantileValues)-1].UnmarshalProto(buf[startPos:pos])
399 if err != nil {
400 return err
401 }
402
403 case 8:
404 if wireType != proto.WireTypeVarint {
405 return fmt.Errorf("proto: wrong wireType = %d for field Flags", wireType)
406 }
407 var num uint64
408 num, pos, err = proto.ConsumeVarint(buf, pos)
409 if err != nil {
410 return err
411 }
412
413 orig.Flags = uint32(num)
414 default:
415 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
416 if err != nil {
417 return err
418 }
419 }
420 }
421 return nil
422 }
423
424 func GenTestSummaryDataPoint() *SummaryDataPoint {
425 orig := NewSummaryDataPoint()
426 orig.Attributes = []KeyValue{{}, *GenTestKeyValue()}
427 orig.StartTimeUnixNano = uint64(13)
428 orig.TimeUnixNano = uint64(13)
429 orig.Count = uint64(13)
430 orig.Sum = float64(3.1415926)
431 orig.QuantileValues = []*SummaryDataPointValueAtQuantile{{}, GenTestSummaryDataPointValueAtQuantile()}
432 orig.Flags = uint32(13)
433 return orig
434 }
435
436 func GenTestSummaryDataPointPtrSlice() []*SummaryDataPoint {
437 orig := make([]*SummaryDataPoint, 5)
438 orig[0] = NewSummaryDataPoint()
439 orig[1] = GenTestSummaryDataPoint()
440 orig[2] = NewSummaryDataPoint()
441 orig[3] = GenTestSummaryDataPoint()
442 orig[4] = NewSummaryDataPoint()
443 return orig
444 }
445
446 func GenTestSummaryDataPointSlice() []SummaryDataPoint {
447 orig := make([]SummaryDataPoint, 5)
448 orig[1] = *GenTestSummaryDataPoint()
449 orig[3] = *GenTestSummaryDataPoint()
450 return orig
451 }