Debian Codegraph @

pdata/internal/generated_proto_instrumentationscope.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 // InstrumentationScope is a message representing the instrumentation scope information.
18 type InstrumentationScope struct {
19 Name string
20 Version string
21 Attributes []KeyValue
22 DroppedAttributesCount uint32
23 }
24
25 var (
26 protoPoolInstrumentationScope = sync.Pool{
27 New: func() any {
28 return &InstrumentationScope{}
29 },
30 }
31 )
32
33 func NewInstrumentationScope() *InstrumentationScope {
34 if !UseProtoPooling.IsEnabled() {
35 return &InstrumentationScope{}
36 }
37 return protoPoolInstrumentationScope.Get().(*InstrumentationScope)
38 }
39
40 func DeleteInstrumentationScope(orig *InstrumentationScope, 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.Attributes {
51 DeleteKeyValue(&orig.Attributes[i], false)
52 }
53
54 orig.Reset()
55 if nullable {
56 protoPoolInstrumentationScope.Put(orig)
57 }
58 }
59
60 func CopyInstrumentationScope(dest, src *InstrumentationScope) *InstrumentationScope {
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 = NewInstrumentationScope()
72 }
73 dest.Name = src.Name
74
75 dest.Version = src.Version
76
77 dest.Attributes = CopyKeyValueSlice(dest.Attributes, src.Attributes)
78
79 dest.DroppedAttributesCount = src.DroppedAttributesCount
80
81 return dest
82 }
83
84 func CopyInstrumentationScopeSlice(dest, src []InstrumentationScope) []InstrumentationScope {
85 var newDest []InstrumentationScope
86 if cap(dest) < len(src) {
87 newDest = make([]InstrumentationScope, 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 DeleteInstrumentationScope(&dest[i], false)
94 }
95 }
96 for i := range src {
97 CopyInstrumentationScope(&newDest[i], &src[i])
98 }
99 return newDest
100 }
101
102 func CopyInstrumentationScopePtrSlice(dest, src []*InstrumentationScope) []*InstrumentationScope {
103 var newDest []*InstrumentationScope
104 if cap(dest) < len(src) {
105 newDest = make([]*InstrumentationScope, 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] = NewInstrumentationScope()
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 DeleteInstrumentationScope(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] = NewInstrumentationScope()
124 }
125 }
126 for i := range src {
127 CopyInstrumentationScope(newDest[i], src[i])
128 }
129 return newDest
130 }
131
132 func (orig *InstrumentationScope) Reset() {
133 *orig = InstrumentationScope{}
134 }
135
136 // MarshalJSON marshals all properties from the current struct to the destination stream.
137 func (orig *InstrumentationScope) MarshalJSON(dest *json.Stream) {
138 dest.WriteObjectStart()
139 if orig.Name != "" {
140 dest.WriteObjectField("name")
141 dest.WriteString(orig.Name)
142 }
143 if orig.Version != "" {
144 dest.WriteObjectField("version")
145 dest.WriteString(orig.Version)
146 }
147 if len(orig.Attributes) > 0 {
148 dest.WriteObjectField("attributes")
149 dest.WriteArrayStart()
150 orig.Attributes[0].MarshalJSON(dest)
151 for i := 1; i < len(orig.Attributes); i++ {
152 dest.WriteMore()
153 orig.Attributes[i].MarshalJSON(dest)
154 }
155 dest.WriteArrayEnd()
156 }
157 if orig.DroppedAttributesCount != uint32(0) {
158 dest.WriteObjectField("droppedAttributesCount")
159 dest.WriteUint32(orig.DroppedAttributesCount)
160 }
161 dest.WriteObjectEnd()
162 }
163
164 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
165 func (orig *InstrumentationScope) UnmarshalJSON(iter *json.Iterator) {
166 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
167 switch f {
168 case "name":
169 orig.Name = iter.ReadString()
170 case "version":
171 orig.Version = iter.ReadString()
172 case "attributes":
173 for iter.ReadArray() {
174 orig.Attributes = append(orig.Attributes, KeyValue{})
175 orig.Attributes[len(orig.Attributes)-1].UnmarshalJSON(iter)
176 }
177
178 case "droppedAttributesCount", "dropped_attributes_count":
179 orig.DroppedAttributesCount = iter.ReadUint32()
180 default:
181 iter.Skip()
182 }
183 }
184 }
185
186 func (orig *InstrumentationScope) SizeProto() int {
187 var n int
188 var l int
189 _ = l
190 l = len(orig.Name)
191 if l > 0 {
192 n += 1 + proto.Sov(uint64(l)) + l
193 }
194 l = len(orig.Version)
195 if l > 0 {
196 n += 1 + proto.Sov(uint64(l)) + l
197 }
198 for i := range orig.Attributes {
199 l = orig.Attributes[i].SizeProto()
200 n += 1 + proto.Sov(uint64(l)) + l
201 }
202 if orig.DroppedAttributesCount != 0 {
203 n += 1 + proto.Sov(uint64(orig.DroppedAttributesCount))
204 }
205 return n
206 }
207
208 func (orig *InstrumentationScope) MarshalProto(buf []byte) int {
209 pos := len(buf)
210 var l int
211 _ = l
212 l = len(orig.Name)
213 if l > 0 {
214 pos -= l
215 copy(buf[pos:], orig.Name)
216 pos = proto.EncodeVarint(buf, pos, uint64(l))
217 pos--
218 buf[pos] = 0xa
219 }
220 l = len(orig.Version)
221 if l > 0 {
222 pos -= l
223 copy(buf[pos:], orig.Version)
224 pos = proto.EncodeVarint(buf, pos, uint64(l))
225 pos--
226 buf[pos] = 0x12
227 }
228 for i := len(orig.Attributes) - 1; i >= 0; i-- {
229 l = orig.Attributes[i].MarshalProto(buf[:pos])
230 pos -= l
231 pos = proto.EncodeVarint(buf, pos, uint64(l))
232 pos--
233 buf[pos] = 0x1a
234 }
235 if orig.DroppedAttributesCount != 0 {
236 pos = proto.EncodeVarint(buf, pos, uint64(orig.DroppedAttributesCount))
237 pos--
238 buf[pos] = 0x20
239 }
240 return len(buf) - pos
241 }
242
243 func (orig *InstrumentationScope) UnmarshalProto(buf []byte) error {
244 var err error
245 var fieldNum int32
246 var wireType proto.WireType
247
248 l := len(buf)
249 pos := 0
250 for pos < l {
251 // If in a group parsing, move to the next tag.
252 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
253 if err != nil {
254 return err
255 }
256 switch fieldNum {
257
258 case 1:
259 if wireType != proto.WireTypeLen {
260 return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
261 }
262 var length int
263 length, pos, err = proto.ConsumeLen(buf, pos)
264 if err != nil {
265 return err
266 }
267 startPos := pos - length
268 orig.Name = string(buf[startPos:pos])
269
270 case 2:
271 if wireType != proto.WireTypeLen {
272 return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType)
273 }
274 var length int
275 length, pos, err = proto.ConsumeLen(buf, pos)
276 if err != nil {
277 return err
278 }
279 startPos := pos - length
280 orig.Version = string(buf[startPos:pos])
281
282 case 3:
283 if wireType != proto.WireTypeLen {
284 return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType)
285 }
286 var length int
287 length, pos, err = proto.ConsumeLen(buf, pos)
288 if err != nil {
289 return err
290 }
291 startPos := pos - length
292 orig.Attributes = append(orig.Attributes, KeyValue{})
293 err = orig.Attributes[len(orig.Attributes)-1].UnmarshalProto(buf[startPos:pos])
294 if err != nil {
295 return err
296 }
297
298 case 4:
299 if wireType != proto.WireTypeVarint {
300 return fmt.Errorf("proto: wrong wireType = %d for field DroppedAttributesCount", wireType)
301 }
302 var num uint64
303 num, pos, err = proto.ConsumeVarint(buf, pos)
304 if err != nil {
305 return err
306 }
307
308 orig.DroppedAttributesCount = uint32(num)
309 default:
310 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
311 if err != nil {
312 return err
313 }
314 }
315 }
316 return nil
317 }
318
319 func GenTestInstrumentationScope() *InstrumentationScope {
320 orig := NewInstrumentationScope()
321 orig.Name = "test_name"
322 orig.Version = "test_version"
323 orig.Attributes = []KeyValue{{}, *GenTestKeyValue()}
324 orig.DroppedAttributesCount = uint32(13)
325 return orig
326 }
327
328 func GenTestInstrumentationScopePtrSlice() []*InstrumentationScope {
329 orig := make([]*InstrumentationScope, 5)
330 orig[0] = NewInstrumentationScope()
331 orig[1] = GenTestInstrumentationScope()
332 orig[2] = NewInstrumentationScope()
333 orig[3] = GenTestInstrumentationScope()
334 orig[4] = NewInstrumentationScope()
335 return orig
336 }
337
338 func GenTestInstrumentationScopeSlice() []InstrumentationScope {
339 orig := make([]InstrumentationScope, 5)
340 orig[1] = *GenTestInstrumentationScope()
341 orig[3] = *GenTestInstrumentationScope()
342 return orig
343 }