Debian Codegraph @

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