Debian Codegraph @

pdata/internal/generated_proto_profile.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 "sync"
13
14 "go.opentelemetry.io/collector/pdata/internal/json"
15 "go.opentelemetry.io/collector/pdata/internal/proto"
16 )
17
18 // Profile are an implementation of the pprofextended data model.
19
20 type Profile struct {
21 SampleType ValueType
22 Samples []*Sample
23 TimeUnixNano uint64
24 DurationNano uint64
25 PeriodType ValueType
26 Period int64
27 ProfileId ProfileID
28 DroppedAttributesCount uint32
29 OriginalPayloadFormat string
30 OriginalPayload []byte
31 AttributeIndices []int32
32 }
33
34 var (
35 protoPoolProfile = sync.Pool{
36 New: func() any {
37 return &Profile{}
38 },
39 }
40 )
41
42 func NewProfile() *Profile {
43 if !UseProtoPooling.IsEnabled() {
44 return &Profile{}
45 }
46 return protoPoolProfile.Get().(*Profile)
47 }
48
49 func DeleteProfile(orig *Profile, nullable bool) {
50 if orig == nil {
51 return
52 }
53
54 if !UseProtoPooling.IsEnabled() {
55 orig.Reset()
56 return
57 }
58
59 DeleteValueType(&orig.SampleType, false)
60 for i := range orig.Samples {
61 DeleteSample(orig.Samples[i], true)
62 }
63 DeleteValueType(&orig.PeriodType, false)
64 DeleteProfileID(&orig.ProfileId, false)
65
66 orig.Reset()
67 if nullable {
68 protoPoolProfile.Put(orig)
69 }
70 }
71
72 func CopyProfile(dest, src *Profile) *Profile {
73 // If copying to same object, just return.
74 if src == dest {
75 return dest
76 }
77
78 if src == nil {
79 return nil
80 }
81
82 if dest == nil {
83 dest = NewProfile()
84 }
85 CopyValueType(&dest.SampleType, &src.SampleType)
86
87 dest.Samples = CopySamplePtrSlice(dest.Samples, src.Samples)
88
89 dest.TimeUnixNano = src.TimeUnixNano
90
91 dest.DurationNano = src.DurationNano
92
93 CopyValueType(&dest.PeriodType, &src.PeriodType)
94
95 dest.Period = src.Period
96
97 CopyProfileID(&dest.ProfileId, &src.ProfileId)
98
99 dest.DroppedAttributesCount = src.DroppedAttributesCount
100
101 dest.OriginalPayloadFormat = src.OriginalPayloadFormat
102
103 dest.OriginalPayload = src.OriginalPayload
104
105 dest.AttributeIndices = append(dest.AttributeIndices[:0], src.AttributeIndices...)
106
107 return dest
108 }
109
110 func CopyProfileSlice(dest, src []Profile) []Profile {
111 var newDest []Profile
112 if cap(dest) < len(src) {
113 newDest = make([]Profile, len(src))
114 } else {
115 newDest = dest[:len(src)]
116 // Cleanup the rest of the elements so GC can free the memory.
117 // This can happen when len(src) < len(dest) < cap(dest).
118 for i := len(src); i < len(dest); i++ {
119 DeleteProfile(&dest[i], false)
120 }
121 }
122 for i := range src {
123 CopyProfile(&newDest[i], &src[i])
124 }
125 return newDest
126 }
127
128 func CopyProfilePtrSlice(dest, src []*Profile) []*Profile {
129 var newDest []*Profile
130 if cap(dest) < len(src) {
131 newDest = make([]*Profile, len(src))
132 // Copy old pointers to re-use.
133 copy(newDest, dest)
134 // Add new pointers for missing elements from len(dest) to len(srt).
135 for i := len(dest); i < len(src); i++ {
136 newDest[i] = NewProfile()
137 }
138 } else {
139 newDest = dest[:len(src)]
140 // Cleanup the rest of the elements so GC can free the memory.
141 // This can happen when len(src) < len(dest) < cap(dest).
142 for i := len(src); i < len(dest); i++ {
143 DeleteProfile(dest[i], true)
144 dest[i] = nil
145 }
146 // Add new pointers for missing elements.
147 // This can happen when len(dest) < len(src) < cap(dest).
148 for i := len(dest); i < len(src); i++ {
149 newDest[i] = NewProfile()
150 }
151 }
152 for i := range src {
153 CopyProfile(newDest[i], src[i])
154 }
155 return newDest
156 }
157
158 func (orig *Profile) Reset() {
159 *orig = Profile{}
160 }
161
162 // MarshalJSON marshals all properties from the current struct to the destination stream.
163 func (orig *Profile) MarshalJSON(dest *json.Stream) {
164 dest.WriteObjectStart()
165 dest.WriteObjectField("sampleType")
166 orig.SampleType.MarshalJSON(dest)
167 if len(orig.Samples) > 0 {
168 dest.WriteObjectField("samples")
169 dest.WriteArrayStart()
170 orig.Samples[0].MarshalJSON(dest)
171 for i := 1; i < len(orig.Samples); i++ {
172 dest.WriteMore()
173 orig.Samples[i].MarshalJSON(dest)
174 }
175 dest.WriteArrayEnd()
176 }
177 if orig.TimeUnixNano != uint64(0) {
178 dest.WriteObjectField("timeUnixNano")
179 dest.WriteUint64(orig.TimeUnixNano)
180 }
181 if orig.DurationNano != uint64(0) {
182 dest.WriteObjectField("durationNano")
183 dest.WriteUint64(orig.DurationNano)
184 }
185 dest.WriteObjectField("periodType")
186 orig.PeriodType.MarshalJSON(dest)
187 if orig.Period != int64(0) {
188 dest.WriteObjectField("period")
189 dest.WriteInt64(orig.Period)
190 }
191 if !orig.ProfileId.IsEmpty() {
192 dest.WriteObjectField("profileId")
193 orig.ProfileId.MarshalJSON(dest)
194 }
195 if orig.DroppedAttributesCount != uint32(0) {
196 dest.WriteObjectField("droppedAttributesCount")
197 dest.WriteUint32(orig.DroppedAttributesCount)
198 }
199 if orig.OriginalPayloadFormat != "" {
200 dest.WriteObjectField("originalPayloadFormat")
201 dest.WriteString(orig.OriginalPayloadFormat)
202 }
203
204 if len(orig.OriginalPayload) > 0 {
205 dest.WriteObjectField("originalPayload")
206 dest.WriteBytes(orig.OriginalPayload)
207 }
208 if len(orig.AttributeIndices) > 0 {
209 dest.WriteObjectField("attributeIndices")
210 dest.WriteArrayStart()
211 dest.WriteInt32(orig.AttributeIndices[0])
212 for i := 1; i < len(orig.AttributeIndices); i++ {
213 dest.WriteMore()
214 dest.WriteInt32(orig.AttributeIndices[i])
215 }
216 dest.WriteArrayEnd()
217 }
218 dest.WriteObjectEnd()
219 }
220
221 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
222 func (orig *Profile) UnmarshalJSON(iter *json.Iterator) {
223 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
224 switch f {
225 case "sampleType", "sample_type":
226
227 orig.SampleType.UnmarshalJSON(iter)
228 case "samples":
229 for iter.ReadArray() {
230 orig.Samples = append(orig.Samples, NewSample())
231 orig.Samples[len(orig.Samples)-1].UnmarshalJSON(iter)
232 }
233
234 case "timeUnixNano", "time_unix_nano":
235 orig.TimeUnixNano = iter.ReadUint64()
236 case "durationNano", "duration_nano":
237 orig.DurationNano = iter.ReadUint64()
238 case "periodType", "period_type":
239
240 orig.PeriodType.UnmarshalJSON(iter)
241 case "period":
242 orig.Period = iter.ReadInt64()
243 case "profileId", "profile_id":
244
245 orig.ProfileId.UnmarshalJSON(iter)
246 case "droppedAttributesCount", "dropped_attributes_count":
247 orig.DroppedAttributesCount = iter.ReadUint32()
248 case "originalPayloadFormat", "original_payload_format":
249 orig.OriginalPayloadFormat = iter.ReadString()
250 case "originalPayload", "original_payload":
251 orig.OriginalPayload = iter.ReadBytes()
252 case "attributeIndices", "attribute_indices":
253 for iter.ReadArray() {
254 orig.AttributeIndices = append(orig.AttributeIndices, iter.ReadInt32())
255 }
256
257 default:
258 iter.Skip()
259 }
260 }
261 }
262
263 func (orig *Profile) SizeProto() int {
264 var n int
265 var l int
266 _ = l
267 l = orig.SampleType.SizeProto()
268 n += 1 + proto.Sov(uint64(l)) + l
269 for i := range orig.Samples {
270 l = orig.Samples[i].SizeProto()
271 n += 1 + proto.Sov(uint64(l)) + l
272 }
273 if orig.TimeUnixNano != 0 {
274 n += 9
275 }
276 if orig.DurationNano != 0 {
277 n += 1 + proto.Sov(uint64(orig.DurationNano))
278 }
279 l = orig.PeriodType.SizeProto()
280 n += 1 + proto.Sov(uint64(l)) + l
281 if orig.Period != 0 {
282 n += 1 + proto.Sov(uint64(orig.Period))
283 }
284 l = orig.ProfileId.SizeProto()
285 n += 1 + proto.Sov(uint64(l)) + l
286 if orig.DroppedAttributesCount != 0 {
287 n += 1 + proto.Sov(uint64(orig.DroppedAttributesCount))
288 }
289 l = len(orig.OriginalPayloadFormat)
290 if l > 0 {
291 n += 1 + proto.Sov(uint64(l)) + l
292 }
293 l = len(orig.OriginalPayload)
294 if l > 0 {
295 n += 1 + proto.Sov(uint64(l)) + l
296 }
297 if len(orig.AttributeIndices) > 0 {
298 l = 0
299 for _, e := range orig.AttributeIndices {
300 l += proto.Sov(uint64(e))
301 }
302 n += 1 + proto.Sov(uint64(l)) + l
303 }
304 return n
305 }
306
307 func (orig *Profile) MarshalProto(buf []byte) int {
308 pos := len(buf)
309 var l int
310 _ = l
311 l = orig.SampleType.MarshalProto(buf[:pos])
312 pos -= l
313 pos = proto.EncodeVarint(buf, pos, uint64(l))
314 pos--
315 buf[pos] = 0xa
316
317 for i := len(orig.Samples) - 1; i >= 0; i-- {
318 l = orig.Samples[i].MarshalProto(buf[:pos])
319 pos -= l
320 pos = proto.EncodeVarint(buf, pos, uint64(l))
321 pos--
322 buf[pos] = 0x12
323 }
324 if orig.TimeUnixNano != 0 {
325 pos -= 8
326 binary.LittleEndian.PutUint64(buf[pos:], uint64(orig.TimeUnixNano))
327 pos--
328 buf[pos] = 0x19
329 }
330 if orig.DurationNano != 0 {
331 pos = proto.EncodeVarint(buf, pos, uint64(orig.DurationNano))
332 pos--
333 buf[pos] = 0x20
334 }
335 l = orig.PeriodType.MarshalProto(buf[:pos])
336 pos -= l
337 pos = proto.EncodeVarint(buf, pos, uint64(l))
338 pos--
339 buf[pos] = 0x2a
340
341 if orig.Period != 0 {
342 pos = proto.EncodeVarint(buf, pos, uint64(orig.Period))
343 pos--
344 buf[pos] = 0x30
345 }
346 l = orig.ProfileId.MarshalProto(buf[:pos])
347 pos -= l
348 pos = proto.EncodeVarint(buf, pos, uint64(l))
349 pos--
350 buf[pos] = 0x3a
351
352 if orig.DroppedAttributesCount != 0 {
353 pos = proto.EncodeVarint(buf, pos, uint64(orig.DroppedAttributesCount))
354 pos--
355 buf[pos] = 0x40
356 }
357 l = len(orig.OriginalPayloadFormat)
358 if l > 0 {
359 pos -= l
360 copy(buf[pos:], orig.OriginalPayloadFormat)
361 pos = proto.EncodeVarint(buf, pos, uint64(l))
362 pos--
363 buf[pos] = 0x4a
364 }
365 l = len(orig.OriginalPayload)
366 if l > 0 {
367 pos -= l
368 copy(buf[pos:], orig.OriginalPayload)
369 pos = proto.EncodeVarint(buf, pos, uint64(l))
370 pos--
371 buf[pos] = 0x52
372 }
373 l = len(orig.AttributeIndices)
374 if l > 0 {
375 endPos := pos
376 for i := l - 1; i >= 0; i-- {
377 pos = proto.EncodeVarint(buf, pos, uint64(orig.AttributeIndices[i]))
378 }
379 pos = proto.EncodeVarint(buf, pos, uint64(endPos-pos))
380 pos--
381 buf[pos] = 0x5a
382 }
383 return len(buf) - pos
384 }
385
386 func (orig *Profile) UnmarshalProto(buf []byte) error {
387 var err error
388 var fieldNum int32
389 var wireType proto.WireType
390
391 l := len(buf)
392 pos := 0
393 for pos < l {
394 // If in a group parsing, move to the next tag.
395 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
396 if err != nil {
397 return err
398 }
399 switch fieldNum {
400
401 case 1:
402 if wireType != proto.WireTypeLen {
403 return fmt.Errorf("proto: wrong wireType = %d for field SampleType", wireType)
404 }
405 var length int
406 length, pos, err = proto.ConsumeLen(buf, pos)
407 if err != nil {
408 return err
409 }
410 startPos := pos - length
411
412 err = orig.SampleType.UnmarshalProto(buf[startPos:pos])
413 if err != nil {
414 return err
415 }
416
417 case 2:
418 if wireType != proto.WireTypeLen {
419 return fmt.Errorf("proto: wrong wireType = %d for field Samples", wireType)
420 }
421 var length int
422 length, pos, err = proto.ConsumeLen(buf, pos)
423 if err != nil {
424 return err
425 }
426 startPos := pos - length
427 orig.Samples = append(orig.Samples, NewSample())
428 err = orig.Samples[len(orig.Samples)-1].UnmarshalProto(buf[startPos:pos])
429 if err != nil {
430 return err
431 }
432
433 case 3:
434 if wireType != proto.WireTypeI64 {
435 return fmt.Errorf("proto: wrong wireType = %d for field TimeUnixNano", wireType)
436 }
437 var num uint64
438 num, pos, err = proto.ConsumeI64(buf, pos)
439 if err != nil {
440 return err
441 }
442
443 orig.TimeUnixNano = uint64(num)
444
445 case 4:
446 if wireType != proto.WireTypeVarint {
447 return fmt.Errorf("proto: wrong wireType = %d for field DurationNano", wireType)
448 }
449 var num uint64
450 num, pos, err = proto.ConsumeVarint(buf, pos)
451 if err != nil {
452 return err
453 }
454
455 orig.DurationNano = uint64(num)
456
457 case 5:
458 if wireType != proto.WireTypeLen {
459 return fmt.Errorf("proto: wrong wireType = %d for field PeriodType", wireType)
460 }
461 var length int
462 length, pos, err = proto.ConsumeLen(buf, pos)
463 if err != nil {
464 return err
465 }
466 startPos := pos - length
467
468 err = orig.PeriodType.UnmarshalProto(buf[startPos:pos])
469 if err != nil {
470 return err
471 }
472
473 case 6:
474 if wireType != proto.WireTypeVarint {
475 return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType)
476 }
477 var num uint64
478 num, pos, err = proto.ConsumeVarint(buf, pos)
479 if err != nil {
480 return err
481 }
482
483 orig.Period = int64(num)
484
485 case 7:
486 if wireType != proto.WireTypeLen {
487 return fmt.Errorf("proto: wrong wireType = %d for field ProfileId", wireType)
488 }
489 var length int
490 length, pos, err = proto.ConsumeLen(buf, pos)
491 if err != nil {
492 return err
493 }
494 startPos := pos - length
495
496 err = orig.ProfileId.UnmarshalProto(buf[startPos:pos])
497 if err != nil {
498 return err
499 }
500
501 case 8:
502 if wireType != proto.WireTypeVarint {
503 return fmt.Errorf("proto: wrong wireType = %d for field DroppedAttributesCount", wireType)
504 }
505 var num uint64
506 num, pos, err = proto.ConsumeVarint(buf, pos)
507 if err != nil {
508 return err
509 }
510
511 orig.DroppedAttributesCount = uint32(num)
512
513 case 9:
514 if wireType != proto.WireTypeLen {
515 return fmt.Errorf("proto: wrong wireType = %d for field OriginalPayloadFormat", wireType)
516 }
517 var length int
518 length, pos, err = proto.ConsumeLen(buf, pos)
519 if err != nil {
520 return err
521 }
522 startPos := pos - length
523 orig.OriginalPayloadFormat = string(buf[startPos:pos])
524
525 case 10:
526 if wireType != proto.WireTypeLen {
527 return fmt.Errorf("proto: wrong wireType = %d for field OriginalPayload", wireType)
528 }
529 var length int
530 length, pos, err = proto.ConsumeLen(buf, pos)
531 if err != nil {
532 return err
533 }
534 startPos := pos - length
535 if length != 0 {
536 orig.OriginalPayload = make([]byte, length)
537 copy(orig.OriginalPayload, buf[startPos:pos])
538 }
539 case 11:
540 switch wireType {
541 case proto.WireTypeLen:
542 var length int
543 length, pos, err = proto.ConsumeLen(buf, pos)
544 if err != nil {
545 return err
546 }
547 startPos := pos - length
548 var num uint64
549 for startPos < pos {
550 num, startPos, err = proto.ConsumeVarint(buf[:pos], startPos)
551 if err != nil {
552 return err
553 }
554 orig.AttributeIndices = append(orig.AttributeIndices, int32(num))
555 }
556 if startPos != pos {
557 return fmt.Errorf("proto: invalid field len = %d for field AttributeIndices", pos-startPos)
558 }
559 case proto.WireTypeVarint:
560 var num uint64
561 num, pos, err = proto.ConsumeVarint(buf, pos)
562 if err != nil {
563 return err
564 }
565 orig.AttributeIndices = append(orig.AttributeIndices, int32(num))
566 default:
567 return fmt.Errorf("proto: wrong wireType = %d for field AttributeIndices", wireType)
568 }
569 default:
570 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
571 if err != nil {
572 return err
573 }
574 }
575 }
576 return nil
577 }
578
579 func GenTestProfile() *Profile {
580 orig := NewProfile()
581 orig.SampleType = *GenTestValueType()
582 orig.Samples = []*Sample{{}, GenTestSample()}
583 orig.TimeUnixNano = uint64(13)
584 orig.DurationNano = uint64(13)
585 orig.PeriodType = *GenTestValueType()
586 orig.Period = int64(13)
587 orig.ProfileId = *GenTestProfileID()
588 orig.DroppedAttributesCount = uint32(13)
589 orig.OriginalPayloadFormat = "test_originalpayloadformat"
590 orig.OriginalPayload = []byte{1, 2, 3}
591 orig.AttributeIndices = []int32{int32(0), int32(13)}
592 return orig
593 }
594
595 func GenTestProfilePtrSlice() []*Profile {
596 orig := make([]*Profile, 5)
597 orig[0] = NewProfile()
598 orig[1] = GenTestProfile()
599 orig[2] = NewProfile()
600 orig[3] = GenTestProfile()
601 orig[4] = NewProfile()
602 return orig
603 }
604
605 func GenTestProfileSlice() []Profile {
606 orig := make([]Profile, 5)
607 orig[1] = *GenTestProfile()
608 orig[3] = *GenTestProfile()
609 return orig
610 }