Debian Codegraph @

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