| 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 |
// Line details a specific line in a source code, linked to a function. |
| 18 |
type Line struct { |
| 19 |
FunctionIndex int32 |
| 20 |
Line int64 |
| 21 |
Column int64 |
| 22 |
} |
| 23 |
|
| 24 |
var ( |
| 25 |
protoPoolLine = sync.Pool{ |
| 26 |
New: func() any { |
| 27 |
return &Line{} |
| 28 |
}, |
| 29 |
} |
| 30 |
) |
| 31 |
|
| 32 |
func NewLine() *Line { |
| 33 |
if !UseProtoPooling.IsEnabled() { |
| 34 |
return &Line{} |
| 35 |
} |
| 36 |
return protoPoolLine.Get().(*Line) |
| 37 |
} |
| 38 |
|
| 39 |
func DeleteLine(orig *Line, 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 |
protoPoolLine.Put(orig) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
func CopyLine(dest, src *Line) *Line { |
| 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 = NewLine() |
| 67 |
} |
| 68 |
dest.FunctionIndex = src.FunctionIndex |
| 69 |
|
| 70 |
dest.Line = src.Line |
| 71 |
|
| 72 |
dest.Column = src.Column |
| 73 |
|
| 74 |
return dest |
| 75 |
} |
| 76 |
|
| 77 |
func CopyLineSlice(dest, src []Line) []Line { |
| 78 |
var newDest []Line |
| 79 |
if cap(dest) < len(src) { |
| 80 |
newDest = make([]Line, len(src)) |
| 81 |
} else { |
| 82 |
newDest = dest[:len(src)] |
| 83 |
// Cleanup the rest of the elements so GC can free the memory. |
| 84 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 85 |
for i := len(src); i < len(dest); i++ { |
| 86 |
DeleteLine(&dest[i], false) |
| 87 |
} |
| 88 |
} |
| 89 |
for i := range src { |
| 90 |
CopyLine(&newDest[i], &src[i]) |
| 91 |
} |
| 92 |
return newDest |
| 93 |
} |
| 94 |
|
| 95 |
func CopyLinePtrSlice(dest, src []*Line) []*Line { |
| 96 |
var newDest []*Line |
| 97 |
if cap(dest) < len(src) { |
| 98 |
newDest = make([]*Line, len(src)) |
| 99 |
// Copy old pointers to re-use. |
| 100 |
copy(newDest, dest) |
| 101 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 102 |
for i := len(dest); i < len(src); i++ { |
| 103 |
newDest[i] = NewLine() |
| 104 |
} |
| 105 |
} else { |
| 106 |
newDest = dest[:len(src)] |
| 107 |
// Cleanup the rest of the elements so GC can free the memory. |
| 108 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 109 |
for i := len(src); i < len(dest); i++ { |
| 110 |
DeleteLine(dest[i], true) |
| 111 |
dest[i] = nil |
| 112 |
} |
| 113 |
// Add new pointers for missing elements. |
| 114 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 115 |
for i := len(dest); i < len(src); i++ { |
| 116 |
newDest[i] = NewLine() |
| 117 |
} |
| 118 |
} |
| 119 |
for i := range src { |
| 120 |
CopyLine(newDest[i], src[i]) |
| 121 |
} |
| 122 |
return newDest |
| 123 |
} |
| 124 |
|
| 125 |
func (orig *Line) Reset() { |
| 126 |
*orig = Line{} |
| 127 |
} |
| 128 |
|
| 129 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 130 |
func (orig *Line) MarshalJSON(dest *json.Stream) { |
| 131 |
dest.WriteObjectStart() |
| 132 |
if orig.FunctionIndex != int32(0) { |
| 133 |
dest.WriteObjectField("functionIndex") |
| 134 |
dest.WriteInt32(orig.FunctionIndex) |
| 135 |
} |
| 136 |
if orig.Line != int64(0) { |
| 137 |
dest.WriteObjectField("line") |
| 138 |
dest.WriteInt64(orig.Line) |
| 139 |
} |
| 140 |
if orig.Column != int64(0) { |
| 141 |
dest.WriteObjectField("column") |
| 142 |
dest.WriteInt64(orig.Column) |
| 143 |
} |
| 144 |
dest.WriteObjectEnd() |
| 145 |
} |
| 146 |
|
| 147 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 148 |
func (orig *Line) UnmarshalJSON(iter *json.Iterator) { |
| 149 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 150 |
switch f { |
| 151 |
case "functionIndex", "function_index": |
| 152 |
orig.FunctionIndex = iter.ReadInt32() |
| 153 |
case "line": |
| 154 |
orig.Line = iter.ReadInt64() |
| 155 |
case "column": |
| 156 |
orig.Column = iter.ReadInt64() |
| 157 |
default: |
| 158 |
iter.Skip() |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
func (orig *Line) SizeProto() int { |
| 164 |
var n int |
| 165 |
var l int |
| 166 |
_ = l |
| 167 |
if orig.FunctionIndex != 0 { |
| 168 |
n += 1 + proto.Sov(uint64(orig.FunctionIndex)) |
| 169 |
} |
| 170 |
if orig.Line != 0 { |
| 171 |
n += 1 + proto.Sov(uint64(orig.Line)) |
| 172 |
} |
| 173 |
if orig.Column != 0 { |
| 174 |
n += 1 + proto.Sov(uint64(orig.Column)) |
| 175 |
} |
| 176 |
return n |
| 177 |
} |
| 178 |
|
| 179 |
func (orig *Line) MarshalProto(buf []byte) int { |
| 180 |
pos := len(buf) |
| 181 |
var l int |
| 182 |
_ = l |
| 183 |
if orig.FunctionIndex != 0 { |
| 184 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.FunctionIndex)) |
| 185 |
pos-- |
| 186 |
buf[pos] = 0x8 |
| 187 |
} |
| 188 |
if orig.Line != 0 { |
| 189 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.Line)) |
| 190 |
pos-- |
| 191 |
buf[pos] = 0x10 |
| 192 |
} |
| 193 |
if orig.Column != 0 { |
| 194 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.Column)) |
| 195 |
pos-- |
| 196 |
buf[pos] = 0x18 |
| 197 |
} |
| 198 |
return len(buf) - pos |
| 199 |
} |
| 200 |
|
| 201 |
func (orig *Line) UnmarshalProto(buf []byte) error { |
| 202 |
var err error |
| 203 |
var fieldNum int32 |
| 204 |
var wireType proto.WireType |
| 205 |
|
| 206 |
l := len(buf) |
| 207 |
pos := 0 |
| 208 |
for pos < l { |
| 209 |
// If in a group parsing, move to the next tag. |
| 210 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 211 |
if err != nil { |
| 212 |
return err |
| 213 |
} |
| 214 |
switch fieldNum { |
| 215 |
|
| 216 |
case 1: |
| 217 |
if wireType != proto.WireTypeVarint { |
| 218 |
return fmt.Errorf("proto: wrong wireType = %d for field FunctionIndex", wireType) |
| 219 |
} |
| 220 |
var num uint64 |
| 221 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 222 |
if err != nil { |
| 223 |
return err |
| 224 |
} |
| 225 |
|
| 226 |
orig.FunctionIndex = int32(num) |
| 227 |
|
| 228 |
case 2: |
| 229 |
if wireType != proto.WireTypeVarint { |
| 230 |
return fmt.Errorf("proto: wrong wireType = %d for field Line", wireType) |
| 231 |
} |
| 232 |
var num uint64 |
| 233 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 234 |
if err != nil { |
| 235 |
return err |
| 236 |
} |
| 237 |
|
| 238 |
orig.Line = int64(num) |
| 239 |
|
| 240 |
case 3: |
| 241 |
if wireType != proto.WireTypeVarint { |
| 242 |
return fmt.Errorf("proto: wrong wireType = %d for field Column", wireType) |
| 243 |
} |
| 244 |
var num uint64 |
| 245 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 246 |
if err != nil { |
| 247 |
return err |
| 248 |
} |
| 249 |
|
| 250 |
orig.Column = int64(num) |
| 251 |
default: |
| 252 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 253 |
if err != nil { |
| 254 |
return err |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
return nil |
| 259 |
} |
| 260 |
|
| 261 |
func GenTestLine() *Line { |
| 262 |
orig := NewLine() |
| 263 |
orig.FunctionIndex = int32(13) |
| 264 |
orig.Line = int64(13) |
| 265 |
orig.Column = int64(13) |
| 266 |
return orig |
| 267 |
} |
| 268 |
|
| 269 |
func GenTestLinePtrSlice() []*Line { |
| 270 |
orig := make([]*Line, 5) |
| 271 |
orig[0] = NewLine() |
| 272 |
orig[1] = GenTestLine() |
| 273 |
orig[2] = NewLine() |
| 274 |
orig[3] = GenTestLine() |
| 275 |
orig[4] = NewLine() |
| 276 |
return orig |
| 277 |
} |
| 278 |
|
| 279 |
func GenTestLineSlice() []Line { |
| 280 |
orig := make([]Line, 5) |
| 281 |
orig[1] = *GenTestLine() |
| 282 |
orig[3] = *GenTestLine() |
| 283 |
return orig |
| 284 |
} |