Debian Codegraph @

pdata/internal/generated_proto_profilesdictionary.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 // ProfilesDictionary is the reference table containing all data shared by profiles across the message being sent.
18 type ProfilesDictionary struct {
19 MappingTable []*Mapping
20 LocationTable []*Location
21 FunctionTable []*Function
22 LinkTable []*Link
23 StringTable []string
24 AttributeTable []*KeyValueAndUnit
25 StackTable []*Stack
26 }
27
28 var (
29 protoPoolProfilesDictionary = sync.Pool{
30 New: func() any {
31 return &ProfilesDictionary{}
32 },
33 }
34 )
35
36 func NewProfilesDictionary() *ProfilesDictionary {
37 if !UseProtoPooling.IsEnabled() {
38 return &ProfilesDictionary{}
39 }
40 return protoPoolProfilesDictionary.Get().(*ProfilesDictionary)
41 }
42
43 func DeleteProfilesDictionary(orig *ProfilesDictionary, nullable bool) {
44 if orig == nil {
45 return
46 }
47
48 if !UseProtoPooling.IsEnabled() {
49 orig.Reset()
50 return
51 }
52
53 for i := range orig.MappingTable {
54 DeleteMapping(orig.MappingTable[i], true)
55 }
56 for i := range orig.LocationTable {
57 DeleteLocation(orig.LocationTable[i], true)
58 }
59 for i := range orig.FunctionTable {
60 DeleteFunction(orig.FunctionTable[i], true)
61 }
62 for i := range orig.LinkTable {
63 DeleteLink(orig.LinkTable[i], true)
64 }
65 for i := range orig.AttributeTable {
66 DeleteKeyValueAndUnit(orig.AttributeTable[i], true)
67 }
68 for i := range orig.StackTable {
69 DeleteStack(orig.StackTable[i], true)
70 }
71
72 orig.Reset()
73 if nullable {
74 protoPoolProfilesDictionary.Put(orig)
75 }
76 }
77
78 func CopyProfilesDictionary(dest, src *ProfilesDictionary) *ProfilesDictionary {
79 // If copying to same object, just return.
80 if src == dest {
81 return dest
82 }
83
84 if src == nil {
85 return nil
86 }
87
88 if dest == nil {
89 dest = NewProfilesDictionary()
90 }
91 dest.MappingTable = CopyMappingPtrSlice(dest.MappingTable, src.MappingTable)
92
93 dest.LocationTable = CopyLocationPtrSlice(dest.LocationTable, src.LocationTable)
94
95 dest.FunctionTable = CopyFunctionPtrSlice(dest.FunctionTable, src.FunctionTable)
96
97 dest.LinkTable = CopyLinkPtrSlice(dest.LinkTable, src.LinkTable)
98
99 dest.StringTable = append(dest.StringTable[:0], src.StringTable...)
100 dest.AttributeTable = CopyKeyValueAndUnitPtrSlice(dest.AttributeTable, src.AttributeTable)
101
102 dest.StackTable = CopyStackPtrSlice(dest.StackTable, src.StackTable)
103
104 return dest
105 }
106
107 func CopyProfilesDictionarySlice(dest, src []ProfilesDictionary) []ProfilesDictionary {
108 var newDest []ProfilesDictionary
109 if cap(dest) < len(src) {
110 newDest = make([]ProfilesDictionary, len(src))
111 } else {
112 newDest = dest[:len(src)]
113 // Cleanup the rest of the elements so GC can free the memory.
114 // This can happen when len(src) < len(dest) < cap(dest).
115 for i := len(src); i < len(dest); i++ {
116 DeleteProfilesDictionary(&dest[i], false)
117 }
118 }
119 for i := range src {
120 CopyProfilesDictionary(&newDest[i], &src[i])
121 }
122 return newDest
123 }
124
125 func CopyProfilesDictionaryPtrSlice(dest, src []*ProfilesDictionary) []*ProfilesDictionary {
126 var newDest []*ProfilesDictionary
127 if cap(dest) < len(src) {
128 newDest = make([]*ProfilesDictionary, len(src))
129 // Copy old pointers to re-use.
130 copy(newDest, dest)
131 // Add new pointers for missing elements from len(dest) to len(srt).
132 for i := len(dest); i < len(src); i++ {
133 newDest[i] = NewProfilesDictionary()
134 }
135 } else {
136 newDest = dest[:len(src)]
137 // Cleanup the rest of the elements so GC can free the memory.
138 // This can happen when len(src) < len(dest) < cap(dest).
139 for i := len(src); i < len(dest); i++ {
140 DeleteProfilesDictionary(dest[i], true)
141 dest[i] = nil
142 }
143 // Add new pointers for missing elements.
144 // This can happen when len(dest) < len(src) < cap(dest).
145 for i := len(dest); i < len(src); i++ {
146 newDest[i] = NewProfilesDictionary()
147 }
148 }
149 for i := range src {
150 CopyProfilesDictionary(newDest[i], src[i])
151 }
152 return newDest
153 }
154
155 func (orig *ProfilesDictionary) Reset() {
156 *orig = ProfilesDictionary{}
157 }
158
159 // MarshalJSON marshals all properties from the current struct to the destination stream.
160 func (orig *ProfilesDictionary) MarshalJSON(dest *json.Stream) {
161 dest.WriteObjectStart()
162 if len(orig.MappingTable) > 0 {
163 dest.WriteObjectField("mappingTable")
164 dest.WriteArrayStart()
165 orig.MappingTable[0].MarshalJSON(dest)
166 for i := 1; i < len(orig.MappingTable); i++ {
167 dest.WriteMore()
168 orig.MappingTable[i].MarshalJSON(dest)
169 }
170 dest.WriteArrayEnd()
171 }
172 if len(orig.LocationTable) > 0 {
173 dest.WriteObjectField("locationTable")
174 dest.WriteArrayStart()
175 orig.LocationTable[0].MarshalJSON(dest)
176 for i := 1; i < len(orig.LocationTable); i++ {
177 dest.WriteMore()
178 orig.LocationTable[i].MarshalJSON(dest)
179 }
180 dest.WriteArrayEnd()
181 }
182 if len(orig.FunctionTable) > 0 {
183 dest.WriteObjectField("functionTable")
184 dest.WriteArrayStart()
185 orig.FunctionTable[0].MarshalJSON(dest)
186 for i := 1; i < len(orig.FunctionTable); i++ {
187 dest.WriteMore()
188 orig.FunctionTable[i].MarshalJSON(dest)
189 }
190 dest.WriteArrayEnd()
191 }
192 if len(orig.LinkTable) > 0 {
193 dest.WriteObjectField("linkTable")
194 dest.WriteArrayStart()
195 orig.LinkTable[0].MarshalJSON(dest)
196 for i := 1; i < len(orig.LinkTable); i++ {
197 dest.WriteMore()
198 orig.LinkTable[i].MarshalJSON(dest)
199 }
200 dest.WriteArrayEnd()
201 }
202 if len(orig.StringTable) > 0 {
203 dest.WriteObjectField("stringTable")
204 dest.WriteArrayStart()
205 dest.WriteString(orig.StringTable[0])
206 for i := 1; i < len(orig.StringTable); i++ {
207 dest.WriteMore()
208 dest.WriteString(orig.StringTable[i])
209 }
210 dest.WriteArrayEnd()
211 }
212 if len(orig.AttributeTable) > 0 {
213 dest.WriteObjectField("attributeTable")
214 dest.WriteArrayStart()
215 orig.AttributeTable[0].MarshalJSON(dest)
216 for i := 1; i < len(orig.AttributeTable); i++ {
217 dest.WriteMore()
218 orig.AttributeTable[i].MarshalJSON(dest)
219 }
220 dest.WriteArrayEnd()
221 }
222 if len(orig.StackTable) > 0 {
223 dest.WriteObjectField("stackTable")
224 dest.WriteArrayStart()
225 orig.StackTable[0].MarshalJSON(dest)
226 for i := 1; i < len(orig.StackTable); i++ {
227 dest.WriteMore()
228 orig.StackTable[i].MarshalJSON(dest)
229 }
230 dest.WriteArrayEnd()
231 }
232 dest.WriteObjectEnd()
233 }
234
235 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
236 func (orig *ProfilesDictionary) UnmarshalJSON(iter *json.Iterator) {
237 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
238 switch f {
239 case "mappingTable", "mapping_table":
240 for iter.ReadArray() {
241 orig.MappingTable = append(orig.MappingTable, NewMapping())
242 orig.MappingTable[len(orig.MappingTable)-1].UnmarshalJSON(iter)
243 }
244
245 case "locationTable", "location_table":
246 for iter.ReadArray() {
247 orig.LocationTable = append(orig.LocationTable, NewLocation())
248 orig.LocationTable[len(orig.LocationTable)-1].UnmarshalJSON(iter)
249 }
250
251 case "functionTable", "function_table":
252 for iter.ReadArray() {
253 orig.FunctionTable = append(orig.FunctionTable, NewFunction())
254 orig.FunctionTable[len(orig.FunctionTable)-1].UnmarshalJSON(iter)
255 }
256
257 case "linkTable", "link_table":
258 for iter.ReadArray() {
259 orig.LinkTable = append(orig.LinkTable, NewLink())
260 orig.LinkTable[len(orig.LinkTable)-1].UnmarshalJSON(iter)
261 }
262
263 case "stringTable", "string_table":
264 for iter.ReadArray() {
265 orig.StringTable = append(orig.StringTable, iter.ReadString())
266 }
267
268 case "attributeTable", "attribute_table":
269 for iter.ReadArray() {
270 orig.AttributeTable = append(orig.AttributeTable, NewKeyValueAndUnit())
271 orig.AttributeTable[len(orig.AttributeTable)-1].UnmarshalJSON(iter)
272 }
273
274 case "stackTable", "stack_table":
275 for iter.ReadArray() {
276 orig.StackTable = append(orig.StackTable, NewStack())
277 orig.StackTable[len(orig.StackTable)-1].UnmarshalJSON(iter)
278 }
279
280 default:
281 iter.Skip()
282 }
283 }
284 }
285
286 func (orig *ProfilesDictionary) SizeProto() int {
287 var n int
288 var l int
289 _ = l
290 for i := range orig.MappingTable {
291 l = orig.MappingTable[i].SizeProto()
292 n += 1 + proto.Sov(uint64(l)) + l
293 }
294 for i := range orig.LocationTable {
295 l = orig.LocationTable[i].SizeProto()
296 n += 1 + proto.Sov(uint64(l)) + l
297 }
298 for i := range orig.FunctionTable {
299 l = orig.FunctionTable[i].SizeProto()
300 n += 1 + proto.Sov(uint64(l)) + l
301 }
302 for i := range orig.LinkTable {
303 l = orig.LinkTable[i].SizeProto()
304 n += 1 + proto.Sov(uint64(l)) + l
305 }
306 for _, s := range orig.StringTable {
307 l = len(s)
308 n += 1 + proto.Sov(uint64(l)) + l
309 }
310 for i := range orig.AttributeTable {
311 l = orig.AttributeTable[i].SizeProto()
312 n += 1 + proto.Sov(uint64(l)) + l
313 }
314 for i := range orig.StackTable {
315 l = orig.StackTable[i].SizeProto()
316 n += 1 + proto.Sov(uint64(l)) + l
317 }
318 return n
319 }
320
321 func (orig *ProfilesDictionary) MarshalProto(buf []byte) int {
322 pos := len(buf)
323 var l int
324 _ = l
325 for i := len(orig.MappingTable) - 1; i >= 0; i-- {
326 l = orig.MappingTable[i].MarshalProto(buf[:pos])
327 pos -= l
328 pos = proto.EncodeVarint(buf, pos, uint64(l))
329 pos--
330 buf[pos] = 0xa
331 }
332 for i := len(orig.LocationTable) - 1; i >= 0; i-- {
333 l = orig.LocationTable[i].MarshalProto(buf[:pos])
334 pos -= l
335 pos = proto.EncodeVarint(buf, pos, uint64(l))
336 pos--
337 buf[pos] = 0x12
338 }
339 for i := len(orig.FunctionTable) - 1; i >= 0; i-- {
340 l = orig.FunctionTable[i].MarshalProto(buf[:pos])
341 pos -= l
342 pos = proto.EncodeVarint(buf, pos, uint64(l))
343 pos--
344 buf[pos] = 0x1a
345 }
346 for i := len(orig.LinkTable) - 1; i >= 0; i-- {
347 l = orig.LinkTable[i].MarshalProto(buf[:pos])
348 pos -= l
349 pos = proto.EncodeVarint(buf, pos, uint64(l))
350 pos--
351 buf[pos] = 0x22
352 }
353 for i := len(orig.StringTable) - 1; i >= 0; i-- {
354 l = len(orig.StringTable[i])
355 pos -= l
356 copy(buf[pos:], orig.StringTable[i])
357 pos = proto.EncodeVarint(buf, pos, uint64(l))
358 pos--
359 buf[pos] = 0x2a
360 }
361 for i := len(orig.AttributeTable) - 1; i >= 0; i-- {
362 l = orig.AttributeTable[i].MarshalProto(buf[:pos])
363 pos -= l
364 pos = proto.EncodeVarint(buf, pos, uint64(l))
365 pos--
366 buf[pos] = 0x32
367 }
368 for i := len(orig.StackTable) - 1; i >= 0; i-- {
369 l = orig.StackTable[i].MarshalProto(buf[:pos])
370 pos -= l
371 pos = proto.EncodeVarint(buf, pos, uint64(l))
372 pos--
373 buf[pos] = 0x3a
374 }
375 return len(buf) - pos
376 }
377
378 func (orig *ProfilesDictionary) UnmarshalProto(buf []byte) error {
379 var err error
380 var fieldNum int32
381 var wireType proto.WireType
382
383 l := len(buf)
384 pos := 0
385 for pos < l {
386 // If in a group parsing, move to the next tag.
387 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
388 if err != nil {
389 return err
390 }
391 switch fieldNum {
392
393 case 1:
394 if wireType != proto.WireTypeLen {
395 return fmt.Errorf("proto: wrong wireType = %d for field MappingTable", wireType)
396 }
397 var length int
398 length, pos, err = proto.ConsumeLen(buf, pos)
399 if err != nil {
400 return err
401 }
402 startPos := pos - length
403 orig.MappingTable = append(orig.MappingTable, NewMapping())
404 err = orig.MappingTable[len(orig.MappingTable)-1].UnmarshalProto(buf[startPos:pos])
405 if err != nil {
406 return err
407 }
408
409 case 2:
410 if wireType != proto.WireTypeLen {
411 return fmt.Errorf("proto: wrong wireType = %d for field LocationTable", wireType)
412 }
413 var length int
414 length, pos, err = proto.ConsumeLen(buf, pos)
415 if err != nil {
416 return err
417 }
418 startPos := pos - length
419 orig.LocationTable = append(orig.LocationTable, NewLocation())
420 err = orig.LocationTable[len(orig.LocationTable)-1].UnmarshalProto(buf[startPos:pos])
421 if err != nil {
422 return err
423 }
424
425 case 3:
426 if wireType != proto.WireTypeLen {
427 return fmt.Errorf("proto: wrong wireType = %d for field FunctionTable", wireType)
428 }
429 var length int
430 length, pos, err = proto.ConsumeLen(buf, pos)
431 if err != nil {
432 return err
433 }
434 startPos := pos - length
435 orig.FunctionTable = append(orig.FunctionTable, NewFunction())
436 err = orig.FunctionTable[len(orig.FunctionTable)-1].UnmarshalProto(buf[startPos:pos])
437 if err != nil {
438 return err
439 }
440
441 case 4:
442 if wireType != proto.WireTypeLen {
443 return fmt.Errorf("proto: wrong wireType = %d for field LinkTable", wireType)
444 }
445 var length int
446 length, pos, err = proto.ConsumeLen(buf, pos)
447 if err != nil {
448 return err
449 }
450 startPos := pos - length
451 orig.LinkTable = append(orig.LinkTable, NewLink())
452 err = orig.LinkTable[len(orig.LinkTable)-1].UnmarshalProto(buf[startPos:pos])
453 if err != nil {
454 return err
455 }
456
457 case 5:
458 if wireType != proto.WireTypeLen {
459 return fmt.Errorf("proto: wrong wireType = %d for field StringTable", 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 orig.StringTable = append(orig.StringTable, string(buf[startPos:pos]))
468
469 case 6:
470 if wireType != proto.WireTypeLen {
471 return fmt.Errorf("proto: wrong wireType = %d for field AttributeTable", wireType)
472 }
473 var length int
474 length, pos, err = proto.ConsumeLen(buf, pos)
475 if err != nil {
476 return err
477 }
478 startPos := pos - length
479 orig.AttributeTable = append(orig.AttributeTable, NewKeyValueAndUnit())
480 err = orig.AttributeTable[len(orig.AttributeTable)-1].UnmarshalProto(buf[startPos:pos])
481 if err != nil {
482 return err
483 }
484
485 case 7:
486 if wireType != proto.WireTypeLen {
487 return fmt.Errorf("proto: wrong wireType = %d for field StackTable", 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 orig.StackTable = append(orig.StackTable, NewStack())
496 err = orig.StackTable[len(orig.StackTable)-1].UnmarshalProto(buf[startPos:pos])
497 if err != nil {
498 return err
499 }
500 default:
501 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
502 if err != nil {
503 return err
504 }
505 }
506 }
507 return nil
508 }
509
510 func GenTestProfilesDictionary() *ProfilesDictionary {
511 orig := NewProfilesDictionary()
512 orig.MappingTable = []*Mapping{{}, GenTestMapping()}
513 orig.LocationTable = []*Location{{}, GenTestLocation()}
514 orig.FunctionTable = []*Function{{}, GenTestFunction()}
515 orig.LinkTable = []*Link{{}, GenTestLink()}
516 orig.StringTable = []string{"", "test_stringtable"}
517 orig.AttributeTable = []*KeyValueAndUnit{{}, GenTestKeyValueAndUnit()}
518 orig.StackTable = []*Stack{{}, GenTestStack()}
519 return orig
520 }
521
522 func GenTestProfilesDictionaryPtrSlice() []*ProfilesDictionary {
523 orig := make([]*ProfilesDictionary, 5)
524 orig[0] = NewProfilesDictionary()
525 orig[1] = GenTestProfilesDictionary()
526 orig[2] = NewProfilesDictionary()
527 orig[3] = GenTestProfilesDictionary()
528 orig[4] = NewProfilesDictionary()
529 return orig
530 }
531
532 func GenTestProfilesDictionarySlice() []ProfilesDictionary {
533 orig := make([]ProfilesDictionary, 5)
534 orig[1] = *GenTestProfilesDictionary()
535 orig[3] = *GenTestProfilesDictionary()
536 return orig
537 }