Debian Codegraph @

pdata/internal/generated_proto_status.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 // Status is an optional final status for this span. Semantically, when Status was not
18 // set, that means the span ended without errors and to assume Status.Ok (code = 0).
19 type Status struct {
20 Message string
21 Code StatusCode
22 }
23
24 var (
25 protoPoolStatus = sync.Pool{
26 New: func() any {
27 return &Status{}
28 },
29 }
30 )
31
32 func NewStatus() *Status {
33 if !UseProtoPooling.IsEnabled() {
34 return &Status{}
35 }
36 return protoPoolStatus.Get().(*Status)
37 }
38
39 func DeleteStatus(orig *Status, nullable bool) {
40 if orig == nil {
41 return
42 }
43
44 if !UseProtoPooling.IsEnabled() {
45 orig.Reset()
46 return
47 }
48
49 orig.Reset()
50 if nullable {
51 protoPoolStatus.Put(orig)
52 }
53 }
54
55 func CopyStatus(dest, src *Status) *Status {
56 // If copying to same object, just return.
57 if src == dest {
58 return dest
59 }
60
61 if src == nil {
62 return nil
63 }
64
65 if dest == nil {
66 dest = NewStatus()
67 }
68 dest.Message = src.Message
69
70 dest.Code = src.Code
71
72 return dest
73 }
74
75 func CopyStatusSlice(dest, src []Status) []Status {
76 var newDest []Status
77 if cap(dest) < len(src) {
78 newDest = make([]Status, 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 DeleteStatus(&dest[i], false)
85 }
86 }
87 for i := range src {
88 CopyStatus(&newDest[i], &src[i])
89 }
90 return newDest
91 }
92
93 func CopyStatusPtrSlice(dest, src []*Status) []*Status {
94 var newDest []*Status
95 if cap(dest) < len(src) {
96 newDest = make([]*Status, 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] = NewStatus()
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 DeleteStatus(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] = NewStatus()
115 }
116 }
117 for i := range src {
118 CopyStatus(newDest[i], src[i])
119 }
120 return newDest
121 }
122
123 func (orig *Status) Reset() {
124 *orig = Status{}
125 }
126
127 // MarshalJSON marshals all properties from the current struct to the destination stream.
128 func (orig *Status) MarshalJSON(dest *json.Stream) {
129 dest.WriteObjectStart()
130 if orig.Message != "" {
131 dest.WriteObjectField("message")
132 dest.WriteString(orig.Message)
133 }
134
135 if int32(orig.Code) != 0 {
136 dest.WriteObjectField("code")
137 dest.WriteInt32(int32(orig.Code))
138 }
139 dest.WriteObjectEnd()
140 }
141
142 // UnmarshalJSON unmarshals all properties from the current struct from the source iterator.
143 func (orig *Status) UnmarshalJSON(iter *json.Iterator) {
144 for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
145 switch f {
146 case "message":
147 orig.Message = iter.ReadString()
148 case "code":
149 orig.Code = StatusCode(iter.ReadEnumValue(StatusCode_value))
150 default:
151 iter.Skip()
152 }
153 }
154 }
155
156 func (orig *Status) SizeProto() int {
157 var n int
158 var l int
159 _ = l
160 l = len(orig.Message)
161 if l > 0 {
162 n += 1 + proto.Sov(uint64(l)) + l
163 }
164 if orig.Code != 0 {
165 n += 1 + proto.Sov(uint64(orig.Code))
166 }
167 return n
168 }
169
170 func (orig *Status) MarshalProto(buf []byte) int {
171 pos := len(buf)
172 var l int
173 _ = l
174 l = len(orig.Message)
175 if l > 0 {
176 pos -= l
177 copy(buf[pos:], orig.Message)
178 pos = proto.EncodeVarint(buf, pos, uint64(l))
179 pos--
180 buf[pos] = 0x12
181 }
182 if orig.Code != 0 {
183 pos = proto.EncodeVarint(buf, pos, uint64(orig.Code))
184 pos--
185 buf[pos] = 0x18
186 }
187 return len(buf) - pos
188 }
189
190 func (orig *Status) UnmarshalProto(buf []byte) error {
191 var err error
192 var fieldNum int32
193 var wireType proto.WireType
194
195 l := len(buf)
196 pos := 0
197 for pos < l {
198 // If in a group parsing, move to the next tag.
199 fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos)
200 if err != nil {
201 return err
202 }
203 switch fieldNum {
204
205 case 2:
206 if wireType != proto.WireTypeLen {
207 return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType)
208 }
209 var length int
210 length, pos, err = proto.ConsumeLen(buf, pos)
211 if err != nil {
212 return err
213 }
214 startPos := pos - length
215 orig.Message = string(buf[startPos:pos])
216
217 case 3:
218 if wireType != proto.WireTypeVarint {
219 return fmt.Errorf("proto: wrong wireType = %d for field Code", 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.Code = StatusCode(num)
228 default:
229 pos, err = proto.ConsumeUnknown(buf, pos, wireType)
230 if err != nil {
231 return err
232 }
233 }
234 }
235 return nil
236 }
237
238 func GenTestStatus() *Status {
239 orig := NewStatus()
240 orig.Message = "test_message"
241 orig.Code = StatusCode(13)
242 return orig
243 }
244
245 func GenTestStatusPtrSlice() []*Status {
246 orig := make([]*Status, 5)
247 orig[0] = NewStatus()
248 orig[1] = GenTestStatus()
249 orig[2] = NewStatus()
250 orig[3] = GenTestStatus()
251 orig[4] = NewStatus()
252 return orig
253 }
254
255 func GenTestStatusSlice() []Status {
256 orig := make([]Status, 5)
257 orig[1] = *GenTestStatus()
258 orig[3] = *GenTestStatus()
259 return orig
260 }