Debian Codegraph @

pdata/internal/generated_proto_stack.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 // Stack represents a stack trace as a list of locations.
18
19 type Stack struct {
20 LocationIndices []int32
21 }
22
23 var (
24 protoPoolStack = sync.Pool{
25 New: func() any {
26 return &Stack{}
27 },
28 }
29 )
30
31 func NewStack() *Stack {
32 if !UseProtoPooling.IsEnabled() {
33 return &Stack{}
34 }
35 return protoPoolStack.Get().(*Stack)
36 }
37
38 func DeleteStack(orig *Stack, 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 protoPoolStack.Put(orig)
51 }
52 }
53
54 func CopyStack(dest, src *Stack) *Stack {
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 = NewStack()
66 }
67 dest.LocationIndices = append(dest.LocationIndices[:0], src.LocationIndices...)
68
69 return dest
70 }
71
72 func CopyStackSlice(dest, src []Stack) []Stack {
73 var newDest []Stack
74 if cap(dest) < len(src) {
75 newDest = make([]Stack, len(src))
76 } else {
77 newDest = dest[:len(src)]
78 // Cleanup the rest of the elements so GC can free the memory.
79 // This can happen when len(src) < len(dest) < cap(dest).
80 for i := len(src); i < len(dest); i++ {
81 DeleteStack(&dest[i], false)
82 }
83 }
84 for i := range src {
85 CopyStack(&newDest[i], &src[i])
86 }
87 return newDest
88 }
89
90 func CopyStackPtrSlice(dest, src []*Stack) []*Stack {
91 var newDest []*Stack
92 if cap(dest) < len(src) {
93 newDest = make([]*Stack, len(src))
94 // Copy old pointers to re-use.
95 copy(newDest, dest)
96 // Add new pointers for missing elements from len(dest) to len(srt).
97 for i := len(dest); i < len(src); i++ {
98 newDest[i] = NewStack()
99 }
100 } else {
101 newDest = dest[:len(src)]
102 // Cleanup the rest of the elements so GC can free the memory.
103 // This can happen when len(src) < len(dest) < cap(dest).
104 for i := len(src); i < len(dest); i++ {
105 DeleteStack(dest[i], true)
106 dest[i] = nil
107 }
108 // Add new pointers for missing elements.
109 // This can happen when len(dest) < len(src) < cap(dest).
110 for i := len(dest); i < len(src); i++ {
111 newDest[i] = NewStack()
112 }
113 }
114 for i := range src {
115 CopyStack(newDest[i], src[i])
116 }
117 return newDest
118 }
119
120 func (orig *Stack) Reset() {
121 *orig = Stack{}
122 }
123
124 // MarshalJSON marshals all properties from the current struct to the destination stream.
125 func (orig *Stack) MarshalJSON(dest *json.Stream) {
126 dest.WriteObjectStart()
127 if len(orig.LocationIndices) > 0 {
128 dest.WriteObjectField("locationIndices")
129 dest.WriteArrayStart()
130 dest.WriteInt32(orig.LocationIndices[0])
131 for i := 1; i < len(orig.LocationIndices); i++ {
132 dest.WriteMore()
133 dest.WriteInt32(orig.LocationIndices[i])
134 }
135 dest.WriteArrayEnd()
136 }
137 dest.WriteObjectEnd()
138 }
139
140 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
141 func (orig *Stack) UnmarshalJSON(iter *json.Iterator) {
142 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
143 switch f {
144 case "locationIndices", "location_indices":
145 for iter.ReadArray() {
146 orig.LocationIndices = append(orig.LocationIndices, iter.ReadInt32())
147 }
148
149 default:
150 iter.Skip()
151 }
152 }
153 }
154
155 func (orig *Stack) SizeProto() int {
156 var n int
157 var l int
158 _ = l
159 if len(orig.LocationIndices) > 0 {
160 l = 0
161 for _, e := range orig.LocationIndices {
162 l += proto.Sov(uint64(e))
163 }
164 n += 1 + proto.Sov(uint64(l)) + l
165 }
166 return n
167 }
168
169 func (orig *Stack) MarshalProto(buf []byte) int {
170 pos := len(buf)
171 var l int
172 _ = l
173 l = len(orig.LocationIndices)
174 if l > 0 {
175 endPos := pos
176 for i := l - 1; i >= 0; i-- {
177 pos = proto.EncodeVarint(buf, pos, uint64(orig.LocationIndices[i]))
178 }
179 pos = proto.EncodeVarint(buf, pos, uint64(endPos-pos))
180 pos--
181 buf[pos] = 0xa
182 }
183 return len(buf) - pos
184 }
185
186 func (orig *Stack) UnmarshalProto(buf []byte) error {
187 var err error
188 var fieldNum int32
189 var wireType proto.WireType
190
191 l := len(buf)
192 pos := 0
193 for pos < l {
194 // If in a group parsing, move to the next tag.
195 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
196 if err != nil {
197 return err
198 }
199 switch fieldNum {
200 case 1:
201 switch wireType {
202 case proto.WireTypeLen:
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 var num uint64
210 for startPos < pos {
211 num, startPos, err = proto.ConsumeVarint(buf[:pos], startPos)
212 if err != nil {
213 return err
214 }
215 orig.LocationIndices = append(orig.LocationIndices, int32(num))
216 }
217 if startPos != pos {
218 return fmt.Errorf("proto: invalid field len = %d for field LocationIndices", pos-startPos)
219 }
220 case proto.WireTypeVarint:
221 var num uint64
222 num, pos, err = proto.ConsumeVarint(buf, pos)
223 if err != nil {
224 return err
225 }
226 orig.LocationIndices = append(orig.LocationIndices, int32(num))
227 default:
228 return fmt.Errorf("proto: wrong wireType = %d for field LocationIndices", wireType)
229 }
230 default:
231 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
232 if err != nil {
233 return err
234 }
235 }
236 }
237 return nil
238 }
239
240 func GenTestStack() *Stack {
241 orig := NewStack()
242 orig.LocationIndices = []int32{int32(0), int32(13)}
243 return orig
244 }
245
246 func GenTestStackPtrSlice() []*Stack {
247 orig := make([]*Stack, 5)
248 orig[0] = NewStack()
249 orig[1] = GenTestStack()
250 orig[2] = NewStack()
251 orig[3] = GenTestStack()
252 orig[4] = NewStack()
253 return orig
254 }
255
256 func GenTestStackSlice() []Stack {
257 orig := make([]Stack, 5)
258 orig[1] = *GenTestStack()
259 orig[3] = *GenTestStack()
260 return orig
261 }