Debian Codegraph @

pdata/internal/generated_proto_summarydatapointvalueatquantile.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 "encoding/binary"
11 "fmt"
12 "math"
13 "sync"
14
15 "go.opentelemetry.io/collector/pdata/internal/json"
16 "go.opentelemetry.io/collector/pdata/internal/proto"
17 )
18
19 // SummaryDataPointValueAtQuantile is a quantile value within a Summary data point.
20 type SummaryDataPointValueAtQuantile struct {
21 Quantile float64
22 Value float64
23 }
24
25 var (
26 protoPoolSummaryDataPointValueAtQuantile = sync.Pool{
27 New: func() any {
28 return &SummaryDataPointValueAtQuantile{}
29 },
30 }
31 )
32
33 func NewSummaryDataPointValueAtQuantile() *SummaryDataPointValueAtQuantile {
34 if !UseProtoPooling.IsEnabled() {
35 return &SummaryDataPointValueAtQuantile{}
36 }
37 return protoPoolSummaryDataPointValueAtQuantile.Get().(*SummaryDataPointValueAtQuantile)
38 }
39
40 func DeleteSummaryDataPointValueAtQuantile(orig *SummaryDataPointValueAtQuantile, nullable bool) {
41 if orig == nil {
42 return
43 }
44
45 if !UseProtoPooling.IsEnabled() {
46 orig.Reset()
47 return
48 }
49
50 orig.Reset()
51 if nullable {
52 protoPoolSummaryDataPointValueAtQuantile.Put(orig)
53 }
54 }
55
56 func CopySummaryDataPointValueAtQuantile(dest, src *SummaryDataPointValueAtQuantile) *SummaryDataPointValueAtQuantile {
57 // If copying to same object, just return.
58 if src == dest {
59 return dest
60 }
61
62 if src == nil {
63 return nil
64 }
65
66 if dest == nil {
67 dest = NewSummaryDataPointValueAtQuantile()
68 }
69 dest.Quantile = src.Quantile
70
71 dest.Value = src.Value
72
73 return dest
74 }
75
76 func CopySummaryDataPointValueAtQuantileSlice(dest, src []SummaryDataPointValueAtQuantile) []SummaryDataPointValueAtQuantile {
77 var newDest []SummaryDataPointValueAtQuantile
78 if cap(dest) < len(src) {
79 newDest = make([]SummaryDataPointValueAtQuantile, 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 DeleteSummaryDataPointValueAtQuantile(&dest[i], false)
86 }
87 }
88 for i := range src {
89 CopySummaryDataPointValueAtQuantile(&newDest[i], &src[i])
90 }
91 return newDest
92 }
93
94 func CopySummaryDataPointValueAtQuantilePtrSlice(dest, src []*SummaryDataPointValueAtQuantile) []*SummaryDataPointValueAtQuantile {
95 var newDest []*SummaryDataPointValueAtQuantile
96 if cap(dest) < len(src) {
97 newDest = make([]*SummaryDataPointValueAtQuantile, 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] = NewSummaryDataPointValueAtQuantile()
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 DeleteSummaryDataPointValueAtQuantile(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] = NewSummaryDataPointValueAtQuantile()
116 }
117 }
118 for i := range src {
119 CopySummaryDataPointValueAtQuantile(newDest[i], src[i])
120 }
121 return newDest
122 }
123
124 func (orig *SummaryDataPointValueAtQuantile) Reset() {
125 *orig = SummaryDataPointValueAtQuantile{}
126 }
127
128 // MarshalJSON marshals all properties from the current struct to the destination stream.
129 func (orig *SummaryDataPointValueAtQuantile) MarshalJSON(dest *json.Stream) {
130 dest.WriteObjectStart()
131 if orig.Quantile != float64(0) {
132 dest.WriteObjectField("quantile")
133 dest.WriteFloat64(orig.Quantile)
134 }
135 if orig.Value != float64(0) {
136 dest.WriteObjectField("value")
137 dest.WriteFloat64(orig.Value)
138 }
139 dest.WriteObjectEnd()
140 }
141
142 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
143 func (orig *SummaryDataPointValueAtQuantile) UnmarshalJSON(iter *json.Iterator) {
144 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
145 switch f {
146 case "quantile":
147 orig.Quantile = iter.ReadFloat64()
148 case "value":
149 orig.Value = iter.ReadFloat64()
150 default:
151 iter.Skip()
152 }
153 }
154 }
155
156 func (orig *SummaryDataPointValueAtQuantile) SizeProto() int {
157 var n int
158 var l int
159 _ = l
160 if orig.Quantile != 0 {
161 n += 9
162 }
163 if orig.Value != 0 {
164 n += 9
165 }
166 return n
167 }
168
169 func (orig *SummaryDataPointValueAtQuantile) MarshalProto(buf []byte) int {
170 pos := len(buf)
171 var l int
172 _ = l
173 if orig.Quantile != 0 {
174 pos -= 8
175 binary.LittleEndian.PutUint64(buf[pos:], math.Float64bits(orig.Quantile))
176 pos--
177 buf[pos] = 0x9
178 }
179 if orig.Value != 0 {
180 pos -= 8
181 binary.LittleEndian.PutUint64(buf[pos:], math.Float64bits(orig.Value))
182 pos--
183 buf[pos] = 0x11
184 }
185 return len(buf) - pos
186 }
187
188 func (orig *SummaryDataPointValueAtQuantile) UnmarshalProto(buf []byte) error {
189 var err error
190 var fieldNum int32
191 var wireType proto.WireType
192
193 l := len(buf)
194 pos := 0
195 for pos < l {
196 // If in a group parsing, move to the next tag.
197 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
198 if err != nil {
199 return err
200 }
201 switch fieldNum {
202
203 case 1:
204 if wireType != proto.WireTypeI64 {
205 return fmt.Errorf("proto: wrong wireType = %d for field Quantile", wireType)
206 }
207 var num uint64
208 num, pos, err = proto.ConsumeI64(buf, pos)
209 if err != nil {
210 return err
211 }
212
213 orig.Quantile = math.Float64frombits(num)
214
215 case 2:
216 if wireType != proto.WireTypeI64 {
217 return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType)
218 }
219 var num uint64
220 num, pos, err = proto.ConsumeI64(buf, pos)
221 if err != nil {
222 return err
223 }
224
225 orig.Value = math.Float64frombits(num)
226 default:
227 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
228 if err != nil {
229 return err
230 }
231 }
232 }
233 return nil
234 }
235
236 func GenTestSummaryDataPointValueAtQuantile() *SummaryDataPointValueAtQuantile {
237 orig := NewSummaryDataPointValueAtQuantile()
238 orig.Quantile = float64(3.1415926)
239 orig.Value = float64(3.1415926)
240 return orig
241 }
242
243 func GenTestSummaryDataPointValueAtQuantilePtrSlice() []*SummaryDataPointValueAtQuantile {
244 orig := make([]*SummaryDataPointValueAtQuantile, 5)
245 orig[0] = NewSummaryDataPointValueAtQuantile()
246 orig[1] = GenTestSummaryDataPointValueAtQuantile()
247 orig[2] = NewSummaryDataPointValueAtQuantile()
248 orig[3] = GenTestSummaryDataPointValueAtQuantile()
249 orig[4] = NewSummaryDataPointValueAtQuantile()
250 return orig
251 }
252
253 func GenTestSummaryDataPointValueAtQuantileSlice() []SummaryDataPointValueAtQuantile {
254 orig := make([]SummaryDataPointValueAtQuantile, 5)
255 orig[1] = *GenTestSummaryDataPointValueAtQuantile()
256 orig[3] = *GenTestSummaryDataPointValueAtQuantile()
257 return orig
258 }