Debian Codegraph @

pdata/internal/generated_proto_exportmetricsservicerequest.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 // Metrics is the top-level struct that is propagated through the metrics pipeline.
18 // Use NewMetrics to create new instance, zero-initialized instance is not valid for use.
19 type ExportMetricsServiceRequest struct {
20 ResourceMetrics []*ResourceMetrics
21 }
22
23 var (
24 protoPoolExportMetricsServiceRequest = sync.Pool{
25 New: func() any {
26 return &ExportMetricsServiceRequest{}
27 },
28 }
29 )
30
31 func NewExportMetricsServiceRequest() *ExportMetricsServiceRequest {
32 if !UseProtoPooling.IsEnabled() {
33 return &ExportMetricsServiceRequest{}
34 }
35 return protoPoolExportMetricsServiceRequest.Get().(*ExportMetricsServiceRequest)
36 }
37
38 func DeleteExportMetricsServiceRequest(orig *ExportMetricsServiceRequest, nullable bool) {
39 if orig == nil {
40 return
41 }
42
43 if !UseProtoPooling.IsEnabled() {
44 orig.Reset()
45 return
46 }
47
48 for i := range orig.ResourceMetrics {
49 DeleteResourceMetrics(orig.ResourceMetrics[i], true)
50 }
51
52 orig.Reset()
53 if nullable {
54 protoPoolExportMetricsServiceRequest.Put(orig)
55 }
56 }
57
58 func CopyExportMetricsServiceRequest(dest, src *ExportMetricsServiceRequest) *ExportMetricsServiceRequest {
59 // If copying to same object, just return.
60 if src == dest {
61 return dest
62 }
63
64 if src == nil {
65 return nil
66 }
67
68 if dest == nil {
69 dest = NewExportMetricsServiceRequest()
70 }
71 dest.ResourceMetrics = CopyResourceMetricsPtrSlice(dest.ResourceMetrics, src.ResourceMetrics)
72
73 return dest
74 }
75
76 func CopyExportMetricsServiceRequestSlice(dest, src []ExportMetricsServiceRequest) []ExportMetricsServiceRequest {
77 var newDest []ExportMetricsServiceRequest
78 if cap(dest) < len(src) {
79 newDest = make([]ExportMetricsServiceRequest, len(src))
80 } else {
81 newDest = dest[:len(src)]
82 // Cleanup the rest of the elements so GC can free the memory.
83 // This can happen when len(src) < len(dest) < cap(dest).
84 for i := len(src); i < len(dest); i++ {
85 DeleteExportMetricsServiceRequest(&dest[i], false)
86 }
87 }
88 for i := range src {
89 CopyExportMetricsServiceRequest(&newDest[i], &src[i])
90 }
91 return newDest
92 }
93
94 func CopyExportMetricsServiceRequestPtrSlice(dest, src []*ExportMetricsServiceRequest) []*ExportMetricsServiceRequest {
95 var newDest []*ExportMetricsServiceRequest
96 if cap(dest) < len(src) {
97 newDest = make([]*ExportMetricsServiceRequest, len(src))
98 // Copy old pointers to re-use.
99 copy(newDest, dest)
100 // Add new pointers for missing elements from len(dest) to len(srt).
101 for i := len(dest); i < len(src); i++ {
102 newDest[i] = NewExportMetricsServiceRequest()
103 }
104 } else {
105 newDest = dest[:len(src)]
106 // Cleanup the rest of the elements so GC can free the memory.
107 // This can happen when len(src) < len(dest) < cap(dest).
108 for i := len(src); i < len(dest); i++ {
109 DeleteExportMetricsServiceRequest(dest[i], true)
110 dest[i] = nil
111 }
112 // Add new pointers for missing elements.
113 // This can happen when len(dest) < len(src) < cap(dest).
114 for i := len(dest); i < len(src); i++ {
115 newDest[i] = NewExportMetricsServiceRequest()
116 }
117 }
118 for i := range src {
119 CopyExportMetricsServiceRequest(newDest[i], src[i])
120 }
121 return newDest
122 }
123
124 func (orig *ExportMetricsServiceRequest) Reset() {
125 *orig = ExportMetricsServiceRequest{}
126 }
127
128 // MarshalJSON marshals all properties from the current struct to the destination stream.
129 func (orig *ExportMetricsServiceRequest) MarshalJSON(dest *json.Stream) {
130 dest.WriteObjectStart()
131 if len(orig.ResourceMetrics) > 0 {
132 dest.WriteObjectField("resourceMetrics")
133 dest.WriteArrayStart()
134 orig.ResourceMetrics[0].MarshalJSON(dest)
135 for i := 1; i < len(orig.ResourceMetrics); i++ {
136 dest.WriteMore()
137 orig.ResourceMetrics[i].MarshalJSON(dest)
138 }
139 dest.WriteArrayEnd()
140 }
141 dest.WriteObjectEnd()
142 }
143
144 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
145 func (orig *ExportMetricsServiceRequest) UnmarshalJSON(iter *json.Iterator) {
146 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
147 switch f {
148 case "resourceMetrics", "resource_metrics":
149 for iter.ReadArray() {
150 orig.ResourceMetrics = append(orig.ResourceMetrics, NewResourceMetrics())
151 orig.ResourceMetrics[len(orig.ResourceMetrics)-1].UnmarshalJSON(iter)
152 }
153
154 default:
155 iter.Skip()
156 }
157 }
158 }
159
160 func (orig *ExportMetricsServiceRequest) SizeProto() int {
161 var n int
162 var l int
163 _ = l
164 for i := range orig.ResourceMetrics {
165 l = orig.ResourceMetrics[i].SizeProto()
166 n += 1 + proto.Sov(uint64(l)) + l
167 }
168 return n
169 }
170
171 func (orig *ExportMetricsServiceRequest) MarshalProto(buf []byte) int {
172 pos := len(buf)
173 var l int
174 _ = l
175 for i := len(orig.ResourceMetrics) - 1; i >= 0; i-- {
176 l = orig.ResourceMetrics[i].MarshalProto(buf[:pos])
177 pos -= l
178 pos = proto.EncodeVarint(buf, pos, uint64(l))
179 pos--
180 buf[pos] = 0xa
181 }
182 return len(buf) - pos
183 }
184
185 func (orig *ExportMetricsServiceRequest) UnmarshalProto(buf []byte) error {
186 var err error
187 var fieldNum int32
188 var wireType proto.WireType
189
190 l := len(buf)
191 pos := 0
192 for pos < l {
193 // If in a group parsing, move to the next tag.
194 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
195 if err != nil {
196 return err
197 }
198 switch fieldNum {
199
200 case 1:
201 if wireType != proto.WireTypeLen {
202 return fmt.Errorf("proto: wrong wireType = %d for field ResourceMetrics", wireType)
203 }
204 var length int
205 length, pos, err = proto.ConsumeLen(buf, pos)
206 if err != nil {
207 return err
208 }
209 startPos := pos - length
210 orig.ResourceMetrics = append(orig.ResourceMetrics, NewResourceMetrics())
211 err = orig.ResourceMetrics[len(orig.ResourceMetrics)-1].UnmarshalProto(buf[startPos:pos])
212 if err != nil {
213 return err
214 }
215 default:
216 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
217 if err != nil {
218 return err
219 }
220 }
221 }
222 return nil
223 }
224
225 func GenTestExportMetricsServiceRequest() *ExportMetricsServiceRequest {
226 orig := NewExportMetricsServiceRequest()
227 orig.ResourceMetrics = []*ResourceMetrics{{}, GenTestResourceMetrics()}
228 return orig
229 }
230
231 func GenTestExportMetricsServiceRequestPtrSlice() []*ExportMetricsServiceRequest {
232 orig := make([]*ExportMetricsServiceRequest, 5)
233 orig[0] = NewExportMetricsServiceRequest()
234 orig[1] = GenTestExportMetricsServiceRequest()
235 orig[2] = NewExportMetricsServiceRequest()
236 orig[3] = GenTestExportMetricsServiceRequest()
237 orig[4] = NewExportMetricsServiceRequest()
238 return orig
239 }
240
241 func GenTestExportMetricsServiceRequestSlice() []ExportMetricsServiceRequest {
242 orig := make([]ExportMetricsServiceRequest, 5)
243 orig[1] = *GenTestExportMetricsServiceRequest()
244 orig[3] = *GenTestExportMetricsServiceRequest()
245 return orig
246 }