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