| 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 |
"sync" |
| 13 |
|
| 14 |
"go.opentelemetry.io/collector/pdata/internal/json" |
| 15 |
"go.opentelemetry.io/collector/pdata/internal/proto" |
| 16 |
) |
| 17 |
|
| 18 |
// SpanEvent is a time-stamped annotation of the span, consisting of user-supplied |
| 19 |
// text description and key-value pairs. See OTLP for event definition. |
| 20 |
type SpanEvent struct { |
| 21 |
TimeUnixNano uint64 |
| 22 |
Name string |
| 23 |
Attributes []KeyValue |
| 24 |
DroppedAttributesCount uint32 |
| 25 |
} |
| 26 |
|
| 27 |
var ( |
| 28 |
protoPoolSpanEvent = sync.Pool{ |
| 29 |
New: func() any { |
| 30 |
return &SpanEvent{} |
| 31 |
}, |
| 32 |
} |
| 33 |
) |
| 34 |
|
| 35 |
func NewSpanEvent() *SpanEvent { |
| 36 |
if !UseProtoPooling.IsEnabled() { |
| 37 |
return &SpanEvent{} |
| 38 |
} |
| 39 |
return protoPoolSpanEvent.Get().(*SpanEvent) |
| 40 |
} |
| 41 |
|
| 42 |
func DeleteSpanEvent(orig *SpanEvent, nullable bool) { |
| 43 |
if orig == nil { |
| 44 |
return |
| 45 |
} |
| 46 |
|
| 47 |
if !UseProtoPooling.IsEnabled() { |
| 48 |
orig.Reset() |
| 49 |
return |
| 50 |
} |
| 51 |
|
| 52 |
for i := range orig.Attributes { |
| 53 |
DeleteKeyValue(&orig.Attributes[i], false) |
| 54 |
} |
| 55 |
|
| 56 |
orig.Reset() |
| 57 |
if nullable { |
| 58 |
protoPoolSpanEvent.Put(orig) |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
func CopySpanEvent(dest, src *SpanEvent) *SpanEvent { |
| 63 |
// If copying to same object, just return. |
| 64 |
if src == dest { |
| 65 |
return dest |
| 66 |
} |
| 67 |
|
| 68 |
if src == nil { |
| 69 |
return nil |
| 70 |
} |
| 71 |
|
| 72 |
if dest == nil { |
| 73 |
dest = NewSpanEvent() |
| 74 |
} |
| 75 |
dest.TimeUnixNano = src.TimeUnixNano |
| 76 |
|
| 77 |
dest.Name = src.Name |
| 78 |
|
| 79 |
dest.Attributes = CopyKeyValueSlice(dest.Attributes, src.Attributes) |
| 80 |
|
| 81 |
dest.DroppedAttributesCount = src.DroppedAttributesCount |
| 82 |
|
| 83 |
return dest |
| 84 |
} |
| 85 |
|
| 86 |
func CopySpanEventSlice(dest, src []SpanEvent) []SpanEvent { |
| 87 |
var newDest []SpanEvent |
| 88 |
if cap(dest) < len(src) { |
| 89 |
newDest = make([]SpanEvent, len(src)) |
| 90 |
} else { |
| 91 |
newDest = dest[:len(src)] |
| 92 |
// Cleanup the rest of the elements so GC can free the memory. |
| 93 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 94 |
for i := len(src); i < len(dest); i++ { |
| 95 |
DeleteSpanEvent(&dest[i], false) |
| 96 |
} |
| 97 |
} |
| 98 |
for i := range src { |
| 99 |
CopySpanEvent(&newDest[i], &src[i]) |
| 100 |
} |
| 101 |
return newDest |
| 102 |
} |
| 103 |
|
| 104 |
func CopySpanEventPtrSlice(dest, src []*SpanEvent) []*SpanEvent { |
| 105 |
var newDest []*SpanEvent |
| 106 |
if cap(dest) < len(src) { |
| 107 |
newDest = make([]*SpanEvent, len(src)) |
| 108 |
// Copy old pointers to re-use. |
| 109 |
copy(newDest, dest) |
| 110 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 111 |
for i := len(dest); i < len(src); i++ { |
| 112 |
newDest[i] = NewSpanEvent() |
| 113 |
} |
| 114 |
} else { |
| 115 |
newDest = dest[:len(src)] |
| 116 |
// Cleanup the rest of the elements so GC can free the memory. |
| 117 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 118 |
for i := len(src); i < len(dest); i++ { |
| 119 |
DeleteSpanEvent(dest[i], true) |
| 120 |
dest[i] = nil |
| 121 |
} |
| 122 |
// Add new pointers for missing elements. |
| 123 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 124 |
for i := len(dest); i < len(src); i++ { |
| 125 |
newDest[i] = NewSpanEvent() |
| 126 |
} |
| 127 |
} |
| 128 |
for i := range src { |
| 129 |
CopySpanEvent(newDest[i], src[i]) |
| 130 |
} |
| 131 |
return newDest |
| 132 |
} |
| 133 |
|
| 134 |
func (orig *SpanEvent) Reset() { |
| 135 |
*orig = SpanEvent{} |
| 136 |
} |
| 137 |
|
| 138 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 139 |
func (orig *SpanEvent) MarshalJSON(dest *json.Stream) { |
| 140 |
dest.WriteObjectStart() |
| 141 |
if orig.TimeUnixNano != uint64(0) { |
| 142 |
dest.WriteObjectField("timeUnixNano") |
| 143 |
dest.WriteUint64(orig.TimeUnixNano) |
| 144 |
} |
| 145 |
if orig.Name != "" { |
| 146 |
dest.WriteObjectField("name") |
| 147 |
dest.WriteString(orig.Name) |
| 148 |
} |
| 149 |
if len(orig.Attributes) > 0 { |
| 150 |
dest.WriteObjectField("attributes") |
| 151 |
dest.WriteArrayStart() |
| 152 |
orig.Attributes[0].MarshalJSON(dest) |
| 153 |
for i := 1; i < len(orig.Attributes); i++ { |
| 154 |
dest.WriteMore() |
| 155 |
orig.Attributes[i].MarshalJSON(dest) |
| 156 |
} |
| 157 |
dest.WriteArrayEnd() |
| 158 |
} |
| 159 |
if orig.DroppedAttributesCount != uint32(0) { |
| 160 |
dest.WriteObjectField("droppedAttributesCount") |
| 161 |
dest.WriteUint32(orig.DroppedAttributesCount) |
| 162 |
} |
| 163 |
dest.WriteObjectEnd() |
| 164 |
} |
| 165 |
|
| 166 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 167 |
func (orig *SpanEvent) UnmarshalJSON(iter *json.Iterator) { |
| 168 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 169 |
switch f { |
| 170 |
case "timeUnixNano", "time_unix_nano": |
| 171 |
orig.TimeUnixNano = iter.ReadUint64() |
| 172 |
case "name": |
| 173 |
orig.Name = iter.ReadString() |
| 174 |
case "attributes": |
| 175 |
for iter.ReadArray() { |
| 176 |
orig.Attributes = append(orig.Attributes, KeyValue{}) |
| 177 |
orig.Attributes[len(orig.Attributes)-1].UnmarshalJSON(iter) |
| 178 |
} |
| 179 |
|
| 180 |
case "droppedAttributesCount", "dropped_attributes_count": |
| 181 |
orig.DroppedAttributesCount = iter.ReadUint32() |
| 182 |
default: |
| 183 |
iter.Skip() |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
func (orig *SpanEvent) SizeProto() int { |
| 189 |
var n int |
| 190 |
var l int |
| 191 |
_ = l |
| 192 |
if orig.TimeUnixNano != 0 { |
| 193 |
n += 9 |
| 194 |
} |
| 195 |
l = len(orig.Name) |
| 196 |
if l > 0 { |
| 197 |
n += 1 + proto.Sov(uint64(l)) + l |
| 198 |
} |
| 199 |
for i := range orig.Attributes { |
| 200 |
l = orig.Attributes[i].SizeProto() |
| 201 |
n += 1 + proto.Sov(uint64(l)) + l |
| 202 |
} |
| 203 |
if orig.DroppedAttributesCount != 0 { |
| 204 |
n += 1 + proto.Sov(uint64(orig.DroppedAttributesCount)) |
| 205 |
} |
| 206 |
return n |
| 207 |
} |
| 208 |
|
| 209 |
func (orig *SpanEvent) MarshalProto(buf []byte) int { |
| 210 |
pos := len(buf) |
| 211 |
var l int |
| 212 |
_ = l |
| 213 |
if orig.TimeUnixNano != 0 { |
| 214 |
pos -= 8 |
| 215 |
binary.LittleEndian.PutUint64(buf[pos:], uint64(orig.TimeUnixNano)) |
| 216 |
pos-- |
| 217 |
buf[pos] = 0x9 |
| 218 |
} |
| 219 |
l = len(orig.Name) |
| 220 |
if l > 0 { |
| 221 |
pos -= l |
| 222 |
copy(buf[pos:], orig.Name) |
| 223 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 224 |
pos-- |
| 225 |
buf[pos] = 0x12 |
| 226 |
} |
| 227 |
for i := len(orig.Attributes) - 1; i >= 0; i-- { |
| 228 |
l = orig.Attributes[i].MarshalProto(buf[:pos]) |
| 229 |
pos -= l |
| 230 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 231 |
pos-- |
| 232 |
buf[pos] = 0x1a |
| 233 |
} |
| 234 |
if orig.DroppedAttributesCount != 0 { |
| 235 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.DroppedAttributesCount)) |
| 236 |
pos-- |
| 237 |
buf[pos] = 0x20 |
| 238 |
} |
| 239 |
return len(buf) - pos |
| 240 |
} |
| 241 |
|
| 242 |
func (orig *SpanEvent) UnmarshalProto(buf []byte) error { |
| 243 |
var err error |
| 244 |
var fieldNum int32 |
| 245 |
var wireType proto.WireType |
| 246 |
|
| 247 |
l := len(buf) |
| 248 |
pos := 0 |
| 249 |
for pos < l { |
| 250 |
// If in a group parsing, move to the next tag. |
| 251 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 252 |
if err != nil { |
| 253 |
return err |
| 254 |
} |
| 255 |
switch fieldNum { |
| 256 |
|
| 257 |
case 1: |
| 258 |
if wireType != proto.WireTypeI64 { |
| 259 |
return fmt.Errorf("proto: wrong wireType = %d for field TimeUnixNano", wireType) |
| 260 |
} |
| 261 |
var num uint64 |
| 262 |
num, pos, err = proto.ConsumeI64(buf, pos) |
| 263 |
if err != nil { |
| 264 |
return err |
| 265 |
} |
| 266 |
|
| 267 |
orig.TimeUnixNano = uint64(num) |
| 268 |
|
| 269 |
case 2: |
| 270 |
if wireType != proto.WireTypeLen { |
| 271 |
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) |
| 272 |
} |
| 273 |
var length int |
| 274 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 275 |
if err != nil { |
| 276 |
return err |
| 277 |
} |
| 278 |
startPos := pos - length |
| 279 |
orig.Name = string(buf[startPos:pos]) |
| 280 |
|
| 281 |
case 3: |
| 282 |
if wireType != proto.WireTypeLen { |
| 283 |
return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) |
| 284 |
} |
| 285 |
var length int |
| 286 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 287 |
if err != nil { |
| 288 |
return err |
| 289 |
} |
| 290 |
startPos := pos - length |
| 291 |
orig.Attributes = append(orig.Attributes, KeyValue{}) |
| 292 |
err = orig.Attributes[len(orig.Attributes)-1].UnmarshalProto(buf[startPos:pos]) |
| 293 |
if err != nil { |
| 294 |
return err |
| 295 |
} |
| 296 |
|
| 297 |
case 4: |
| 298 |
if wireType != proto.WireTypeVarint { |
| 299 |
return fmt.Errorf("proto: wrong wireType = %d for field DroppedAttributesCount", wireType) |
| 300 |
} |
| 301 |
var num uint64 |
| 302 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 303 |
if err != nil { |
| 304 |
return err |
| 305 |
} |
| 306 |
|
| 307 |
orig.DroppedAttributesCount = uint32(num) |
| 308 |
default: |
| 309 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 310 |
if err != nil { |
| 311 |
return err |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
return nil |
| 316 |
} |
| 317 |
|
| 318 |
func GenTestSpanEvent() *SpanEvent { |
| 319 |
orig := NewSpanEvent() |
| 320 |
orig.TimeUnixNano = uint64(13) |
| 321 |
orig.Name = "test_name" |
| 322 |
orig.Attributes = []KeyValue{{}, *GenTestKeyValue()} |
| 323 |
orig.DroppedAttributesCount = uint32(13) |
| 324 |
return orig |
| 325 |
} |
| 326 |
|
| 327 |
func GenTestSpanEventPtrSlice() []*SpanEvent { |
| 328 |
orig := make([]*SpanEvent, 5) |
| 329 |
orig[0] = NewSpanEvent() |
| 330 |
orig[1] = GenTestSpanEvent() |
| 331 |
orig[2] = NewSpanEvent() |
| 332 |
orig[3] = GenTestSpanEvent() |
| 333 |
orig[4] = NewSpanEvent() |
| 334 |
return orig |
| 335 |
} |
| 336 |
|
| 337 |
func GenTestSpanEventSlice() []SpanEvent { |
| 338 |
orig := make([]SpanEvent, 5) |
| 339 |
orig[1] = *GenTestSpanEvent() |
| 340 |
orig[3] = *GenTestSpanEvent() |
| 341 |
return orig |
| 342 |
} |