Debian Codegraph @

pdata/internal/generated_proto_mapping.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 // Mapping describes the mapping of a binary in memory, including its address range, file offset, and metadata like build ID
18 type Mapping struct {
19 MemoryStart uint64
20 MemoryLimit uint64
21 FileOffset uint64
22 FilenameStrindex int32
23 AttributeIndices []int32
24 }
25
26 var (
27 protoPoolMapping = sync.Pool{
28 New: func() any {
29 return &Mapping{}
30 },
31 }
32 )
33
34 func NewMapping() *Mapping {
35 if !UseProtoPooling.IsEnabled() {
36 return &Mapping{}
37 }
38 return protoPoolMapping.Get().(*Mapping)
39 }
40
41 func DeleteMapping(orig *Mapping, nullable bool) {
42 if orig == nil {
43 return
44 }
45
46 if !UseProtoPooling.IsEnabled() {
47 orig.Reset()
48 return
49 }
50
51 orig.Reset()
52 if nullable {
53 protoPoolMapping.Put(orig)
54 }
55 }
56
57 func CopyMapping(dest, src *Mapping) *Mapping {
58 // If copying to same object, just return.
59 if src == dest {
60 return dest
61 }
62
63 if src == nil {
64 return nil
65 }
66
67 if dest == nil {
68 dest = NewMapping()
69 }
70 dest.MemoryStart = src.MemoryStart
71
72 dest.MemoryLimit = src.MemoryLimit
73
74 dest.FileOffset = src.FileOffset
75
76 dest.FilenameStrindex = src.FilenameStrindex
77
78 dest.AttributeIndices = append(dest.AttributeIndices[:0], src.AttributeIndices...)
79
80 return dest
81 }
82
83 func CopyMappingSlice(dest, src []Mapping) []Mapping {
84 var newDest []Mapping
85 if cap(dest) < len(src) {
86 newDest = make([]Mapping, len(src))
87 } else {
88 newDest = dest[:len(src)]
89 // Cleanup the rest of the elements so GC can free the memory.
90 // This can happen when len(src) < len(dest) < cap(dest).
91 for i := len(src); i < len(dest); i++ {
92 DeleteMapping(&dest[i], false)
93 }
94 }
95 for i := range src {
96 CopyMapping(&newDest[i], &src[i])
97 }
98 return newDest
99 }
100
101 func CopyMappingPtrSlice(dest, src []*Mapping) []*Mapping {
102 var newDest []*Mapping
103 if cap(dest) < len(src) {
104 newDest = make([]*Mapping, len(src))
105 // Copy old pointers to re-use.
106 copy(newDest, dest)
107 // Add new pointers for missing elements from len(dest) to len(srt).
108 for i := len(dest); i < len(src); i++ {
109 newDest[i] = NewMapping()
110 }
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 DeleteMapping(dest[i], true)
117 dest[i] = nil
118 }
119 // Add new pointers for missing elements.
120 // This can happen when len(dest) < len(src) < cap(dest).
121 for i := len(dest); i < len(src); i++ {
122 newDest[i] = NewMapping()
123 }
124 }
125 for i := range src {
126 CopyMapping(newDest[i], src[i])
127 }
128 return newDest
129 }
130
131 func (orig *Mapping) Reset() {
132 *orig = Mapping{}
133 }
134
135 // MarshalJSON marshals all properties from the current struct to the destination stream.
136 func (orig *Mapping) MarshalJSON(dest *json.Stream) {
137 dest.WriteObjectStart()
138 if orig.MemoryStart != uint64(0) {
139 dest.WriteObjectField("memoryStart")
140 dest.WriteUint64(orig.MemoryStart)
141 }
142 if orig.MemoryLimit != uint64(0) {
143 dest.WriteObjectField("memoryLimit")
144 dest.WriteUint64(orig.MemoryLimit)
145 }
146 if orig.FileOffset != uint64(0) {
147 dest.WriteObjectField("fileOffset")
148 dest.WriteUint64(orig.FileOffset)
149 }
150 if orig.FilenameStrindex != int32(0) {
151 dest.WriteObjectField("filenameStrindex")
152 dest.WriteInt32(orig.FilenameStrindex)
153 }
154 if len(orig.AttributeIndices) > 0 {
155 dest.WriteObjectField("attributeIndices")
156 dest.WriteArrayStart()
157 dest.WriteInt32(orig.AttributeIndices[0])
158 for i := 1; i < len(orig.AttributeIndices); i++ {
159 dest.WriteMore()
160 dest.WriteInt32(orig.AttributeIndices[i])
161 }
162 dest.WriteArrayEnd()
163 }
164 dest.WriteObjectEnd()
165 }
166
167 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
168 func (orig *Mapping) UnmarshalJSON(iter *json.Iterator) {
169 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
170 switch f {
171 case "memoryStart", "memory_start":
172 orig.MemoryStart = iter.ReadUint64()
173 case "memoryLimit", "memory_limit":
174 orig.MemoryLimit = iter.ReadUint64()
175 case "fileOffset", "file_offset":
176 orig.FileOffset = iter.ReadUint64()
177 case "filenameStrindex", "filename_strindex":
178 orig.FilenameStrindex = iter.ReadInt32()
179 case "attributeIndices", "attribute_indices":
180 for iter.ReadArray() {
181 orig.AttributeIndices = append(orig.AttributeIndices, iter.ReadInt32())
182 }
183
184 default:
185 iter.Skip()
186 }
187 }
188 }
189
190 func (orig *Mapping) SizeProto() int {
191 var n int
192 var l int
193 _ = l
194 if orig.MemoryStart != 0 {
195 n += 1 + proto.Sov(uint64(orig.MemoryStart))
196 }
197 if orig.MemoryLimit != 0 {
198 n += 1 + proto.Sov(uint64(orig.MemoryLimit))
199 }
200 if orig.FileOffset != 0 {
201 n += 1 + proto.Sov(uint64(orig.FileOffset))
202 }
203 if orig.FilenameStrindex != 0 {
204 n += 1 + proto.Sov(uint64(orig.FilenameStrindex))
205 }
206 if len(orig.AttributeIndices) > 0 {
207 l = 0
208 for _, e := range orig.AttributeIndices {
209 l += proto.Sov(uint64(e))
210 }
211 n += 1 + proto.Sov(uint64(l)) + l
212 }
213 return n
214 }
215
216 func (orig *Mapping) MarshalProto(buf []byte) int {
217 pos := len(buf)
218 var l int
219 _ = l
220 if orig.MemoryStart != 0 {
221 pos = proto.EncodeVarint(buf, pos, uint64(orig.MemoryStart))
222 pos--
223 buf[pos] = 0x8
224 }
225 if orig.MemoryLimit != 0 {
226 pos = proto.EncodeVarint(buf, pos, uint64(orig.MemoryLimit))
227 pos--
228 buf[pos] = 0x10
229 }
230 if orig.FileOffset != 0 {
231 pos = proto.EncodeVarint(buf, pos, uint64(orig.FileOffset))
232 pos--
233 buf[pos] = 0x18
234 }
235 if orig.FilenameStrindex != 0 {
236 pos = proto.EncodeVarint(buf, pos, uint64(orig.FilenameStrindex))
237 pos--
238 buf[pos] = 0x20
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] = 0x2a
249 }
250 return len(buf) - pos
251 }
252
253 func (orig *Mapping) 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 MemoryStart", 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.MemoryStart = uint64(num)
279
280 case 2:
281 if wireType != proto.WireTypeVarint {
282 return fmt.Errorf("proto: wrong wireType = %d for field MemoryLimit", 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.MemoryLimit = uint64(num)
291
292 case 3:
293 if wireType != proto.WireTypeVarint {
294 return fmt.Errorf("proto: wrong wireType = %d for field FileOffset", wireType)
295 }
296 var num uint64
297 num, pos, err = proto.ConsumeVarint(buf, pos)
298 if err != nil {
299 return err
300 }
301
302 orig.FileOffset = uint64(num)
303
304 case 4:
305 if wireType != proto.WireTypeVarint {
306 return fmt.Errorf("proto: wrong wireType = %d for field FilenameStrindex", wireType)
307 }
308 var num uint64
309 num, pos, err = proto.ConsumeVarint(buf, pos)
310 if err != nil {
311 return err
312 }
313
314 orig.FilenameStrindex = int32(num)
315 case 5:
316 switch wireType {
317 case proto.WireTypeLen:
318 var length int
319 length, pos, err = proto.ConsumeLen(buf, pos)
320 if err != nil {
321 return err
322 }
323 startPos := pos - length
324 var num uint64
325 for startPos < pos {
326 num, startPos, err = proto.ConsumeVarint(buf[:pos], startPos)
327 if err != nil {
328 return err
329 }
330 orig.AttributeIndices = append(orig.AttributeIndices, int32(num))
331 }
332 if startPos != pos {
333 return fmt.Errorf("proto: invalid field len = %d for field AttributeIndices", pos-startPos)
334 }
335 case proto.WireTypeVarint:
336 var num uint64
337 num, pos, err = proto.ConsumeVarint(buf, pos)
338 if err != nil {
339 return err
340 }
341 orig.AttributeIndices = append(orig.AttributeIndices, int32(num))
342 default:
343 return fmt.Errorf("proto: wrong wireType = %d for field AttributeIndices", wireType)
344 }
345 default:
346 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
347 if err != nil {
348 return err
349 }
350 }
351 }
352 return nil
353 }
354
355 func GenTestMapping() *Mapping {
356 orig := NewMapping()
357 orig.MemoryStart = uint64(13)
358 orig.MemoryLimit = uint64(13)
359 orig.FileOffset = uint64(13)
360 orig.FilenameStrindex = int32(13)
361 orig.AttributeIndices = []int32{int32(0), int32(13)}
362 return orig
363 }
364
365 func GenTestMappingPtrSlice() []*Mapping {
366 orig := make([]*Mapping, 5)
367 orig[0] = NewMapping()
368 orig[1] = GenTestMapping()
369 orig[2] = NewMapping()
370 orig[3] = GenTestMapping()
371 orig[4] = NewMapping()
372 return orig
373 }
374
375 func GenTestMappingSlice() []Mapping {
376 orig := make([]Mapping, 5)
377 orig[1] = *GenTestMapping()
378 orig[3] = *GenTestMapping()
379 return orig
380 }