Debian Codegraph @

pdata/internal/generated_proto_function.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 // Function describes a function, including its human-readable name, system name, source file, and starting line number in the source.
18 type Function struct {
19 NameStrindex int32
20 SystemNameStrindex int32
21 FilenameStrindex int32
22 StartLine int64
23 }
24
25 var (
26 protoPoolFunction = sync.Pool{
27 New: func() any {
28 return &Function{}
29 },
30 }
31 )
32
33 func NewFunction() *Function {
34 if !UseProtoPooling.IsEnabled() {
35 return &Function{}
36 }
37 return protoPoolFunction.Get().(*Function)
38 }
39
40 func DeleteFunction(orig *Function, nullable bool) {
41 if orig == nil {
42 return
43 }
44
45 if !UseProtoPooling.IsEnabled() {
46 orig.Reset()
47 return
48 }
49
50 orig.Reset()
51 if nullable {
52 protoPoolFunction.Put(orig)
53 }
54 }
55
56 func CopyFunction(dest, src *Function) *Function {
57 // If copying to same object, just return.
58 if src == dest {
59 return dest
60 }
61
62 if src == nil {
63 return nil
64 }
65
66 if dest == nil {
67 dest = NewFunction()
68 }
69 dest.NameStrindex = src.NameStrindex
70
71 dest.SystemNameStrindex = src.SystemNameStrindex
72
73 dest.FilenameStrindex = src.FilenameStrindex
74
75 dest.StartLine = src.StartLine
76
77 return dest
78 }
79
80 func CopyFunctionSlice(dest, src []Function) []Function {
81 var newDest []Function
82 if cap(dest) < len(src) {
83 newDest = make([]Function, len(src))
84 } else {
85 newDest = dest[:len(src)]
86 // Cleanup the rest of the elements so GC can free the memory.
87 // This can happen when len(src) < len(dest) < cap(dest).
88 for i := len(src); i < len(dest); i++ {
89 DeleteFunction(&dest[i], false)
90 }
91 }
92 for i := range src {
93 CopyFunction(&newDest[i], &src[i])
94 }
95 return newDest
96 }
97
98 func CopyFunctionPtrSlice(dest, src []*Function) []*Function {
99 var newDest []*Function
100 if cap(dest) < len(src) {
101 newDest = make([]*Function, len(src))
102 // Copy old pointers to re-use.
103 copy(newDest, dest)
104 // Add new pointers for missing elements from len(dest) to len(srt).
105 for i := len(dest); i < len(src); i++ {
106 newDest[i] = NewFunction()
107 }
108 } else {
109 newDest = dest[:len(src)]
110 // Cleanup the rest of the elements so GC can free the memory.
111 // This can happen when len(src) < len(dest) < cap(dest).
112 for i := len(src); i < len(dest); i++ {
113 DeleteFunction(dest[i], true)
114 dest[i] = nil
115 }
116 // Add new pointers for missing elements.
117 // This can happen when len(dest) < len(src) < cap(dest).
118 for i := len(dest); i < len(src); i++ {
119 newDest[i] = NewFunction()
120 }
121 }
122 for i := range src {
123 CopyFunction(newDest[i], src[i])
124 }
125 return newDest
126 }
127
128 func (orig *Function) Reset() {
129 *orig = Function{}
130 }
131
132 // MarshalJSON marshals all properties from the current struct to the destination stream.
133 func (orig *Function) MarshalJSON(dest *json.Stream) {
134 dest.WriteObjectStart()
135 if orig.NameStrindex != int32(0) {
136 dest.WriteObjectField("nameStrindex")
137 dest.WriteInt32(orig.NameStrindex)
138 }
139 if orig.SystemNameStrindex != int32(0) {
140 dest.WriteObjectField("systemNameStrindex")
141 dest.WriteInt32(orig.SystemNameStrindex)
142 }
143 if orig.FilenameStrindex != int32(0) {
144 dest.WriteObjectField("filenameStrindex")
145 dest.WriteInt32(orig.FilenameStrindex)
146 }
147 if orig.StartLine != int64(0) {
148 dest.WriteObjectField("startLine")
149 dest.WriteInt64(orig.StartLine)
150 }
151 dest.WriteObjectEnd()
152 }
153
154 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
155 func (orig *Function) UnmarshalJSON(iter *json.Iterator) {
156 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
157 switch f {
158 case "nameStrindex", "name_strindex":
159 orig.NameStrindex = iter.ReadInt32()
160 case "systemNameStrindex", "system_name_strindex":
161 orig.SystemNameStrindex = iter.ReadInt32()
162 case "filenameStrindex", "filename_strindex":
163 orig.FilenameStrindex = iter.ReadInt32()
164 case "startLine", "start_line":
165 orig.StartLine = iter.ReadInt64()
166 default:
167 iter.Skip()
168 }
169 }
170 }
171
172 func (orig *Function) SizeProto() int {
173 var n int
174 var l int
175 _ = l
176 if orig.NameStrindex != 0 {
177 n += 1 + proto.Sov(uint64(orig.NameStrindex))
178 }
179 if orig.SystemNameStrindex != 0 {
180 n += 1 + proto.Sov(uint64(orig.SystemNameStrindex))
181 }
182 if orig.FilenameStrindex != 0 {
183 n += 1 + proto.Sov(uint64(orig.FilenameStrindex))
184 }
185 if orig.StartLine != 0 {
186 n += 1 + proto.Sov(uint64(orig.StartLine))
187 }
188 return n
189 }
190
191 func (orig *Function) MarshalProto(buf []byte) int {
192 pos := len(buf)
193 var l int
194 _ = l
195 if orig.NameStrindex != 0 {
196 pos = proto.EncodeVarint(buf, pos, uint64(orig.NameStrindex))
197 pos--
198 buf[pos] = 0x8
199 }
200 if orig.SystemNameStrindex != 0 {
201 pos = proto.EncodeVarint(buf, pos, uint64(orig.SystemNameStrindex))
202 pos--
203 buf[pos] = 0x10
204 }
205 if orig.FilenameStrindex != 0 {
206 pos = proto.EncodeVarint(buf, pos, uint64(orig.FilenameStrindex))
207 pos--
208 buf[pos] = 0x18
209 }
210 if orig.StartLine != 0 {
211 pos = proto.EncodeVarint(buf, pos, uint64(orig.StartLine))
212 pos--
213 buf[pos] = 0x20
214 }
215 return len(buf) - pos
216 }
217
218 func (orig *Function) UnmarshalProto(buf []byte) error {
219 var err error
220 var fieldNum int32
221 var wireType proto.WireType
222
223 l := len(buf)
224 pos := 0
225 for pos < l {
226 // If in a group parsing, move to the next tag.
227 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
228 if err != nil {
229 return err
230 }
231 switch fieldNum {
232
233 case 1:
234 if wireType != proto.WireTypeVarint {
235 return fmt.Errorf("proto: wrong wireType = %d for field NameStrindex", wireType)
236 }
237 var num uint64
238 num, pos, err = proto.ConsumeVarint(buf, pos)
239 if err != nil {
240 return err
241 }
242
243 orig.NameStrindex = int32(num)
244
245 case 2:
246 if wireType != proto.WireTypeVarint {
247 return fmt.Errorf("proto: wrong wireType = %d for field SystemNameStrindex", wireType)
248 }
249 var num uint64
250 num, pos, err = proto.ConsumeVarint(buf, pos)
251 if err != nil {
252 return err
253 }
254
255 orig.SystemNameStrindex = int32(num)
256
257 case 3:
258 if wireType != proto.WireTypeVarint {
259 return fmt.Errorf("proto: wrong wireType = %d for field FilenameStrindex", wireType)
260 }
261 var num uint64
262 num, pos, err = proto.ConsumeVarint(buf, pos)
263 if err != nil {
264 return err
265 }
266
267 orig.FilenameStrindex = int32(num)
268
269 case 4:
270 if wireType != proto.WireTypeVarint {
271 return fmt.Errorf("proto: wrong wireType = %d for field StartLine", wireType)
272 }
273 var num uint64
274 num, pos, err = proto.ConsumeVarint(buf, pos)
275 if err != nil {
276 return err
277 }
278
279 orig.StartLine = int64(num)
280 default:
281 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
282 if err != nil {
283 return err
284 }
285 }
286 }
287 return nil
288 }
289
290 func GenTestFunction() *Function {
291 orig := NewFunction()
292 orig.NameStrindex = int32(13)
293 orig.SystemNameStrindex = int32(13)
294 orig.FilenameStrindex = int32(13)
295 orig.StartLine = int64(13)
296 return orig
297 }
298
299 func GenTestFunctionPtrSlice() []*Function {
300 orig := make([]*Function, 5)
301 orig[0] = NewFunction()
302 orig[1] = GenTestFunction()
303 orig[2] = NewFunction()
304 orig[3] = GenTestFunction()
305 orig[4] = NewFunction()
306 return orig
307 }
308
309 func GenTestFunctionSlice() []Function {
310 orig := make([]Function, 5)
311 orig[1] = *GenTestFunction()
312 orig[3] = *GenTestFunction()
313 return orig
314 }