Debian Codegraph @

pdata/internal/generated_proto_location.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 // Location describes function and line table debug information.
18 type Location struct {
19 MappingIndex int32
20 Address uint64
21 Lines []*Line
22 AttributeIndices []int32
23 }
24
25 var (
26 protoPoolLocation = sync.Pool{
27 New: func() any {
28 return &Location{}
29 },
30 }
31 )
32
33 func NewLocation() *Location {
34 if !UseProtoPooling.IsEnabled() {
35 return &Location{}
36 }
37 return protoPoolLocation.Get().(*Location)
38 }
39
40 func DeleteLocation(orig *Location, 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.Lines {
51 DeleteLine(orig.Lines[i], true)
52 }
53
54 orig.Reset()
55 if nullable {
56 protoPoolLocation.Put(orig)
57 }
58 }
59
60 func CopyLocation(dest, src *Location) *Location {
61 // If copying to same object, just return.
62 if src == dest {
63 return dest
64 }
65
66 if src == nil {
67 return nil
68 }
69
70 if dest == nil {
71 dest = NewLocation()
72 }
73 dest.MappingIndex = src.MappingIndex
74
75 dest.Address = src.Address
76
77 dest.Lines = CopyLinePtrSlice(dest.Lines, src.Lines)
78
79 dest.AttributeIndices = append(dest.AttributeIndices[:0], src.AttributeIndices...)
80
81 return dest
82 }
83
84 func CopyLocationSlice(dest, src []Location) []Location {
85 var newDest []Location
86 if cap(dest) < len(src) {
87 newDest = make([]Location, len(src))
88 } else {
89 newDest = dest[:len(src)]
90 // Cleanup the rest of the elements so GC can free the memory.
91 // This can happen when len(src) < len(dest) < cap(dest).
92 for i := len(src); i < len(dest); i++ {
93 DeleteLocation(&dest[i], false)
94 }
95 }
96 for i := range src {
97 CopyLocation(&newDest[i], &src[i])
98 }
99 return newDest
100 }
101
102 func CopyLocationPtrSlice(dest, src []*Location) []*Location {
103 var newDest []*Location
104 if cap(dest) < len(src) {
105 newDest = make([]*Location, len(src))
106 // Copy old pointers to re-use.
107 copy(newDest, dest)
108 // Add new pointers for missing elements from len(dest) to len(srt).
109 for i := len(dest); i < len(src); i++ {
110 newDest[i] = NewLocation()
111 }
112 } else {
113 newDest = dest[:len(src)]
114 // Cleanup the rest of the elements so GC can free the memory.
115 // This can happen when len(src) < len(dest) < cap(dest).
116 for i := len(src); i < len(dest); i++ {
117 DeleteLocation(dest[i], true)
118 dest[i] = nil
119 }
120 // Add new pointers for missing elements.
121 // This can happen when len(dest) < len(src) < cap(dest).
122 for i := len(dest); i < len(src); i++ {
123 newDest[i] = NewLocation()
124 }
125 }
126 for i := range src {
127 CopyLocation(newDest[i], src[i])
128 }
129 return newDest
130 }
131
132 func (orig *Location) Reset() {
133 *orig = Location{}
134 }
135
136 // MarshalJSON marshals all properties from the current struct to the destination stream.
137 func (orig *Location) MarshalJSON(dest *json.Stream) {
138 dest.WriteObjectStart()
139 if orig.MappingIndex != int32(0) {
140 dest.WriteObjectField("mappingIndex")
141 dest.WriteInt32(orig.MappingIndex)
142 }
143 if orig.Address != uint64(0) {
144 dest.WriteObjectField("address")
145 dest.WriteUint64(orig.Address)
146 }
147 if len(orig.Lines) > 0 {
148 dest.WriteObjectField("lines")
149 dest.WriteArrayStart()
150 orig.Lines[0].MarshalJSON(dest)
151 for i := 1; i < len(orig.Lines); i++ {
152 dest.WriteMore()
153 orig.Lines[i].MarshalJSON(dest)
154 }
155 dest.WriteArrayEnd()
156 }
157 if len(orig.AttributeIndices) > 0 {
158 dest.WriteObjectField("attributeIndices")
159 dest.WriteArrayStart()
160 dest.WriteInt32(orig.AttributeIndices[0])
161 for i := 1; i < len(orig.AttributeIndices); i++ {
162 dest.WriteMore()
163 dest.WriteInt32(orig.AttributeIndices[i])
164 }
165 dest.WriteArrayEnd()
166 }
167 dest.WriteObjectEnd()
168 }
169
170 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
171 func (orig *Location) UnmarshalJSON(iter *json.Iterator) {
172 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
173 switch f {
174 case "mappingIndex", "mapping_index":
175 orig.MappingIndex = iter.ReadInt32()
176 case "address":
177 orig.Address = iter.ReadUint64()
178 case "lines":
179 for iter.ReadArray() {
180 orig.Lines = append(orig.Lines, NewLine())
181 orig.Lines[len(orig.Lines)-1].UnmarshalJSON(iter)
182 }
183
184 case "attributeIndices", "attribute_indices":
185 for iter.ReadArray() {
186 orig.AttributeIndices = append(orig.AttributeIndices, iter.ReadInt32())
187 }
188
189 default:
190 iter.Skip()
191 }
192 }
193 }
194
195 func (orig *Location) SizeProto() int {
196 var n int
197 var l int
198 _ = l
199 if orig.MappingIndex != 0 {
200 n += 1 + proto.Sov(uint64(orig.MappingIndex))
201 }
202 if orig.Address != 0 {
203 n += 1 + proto.Sov(uint64(orig.Address))
204 }
205 for i := range orig.Lines {
206 l = orig.Lines[i].SizeProto()
207 n += 1 + proto.Sov(uint64(l)) + l
208 }
209 if len(orig.AttributeIndices) > 0 {
210 l = 0
211 for _, e := range orig.AttributeIndices {
212 l += proto.Sov(uint64(e))
213 }
214 n += 1 + proto.Sov(uint64(l)) + l
215 }
216 return n
217 }
218
219 func (orig *Location) MarshalProto(buf []byte) int {
220 pos := len(buf)
221 var l int
222 _ = l
223 if orig.MappingIndex != 0 {
224 pos = proto.EncodeVarint(buf, pos, uint64(orig.MappingIndex))
225 pos--
226 buf[pos] = 0x8
227 }
228 if orig.Address != 0 {
229 pos = proto.EncodeVarint(buf, pos, uint64(orig.Address))
230 pos--
231 buf[pos] = 0x10
232 }
233 for i := len(orig.Lines) - 1; i >= 0; i-- {
234 l = orig.Lines[i].MarshalProto(buf[:pos])
235 pos -= l
236 pos = proto.EncodeVarint(buf, pos, uint64(l))
237 pos--
238 buf[pos] = 0x1a
239 }
240 l = len(orig.AttributeIndices)
241 if l > 0 {
242 endPos := pos
243 for i := l - 1; i >= 0; i-- {
244 pos = proto.EncodeVarint(buf, pos, uint64(orig.AttributeIndices[i]))
245 }
246 pos = proto.EncodeVarint(buf, pos, uint64(endPos-pos))
247 pos--
248 buf[pos] = 0x22
249 }
250 return len(buf) - pos
251 }
252
253 func (orig *Location) UnmarshalProto(buf []byte) error {
254 var err error
255 var fieldNum int32
256 var wireType proto.WireType
257
258 l := len(buf)
259 pos := 0
260 for pos < l {
261 // If in a group parsing, move to the next tag.
262 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
263 if err != nil {
264 return err
265 }
266 switch fieldNum {
267
268 case 1:
269 if wireType != proto.WireTypeVarint {
270 return fmt.Errorf("proto: wrong wireType = %d for field MappingIndex", wireType)
271 }
272 var num uint64
273 num, pos, err = proto.ConsumeVarint(buf, pos)
274 if err != nil {
275 return err
276 }
277
278 orig.MappingIndex = int32(num)
279
280 case 2:
281 if wireType != proto.WireTypeVarint {
282 return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType)
283 }
284 var num uint64
285 num, pos, err = proto.ConsumeVarint(buf, pos)
286 if err != nil {
287 return err
288 }
289
290 orig.Address = uint64(num)
291
292 case 3:
293 if wireType != proto.WireTypeLen {
294 return fmt.Errorf("proto: wrong wireType = %d for field Lines", wireType)
295 }
296 var length int
297 length, pos, err = proto.ConsumeLen(buf, pos)
298 if err != nil {
299 return err
300 }
301 startPos := pos - length
302 orig.Lines = append(orig.Lines, NewLine())
303 err = orig.Lines[len(orig.Lines)-1].UnmarshalProto(buf[startPos:pos])
304 if err != nil {
305 return err
306 }
307 case 4:
308 switch wireType {
309 case proto.WireTypeLen:
310 var length int
311 length, pos, err = proto.ConsumeLen(buf, pos)
312 if err != nil {
313 return err
314 }
315 startPos := pos - length
316 var num uint64
317 for startPos < pos {
318 num, startPos, err = proto.ConsumeVarint(buf[:pos], startPos)
319 if err != nil {
320 return err
321 }
322 orig.AttributeIndices = append(orig.AttributeIndices, int32(num))
323 }
324 if startPos != pos {
325 return fmt.Errorf("proto: invalid field len = %d for field AttributeIndices", pos-startPos)
326 }
327 case proto.WireTypeVarint:
328 var num uint64
329 num, pos, err = proto.ConsumeVarint(buf, pos)
330 if err != nil {
331 return err
332 }
333 orig.AttributeIndices = append(orig.AttributeIndices, int32(num))
334 default:
335 return fmt.Errorf("proto: wrong wireType = %d for field AttributeIndices", wireType)
336 }
337 default:
338 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
339 if err != nil {
340 return err
341 }
342 }
343 }
344 return nil
345 }
346
347 func GenTestLocation() *Location {
348 orig := NewLocation()
349 orig.MappingIndex = int32(13)
350 orig.Address = uint64(13)
351 orig.Lines = []*Line{{}, GenTestLine()}
352 orig.AttributeIndices = []int32{int32(0), int32(13)}
353 return orig
354 }
355
356 func GenTestLocationPtrSlice() []*Location {
357 orig := make([]*Location, 5)
358 orig[0] = NewLocation()
359 orig[1] = GenTestLocation()
360 orig[2] = NewLocation()
361 orig[3] = GenTestLocation()
362 orig[4] = NewLocation()
363 return orig
364 }
365
366 func GenTestLocationSlice() []Location {
367 orig := make([]Location, 5)
368 orig[1] = *GenTestLocation()
369 orig[3] = *GenTestLocation()
370 return orig
371 }