Debian Codegraph @

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