Debian Codegraph @

pdata/internal/generated_proto_profilesdata.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 // ProfilesData represents the profiles data that can be stored in persistent storage,
18 // OR can be embedded by other protocols that transfer OTLP profiles data but do not
19 // implement the OTLP protocol.
20 type ProfilesData struct {
21 ResourceProfiles []*ResourceProfiles
22 Dictionary ProfilesDictionary
23 }
24
25 var (
26 protoPoolProfilesData = sync.Pool{
27 New: func() any {
28 return &ProfilesData{}
29 },
30 }
31 )
32
33 func NewProfilesData() *ProfilesData {
34 if !UseProtoPooling.IsEnabled() {
35 return &ProfilesData{}
36 }
37 return protoPoolProfilesData.Get().(*ProfilesData)
38 }
39
40 func DeleteProfilesData(orig *ProfilesData, nullable bool) {
41 if orig == nil {
42 return
43 }
44
45 if !UseProtoPooling.IsEnabled() {
46 orig.Reset()
47 return
48 }
49
50 for i := range orig.ResourceProfiles {
51 DeleteResourceProfiles(orig.ResourceProfiles[i], true)
52 }
53 DeleteProfilesDictionary(&orig.Dictionary, false)
54
55 orig.Reset()
56 if nullable {
57 protoPoolProfilesData.Put(orig)
58 }
59 }
60
61 func CopyProfilesData(dest, src *ProfilesData) *ProfilesData {
62 // If copying to same object, just return.
63 if src == dest {
64 return dest
65 }
66
67 if src == nil {
68 return nil
69 }
70
71 if dest == nil {
72 dest = NewProfilesData()
73 }
74 dest.ResourceProfiles = CopyResourceProfilesPtrSlice(dest.ResourceProfiles, src.ResourceProfiles)
75
76 CopyProfilesDictionary(&dest.Dictionary, &src.Dictionary)
77
78 return dest
79 }
80
81 func CopyProfilesDataSlice(dest, src []ProfilesData) []ProfilesData {
82 var newDest []ProfilesData
83 if cap(dest) < len(src) {
84 newDest = make([]ProfilesData, len(src))
85 } else {
86 newDest = dest[:len(src)]
87 // Cleanup the rest of the elements so GC can free the memory.
88 // This can happen when len(src) < len(dest) < cap(dest).
89 for i := len(src); i < len(dest); i++ {
90 DeleteProfilesData(&dest[i], false)
91 }
92 }
93 for i := range src {
94 CopyProfilesData(&newDest[i], &src[i])
95 }
96 return newDest
97 }
98
99 func CopyProfilesDataPtrSlice(dest, src []*ProfilesData) []*ProfilesData {
100 var newDest []*ProfilesData
101 if cap(dest) < len(src) {
102 newDest = make([]*ProfilesData, len(src))
103 // Copy old pointers to re-use.
104 copy(newDest, dest)
105 // Add new pointers for missing elements from len(dest) to len(srt).
106 for i := len(dest); i < len(src); i++ {
107 newDest[i] = NewProfilesData()
108 }
109 } else {
110 newDest = dest[:len(src)]
111 // Cleanup the rest of the elements so GC can free the memory.
112 // This can happen when len(src) < len(dest) < cap(dest).
113 for i := len(src); i < len(dest); i++ {
114 DeleteProfilesData(dest[i], true)
115 dest[i] = nil
116 }
117 // Add new pointers for missing elements.
118 // This can happen when len(dest) < len(src) < cap(dest).
119 for i := len(dest); i < len(src); i++ {
120 newDest[i] = NewProfilesData()
121 }
122 }
123 for i := range src {
124 CopyProfilesData(newDest[i], src[i])
125 }
126 return newDest
127 }
128
129 func (orig *ProfilesData) Reset() {
130 *orig = ProfilesData{}
131 }
132
133 // MarshalJSON marshals all properties from the current struct to the destination stream.
134 func (orig *ProfilesData) MarshalJSON(dest *json.Stream) {
135 dest.WriteObjectStart()
136 if len(orig.ResourceProfiles) > 0 {
137 dest.WriteObjectField("resourceProfiles")
138 dest.WriteArrayStart()
139 orig.ResourceProfiles[0].MarshalJSON(dest)
140 for i := 1; i < len(orig.ResourceProfiles); i++ {
141 dest.WriteMore()
142 orig.ResourceProfiles[i].MarshalJSON(dest)
143 }
144 dest.WriteArrayEnd()
145 }
146 dest.WriteObjectField("dictionary")
147 orig.Dictionary.MarshalJSON(dest)
148 dest.WriteObjectEnd()
149 }
150
151 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
152 func (orig *ProfilesData) UnmarshalJSON(iter *json.Iterator) {
153 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
154 switch f {
155 case "resourceProfiles", "resource_profiles":
156 for iter.ReadArray() {
157 orig.ResourceProfiles = append(orig.ResourceProfiles, NewResourceProfiles())
158 orig.ResourceProfiles[len(orig.ResourceProfiles)-1].UnmarshalJSON(iter)
159 }
160
161 case "dictionary":
162
163 orig.Dictionary.UnmarshalJSON(iter)
164 default:
165 iter.Skip()
166 }
167 }
168 }
169
170 func (orig *ProfilesData) SizeProto() int {
171 var n int
172 var l int
173 _ = l
174 for i := range orig.ResourceProfiles {
175 l = orig.ResourceProfiles[i].SizeProto()
176 n += 1 + proto.Sov(uint64(l)) + l
177 }
178 l = orig.Dictionary.SizeProto()
179 n += 1 + proto.Sov(uint64(l)) + l
180 return n
181 }
182
183 func (orig *ProfilesData) MarshalProto(buf []byte) int {
184 pos := len(buf)
185 var l int
186 _ = l
187 for i := len(orig.ResourceProfiles) - 1; i >= 0; i-- {
188 l = orig.ResourceProfiles[i].MarshalProto(buf[:pos])
189 pos -= l
190 pos = proto.EncodeVarint(buf, pos, uint64(l))
191 pos--
192 buf[pos] = 0xa
193 }
194 l = orig.Dictionary.MarshalProto(buf[:pos])
195 pos -= l
196 pos = proto.EncodeVarint(buf, pos, uint64(l))
197 pos--
198 buf[pos] = 0x12
199
200 return len(buf) - pos
201 }
202
203 func (orig *ProfilesData) 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 ResourceProfiles", 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.ResourceProfiles = append(orig.ResourceProfiles, NewResourceProfiles())
229 err = orig.ResourceProfiles[len(orig.ResourceProfiles)-1].UnmarshalProto(buf[startPos:pos])
230 if err != nil {
231 return err
232 }
233
234 case 2:
235 if wireType != proto.WireTypeLen {
236 return fmt.Errorf("proto: wrong wireType = %d for field Dictionary", wireType)
237 }
238 var length int
239 length, pos, err = proto.ConsumeLen(buf, pos)
240 if err != nil {
241 return err
242 }
243 startPos := pos - length
244
245 err = orig.Dictionary.UnmarshalProto(buf[startPos:pos])
246 if err != nil {
247 return err
248 }
249 default:
250 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
251 if err != nil {
252 return err
253 }
254 }
255 }
256 return nil
257 }
258
259 func GenTestProfilesData() *ProfilesData {
260 orig := NewProfilesData()
261 orig.ResourceProfiles = []*ResourceProfiles{{}, GenTestResourceProfiles()}
262 orig.Dictionary = *GenTestProfilesDictionary()
263 return orig
264 }
265
266 func GenTestProfilesDataPtrSlice() []*ProfilesData {
267 orig := make([]*ProfilesData, 5)
268 orig[0] = NewProfilesData()
269 orig[1] = GenTestProfilesData()
270 orig[2] = NewProfilesData()
271 orig[3] = GenTestProfilesData()
272 orig[4] = NewProfilesData()
273 return orig
274 }
275
276 func GenTestProfilesDataSlice() []ProfilesData {
277 orig := make([]ProfilesData, 5)
278 orig[1] = *GenTestProfilesData()
279 orig[3] = *GenTestProfilesData()
280 return orig
281 }