Debian Codegraph @

pdata/internal/generated_proto_scopemetrics.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 // ScopeMetrics is a collection of metrics from a LibraryInstrumentation.
18 type ScopeMetrics struct {
19 Scope InstrumentationScope
20 Metrics []*Metric
21 SchemaUrl string
22 }
23
24 var (
25 protoPoolScopeMetrics = sync.Pool{
26 New: func() any {
27 return &ScopeMetrics{}
28 },
29 }
30 )
31
32 func NewScopeMetrics() *ScopeMetrics {
33 if !UseProtoPooling.IsEnabled() {
34 return &ScopeMetrics{}
35 }
36 return protoPoolScopeMetrics.Get().(*ScopeMetrics)
37 }
38
39 func DeleteScopeMetrics(orig *ScopeMetrics, nullable bool) {
40 if orig == nil {
41 return
42 }
43
44 if !UseProtoPooling.IsEnabled() {
45 orig.Reset()
46 return
47 }
48
49 DeleteInstrumentationScope(&orig.Scope, false)
50 for i := range orig.Metrics {
51 DeleteMetric(orig.Metrics[i], true)
52 }
53
54 orig.Reset()
55 if nullable {
56 protoPoolScopeMetrics.Put(orig)
57 }
58 }
59
60 func CopyScopeMetrics(dest, src *ScopeMetrics) *ScopeMetrics {
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 = NewScopeMetrics()
72 }
73 CopyInstrumentationScope(&dest.Scope, &src.Scope)
74
75 dest.Metrics = CopyMetricPtrSlice(dest.Metrics, src.Metrics)
76
77 dest.SchemaUrl = src.SchemaUrl
78
79 return dest
80 }
81
82 func CopyScopeMetricsSlice(dest, src []ScopeMetrics) []ScopeMetrics {
83 var newDest []ScopeMetrics
84 if cap(dest) < len(src) {
85 newDest = make([]ScopeMetrics, len(src))
86 } else {
87 newDest = dest[:len(src)]
88 // Cleanup the rest of the elements so GC can free the memory.
89 // This can happen when len(src) < len(dest) < cap(dest).
90 for i := len(src); i < len(dest); i++ {
91 DeleteScopeMetrics(&dest[i], false)
92 }
93 }
94 for i := range src {
95 CopyScopeMetrics(&newDest[i], &src[i])
96 }
97 return newDest
98 }
99
100 func CopyScopeMetricsPtrSlice(dest, src []*ScopeMetrics) []*ScopeMetrics {
101 var newDest []*ScopeMetrics
102 if cap(dest) < len(src) {
103 newDest = make([]*ScopeMetrics, len(src))
104 // Copy old pointers to re-use.
105 copy(newDest, dest)
106 // Add new pointers for missing elements from len(dest) to len(srt).
107 for i := len(dest); i < len(src); i++ {
108 newDest[i] = NewScopeMetrics()
109 }
110 } else {
111 newDest = dest[:len(src)]
112 // Cleanup the rest of the elements so GC can free the memory.
113 // This can happen when len(src) < len(dest) < cap(dest).
114 for i := len(src); i < len(dest); i++ {
115 DeleteScopeMetrics(dest[i], true)
116 dest[i] = nil
117 }
118 // Add new pointers for missing elements.
119 // This can happen when len(dest) < len(src) < cap(dest).
120 for i := len(dest); i < len(src); i++ {
121 newDest[i] = NewScopeMetrics()
122 }
123 }
124 for i := range src {
125 CopyScopeMetrics(newDest[i], src[i])
126 }
127 return newDest
128 }
129
130 func (orig *ScopeMetrics) Reset() {
131 *orig = ScopeMetrics{}
132 }
133
134 // MarshalJSON marshals all properties from the current struct to the destination stream.
135 func (orig *ScopeMetrics) MarshalJSON(dest *json.Stream) {
136 dest.WriteObjectStart()
137 dest.WriteObjectField("scope")
138 orig.Scope.MarshalJSON(dest)
139 if len(orig.Metrics) > 0 {
140 dest.WriteObjectField("metrics")
141 dest.WriteArrayStart()
142 orig.Metrics[0].MarshalJSON(dest)
143 for i := 1; i < len(orig.Metrics); i++ {
144 dest.WriteMore()
145 orig.Metrics[i].MarshalJSON(dest)
146 }
147 dest.WriteArrayEnd()
148 }
149 if orig.SchemaUrl != "" {
150 dest.WriteObjectField("schemaUrl")
151 dest.WriteString(orig.SchemaUrl)
152 }
153 dest.WriteObjectEnd()
154 }
155
156 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
157 func (orig *ScopeMetrics) UnmarshalJSON(iter *json.Iterator) {
158 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
159 switch f {
160 case "scope":
161
162 orig.Scope.UnmarshalJSON(iter)
163 case "metrics":
164 for iter.ReadArray() {
165 orig.Metrics = append(orig.Metrics, NewMetric())
166 orig.Metrics[len(orig.Metrics)-1].UnmarshalJSON(iter)
167 }
168
169 case "schemaUrl", "schema_url":
170 orig.SchemaUrl = iter.ReadString()
171 default:
172 iter.Skip()
173 }
174 }
175 }
176
177 func (orig *ScopeMetrics) SizeProto() int {
178 var n int
179 var l int
180 _ = l
181 l = orig.Scope.SizeProto()
182 n += 1 + proto.Sov(uint64(l)) + l
183 for i := range orig.Metrics {
184 l = orig.Metrics[i].SizeProto()
185 n += 1 + proto.Sov(uint64(l)) + l
186 }
187 l = len(orig.SchemaUrl)
188 if l > 0 {
189 n += 1 + proto.Sov(uint64(l)) + l
190 }
191 return n
192 }
193
194 func (orig *ScopeMetrics) MarshalProto(buf []byte) int {
195 pos := len(buf)
196 var l int
197 _ = l
198 l = orig.Scope.MarshalProto(buf[:pos])
199 pos -= l
200 pos = proto.EncodeVarint(buf, pos, uint64(l))
201 pos--
202 buf[pos] = 0xa
203
204 for i := len(orig.Metrics) - 1; i >= 0; i-- {
205 l = orig.Metrics[i].MarshalProto(buf[:pos])
206 pos -= l
207 pos = proto.EncodeVarint(buf, pos, uint64(l))
208 pos--
209 buf[pos] = 0x12
210 }
211 l = len(orig.SchemaUrl)
212 if l > 0 {
213 pos -= l
214 copy(buf[pos:], orig.SchemaUrl)
215 pos = proto.EncodeVarint(buf, pos, uint64(l))
216 pos--
217 buf[pos] = 0x1a
218 }
219 return len(buf) - pos
220 }
221
222 func (orig *ScopeMetrics) UnmarshalProto(buf []byte) error {
223 var err error
224 var fieldNum int32
225 var wireType proto.WireType
226
227 l := len(buf)
228 pos := 0
229 for pos < l {
230 // If in a group parsing, move to the next tag.
231 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
232 if err != nil {
233 return err
234 }
235 switch fieldNum {
236
237 case 1:
238 if wireType != proto.WireTypeLen {
239 return fmt.Errorf("proto: wrong wireType = %d for field Scope", wireType)
240 }
241 var length int
242 length, pos, err = proto.ConsumeLen(buf, pos)
243 if err != nil {
244 return err
245 }
246 startPos := pos - length
247
248 err = orig.Scope.UnmarshalProto(buf[startPos:pos])
249 if err != nil {
250 return err
251 }
252
253 case 2:
254 if wireType != proto.WireTypeLen {
255 return fmt.Errorf("proto: wrong wireType = %d for field Metrics", wireType)
256 }
257 var length int
258 length, pos, err = proto.ConsumeLen(buf, pos)
259 if err != nil {
260 return err
261 }
262 startPos := pos - length
263 orig.Metrics = append(orig.Metrics, NewMetric())
264 err = orig.Metrics[len(orig.Metrics)-1].UnmarshalProto(buf[startPos:pos])
265 if err != nil {
266 return err
267 }
268
269 case 3:
270 if wireType != proto.WireTypeLen {
271 return fmt.Errorf("proto: wrong wireType = %d for field SchemaUrl", wireType)
272 }
273 var length int
274 length, pos, err = proto.ConsumeLen(buf, pos)
275 if err != nil {
276 return err
277 }
278 startPos := pos - length
279 orig.SchemaUrl = string(buf[startPos:pos])
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 GenTestScopeMetrics() *ScopeMetrics {
291 orig := NewScopeMetrics()
292 orig.Scope = *GenTestInstrumentationScope()
293 orig.Metrics = []*Metric{{}, GenTestMetric()}
294 orig.SchemaUrl = "test_schemaurl"
295 return orig
296 }
297
298 func GenTestScopeMetricsPtrSlice() []*ScopeMetrics {
299 orig := make([]*ScopeMetrics, 5)
300 orig[0] = NewScopeMetrics()
301 orig[1] = GenTestScopeMetrics()
302 orig[2] = NewScopeMetrics()
303 orig[3] = GenTestScopeMetrics()
304 orig[4] = NewScopeMetrics()
305 return orig
306 }
307
308 func GenTestScopeMetricsSlice() []ScopeMetrics {
309 orig := make([]ScopeMetrics, 5)
310 orig[1] = *GenTestScopeMetrics()
311 orig[3] = *GenTestScopeMetrics()
312 return orig
313 }