| 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 |
"math" |
| 13 |
"sync" |
| 14 |
|
| 15 |
"go.opentelemetry.io/collector/pdata/internal/json" |
| 16 |
"go.opentelemetry.io/collector/pdata/internal/proto" |
| 17 |
) |
| 18 |
|
| 19 |
func (m *AnyValue) GetValue() any { |
| 20 |
if m != nil { |
| 21 |
return m.Value |
| 22 |
} |
| 23 |
return nil |
| 24 |
} |
| 25 |
|
| 26 |
type AnyValue_StringValue struct { |
| 27 |
StringValue string |
| 28 |
} |
| 29 |
|
| 30 |
func (m *AnyValue) GetStringValue() string { |
| 31 |
if v, ok := m.GetValue().(*AnyValue_StringValue); ok { |
| 32 |
return v.StringValue |
| 33 |
} |
| 34 |
return "" |
| 35 |
} |
| 36 |
|
| 37 |
type AnyValue_BoolValue struct { |
| 38 |
BoolValue bool |
| 39 |
} |
| 40 |
|
| 41 |
func (m *AnyValue) GetBoolValue() bool { |
| 42 |
if v, ok := m.GetValue().(*AnyValue_BoolValue); ok { |
| 43 |
return v.BoolValue |
| 44 |
} |
| 45 |
return false |
| 46 |
} |
| 47 |
|
| 48 |
type AnyValue_IntValue struct { |
| 49 |
IntValue int64 |
| 50 |
} |
| 51 |
|
| 52 |
func (m *AnyValue) GetIntValue() int64 { |
| 53 |
if v, ok := m.GetValue().(*AnyValue_IntValue); ok { |
| 54 |
return v.IntValue |
| 55 |
} |
| 56 |
return int64(0) |
| 57 |
} |
| 58 |
|
| 59 |
type AnyValue_DoubleValue struct { |
| 60 |
DoubleValue float64 |
| 61 |
} |
| 62 |
|
| 63 |
func (m *AnyValue) GetDoubleValue() float64 { |
| 64 |
if v, ok := m.GetValue().(*AnyValue_DoubleValue); ok { |
| 65 |
return v.DoubleValue |
| 66 |
} |
| 67 |
return float64(0) |
| 68 |
} |
| 69 |
|
| 70 |
type AnyValue_ArrayValue struct { |
| 71 |
ArrayValue *ArrayValue |
| 72 |
} |
| 73 |
|
| 74 |
func (m *AnyValue) GetArrayValue() *ArrayValue { |
| 75 |
if v, ok := m.GetValue().(*AnyValue_ArrayValue); ok { |
| 76 |
return v.ArrayValue |
| 77 |
} |
| 78 |
return nil |
| 79 |
} |
| 80 |
|
| 81 |
type AnyValue_KvlistValue struct { |
| 82 |
KvlistValue *KeyValueList |
| 83 |
} |
| 84 |
|
| 85 |
func (m *AnyValue) GetKvlistValue() *KeyValueList { |
| 86 |
if v, ok := m.GetValue().(*AnyValue_KvlistValue); ok { |
| 87 |
return v.KvlistValue |
| 88 |
} |
| 89 |
return nil |
| 90 |
} |
| 91 |
|
| 92 |
type AnyValue_BytesValue struct { |
| 93 |
BytesValue []byte |
| 94 |
} |
| 95 |
|
| 96 |
func (m *AnyValue) GetBytesValue() []byte { |
| 97 |
if v, ok := m.GetValue().(*AnyValue_BytesValue); ok { |
| 98 |
return v.BytesValue |
| 99 |
} |
| 100 |
return nil |
| 101 |
} |
| 102 |
|
| 103 |
type AnyValue struct { |
| 104 |
Value any |
| 105 |
} |
| 106 |
|
| 107 |
var ( |
| 108 |
protoPoolAnyValue = sync.Pool{ |
| 109 |
New: func() any { |
| 110 |
return &AnyValue{} |
| 111 |
}, |
| 112 |
} |
| 113 |
|
| 114 |
ProtoPoolAnyValue_StringValue = sync.Pool{ |
| 115 |
New: func() any { |
| 116 |
return &AnyValue_StringValue{} |
| 117 |
}, |
| 118 |
} |
| 119 |
|
| 120 |
ProtoPoolAnyValue_BoolValue = sync.Pool{ |
| 121 |
New: func() any { |
| 122 |
return &AnyValue_BoolValue{} |
| 123 |
}, |
| 124 |
} |
| 125 |
|
| 126 |
ProtoPoolAnyValue_IntValue = sync.Pool{ |
| 127 |
New: func() any { |
| 128 |
return &AnyValue_IntValue{} |
| 129 |
}, |
| 130 |
} |
| 131 |
|
| 132 |
ProtoPoolAnyValue_DoubleValue = sync.Pool{ |
| 133 |
New: func() any { |
| 134 |
return &AnyValue_DoubleValue{} |
| 135 |
}, |
| 136 |
} |
| 137 |
|
| 138 |
ProtoPoolAnyValue_ArrayValue = sync.Pool{ |
| 139 |
New: func() any { |
| 140 |
return &AnyValue_ArrayValue{} |
| 141 |
}, |
| 142 |
} |
| 143 |
|
| 144 |
ProtoPoolAnyValue_KvlistValue = sync.Pool{ |
| 145 |
New: func() any { |
| 146 |
return &AnyValue_KvlistValue{} |
| 147 |
}, |
| 148 |
} |
| 149 |
|
| 150 |
ProtoPoolAnyValue_BytesValue = sync.Pool{ |
| 151 |
New: func() any { |
| 152 |
return &AnyValue_BytesValue{} |
| 153 |
}, |
| 154 |
} |
| 155 |
) |
| 156 |
|
| 157 |
func NewAnyValue() *AnyValue { |
| 158 |
if !UseProtoPooling.IsEnabled() { |
| 159 |
return &AnyValue{} |
| 160 |
} |
| 161 |
return protoPoolAnyValue.Get().(*AnyValue) |
| 162 |
} |
| 163 |
|
| 164 |
func DeleteAnyValue(orig *AnyValue, nullable bool) { |
| 165 |
if orig == nil { |
| 166 |
return |
| 167 |
} |
| 168 |
|
| 169 |
if !UseProtoPooling.IsEnabled() { |
| 170 |
orig.Reset() |
| 171 |
return |
| 172 |
} |
| 173 |
|
| 174 |
switch ov := orig.Value.(type) { |
| 175 |
case *AnyValue_StringValue: |
| 176 |
if UseProtoPooling.IsEnabled() { |
| 177 |
ov.StringValue = "" |
| 178 |
ProtoPoolAnyValue_StringValue.Put(ov) |
| 179 |
} |
| 180 |
case *AnyValue_BoolValue: |
| 181 |
if UseProtoPooling.IsEnabled() { |
| 182 |
ov.BoolValue = false |
| 183 |
ProtoPoolAnyValue_BoolValue.Put(ov) |
| 184 |
} |
| 185 |
case *AnyValue_IntValue: |
| 186 |
if UseProtoPooling.IsEnabled() { |
| 187 |
ov.IntValue = int64(0) |
| 188 |
ProtoPoolAnyValue_IntValue.Put(ov) |
| 189 |
} |
| 190 |
case *AnyValue_DoubleValue: |
| 191 |
if UseProtoPooling.IsEnabled() { |
| 192 |
ov.DoubleValue = float64(0) |
| 193 |
ProtoPoolAnyValue_DoubleValue.Put(ov) |
| 194 |
} |
| 195 |
case *AnyValue_ArrayValue: |
| 196 |
DeleteArrayValue(ov.ArrayValue, true) |
| 197 |
ov.ArrayValue = nil |
| 198 |
ProtoPoolAnyValue_ArrayValue.Put(ov) |
| 199 |
case *AnyValue_KvlistValue: |
| 200 |
DeleteKeyValueList(ov.KvlistValue, true) |
| 201 |
ov.KvlistValue = nil |
| 202 |
ProtoPoolAnyValue_KvlistValue.Put(ov) |
| 203 |
case *AnyValue_BytesValue: |
| 204 |
if UseProtoPooling.IsEnabled() { |
| 205 |
ov.BytesValue = nil |
| 206 |
ProtoPoolAnyValue_BytesValue.Put(ov) |
| 207 |
} |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
orig.Reset() |
| 212 |
if nullable { |
| 213 |
protoPoolAnyValue.Put(orig) |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
func CopyAnyValue(dest, src *AnyValue) *AnyValue { |
| 218 |
// If copying to same object, just return. |
| 219 |
if src == dest { |
| 220 |
return dest |
| 221 |
} |
| 222 |
|
| 223 |
if src == nil { |
| 224 |
return nil |
| 225 |
} |
| 226 |
|
| 227 |
if dest == nil { |
| 228 |
dest = NewAnyValue() |
| 229 |
} |
| 230 |
switch t := src.Value.(type) { |
| 231 |
case *AnyValue_StringValue: |
| 232 |
var ov *AnyValue_StringValue |
| 233 |
if !UseProtoPooling.IsEnabled() { |
| 234 |
ov = &AnyValue_StringValue{} |
| 235 |
} else { |
| 236 |
ov = ProtoPoolAnyValue_StringValue.Get().(*AnyValue_StringValue) |
| 237 |
} |
| 238 |
ov.StringValue = t.StringValue |
| 239 |
dest.Value = ov |
| 240 |
case *AnyValue_BoolValue: |
| 241 |
var ov *AnyValue_BoolValue |
| 242 |
if !UseProtoPooling.IsEnabled() { |
| 243 |
ov = &AnyValue_BoolValue{} |
| 244 |
} else { |
| 245 |
ov = ProtoPoolAnyValue_BoolValue.Get().(*AnyValue_BoolValue) |
| 246 |
} |
| 247 |
ov.BoolValue = t.BoolValue |
| 248 |
dest.Value = ov |
| 249 |
case *AnyValue_IntValue: |
| 250 |
var ov *AnyValue_IntValue |
| 251 |
if !UseProtoPooling.IsEnabled() { |
| 252 |
ov = &AnyValue_IntValue{} |
| 253 |
} else { |
| 254 |
ov = ProtoPoolAnyValue_IntValue.Get().(*AnyValue_IntValue) |
| 255 |
} |
| 256 |
ov.IntValue = t.IntValue |
| 257 |
dest.Value = ov |
| 258 |
case *AnyValue_DoubleValue: |
| 259 |
var ov *AnyValue_DoubleValue |
| 260 |
if !UseProtoPooling.IsEnabled() { |
| 261 |
ov = &AnyValue_DoubleValue{} |
| 262 |
} else { |
| 263 |
ov = ProtoPoolAnyValue_DoubleValue.Get().(*AnyValue_DoubleValue) |
| 264 |
} |
| 265 |
ov.DoubleValue = t.DoubleValue |
| 266 |
dest.Value = ov |
| 267 |
case *AnyValue_ArrayValue: |
| 268 |
var ov *AnyValue_ArrayValue |
| 269 |
if !UseProtoPooling.IsEnabled() { |
| 270 |
ov = &AnyValue_ArrayValue{} |
| 271 |
} else { |
| 272 |
ov = ProtoPoolAnyValue_ArrayValue.Get().(*AnyValue_ArrayValue) |
| 273 |
} |
| 274 |
ov.ArrayValue = NewArrayValue() |
| 275 |
CopyArrayValue(ov.ArrayValue, t.ArrayValue) |
| 276 |
dest.Value = ov |
| 277 |
|
| 278 |
case *AnyValue_KvlistValue: |
| 279 |
var ov *AnyValue_KvlistValue |
| 280 |
if !UseProtoPooling.IsEnabled() { |
| 281 |
ov = &AnyValue_KvlistValue{} |
| 282 |
} else { |
| 283 |
ov = ProtoPoolAnyValue_KvlistValue.Get().(*AnyValue_KvlistValue) |
| 284 |
} |
| 285 |
ov.KvlistValue = NewKeyValueList() |
| 286 |
CopyKeyValueList(ov.KvlistValue, t.KvlistValue) |
| 287 |
dest.Value = ov |
| 288 |
|
| 289 |
case *AnyValue_BytesValue: |
| 290 |
var ov *AnyValue_BytesValue |
| 291 |
if !UseProtoPooling.IsEnabled() { |
| 292 |
ov = &AnyValue_BytesValue{} |
| 293 |
} else { |
| 294 |
ov = ProtoPoolAnyValue_BytesValue.Get().(*AnyValue_BytesValue) |
| 295 |
} |
| 296 |
ov.BytesValue = t.BytesValue |
| 297 |
dest.Value = ov |
| 298 |
default: |
| 299 |
dest.Value = nil |
| 300 |
} |
| 301 |
|
| 302 |
return dest |
| 303 |
} |
| 304 |
|
| 305 |
func CopyAnyValueSlice(dest, src []AnyValue) []AnyValue { |
| 306 |
var newDest []AnyValue |
| 307 |
if cap(dest) < len(src) { |
| 308 |
newDest = make([]AnyValue, len(src)) |
| 309 |
} else { |
| 310 |
newDest = dest[:len(src)] |
| 311 |
// Cleanup the rest of the elements so GC can free the memory. |
| 312 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 313 |
for i := len(src); i < len(dest); i++ { |
| 314 |
DeleteAnyValue(&dest[i], false) |
| 315 |
} |
| 316 |
} |
| 317 |
for i := range src { |
| 318 |
CopyAnyValue(&newDest[i], &src[i]) |
| 319 |
} |
| 320 |
return newDest |
| 321 |
} |
| 322 |
|
| 323 |
func CopyAnyValuePtrSlice(dest, src []*AnyValue) []*AnyValue { |
| 324 |
var newDest []*AnyValue |
| 325 |
if cap(dest) < len(src) { |
| 326 |
newDest = make([]*AnyValue, len(src)) |
| 327 |
// Copy old pointers to re-use. |
| 328 |
copy(newDest, dest) |
| 329 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 330 |
for i := len(dest); i < len(src); i++ { |
| 331 |
newDest[i] = NewAnyValue() |
| 332 |
} |
| 333 |
} else { |
| 334 |
newDest = dest[:len(src)] |
| 335 |
// Cleanup the rest of the elements so GC can free the memory. |
| 336 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 337 |
for i := len(src); i < len(dest); i++ { |
| 338 |
DeleteAnyValue(dest[i], true) |
| 339 |
dest[i] = nil |
| 340 |
} |
| 341 |
// Add new pointers for missing elements. |
| 342 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 343 |
for i := len(dest); i < len(src); i++ { |
| 344 |
newDest[i] = NewAnyValue() |
| 345 |
} |
| 346 |
} |
| 347 |
for i := range src { |
| 348 |
CopyAnyValue(newDest[i], src[i]) |
| 349 |
} |
| 350 |
return newDest |
| 351 |
} |
| 352 |
|
| 353 |
func (orig *AnyValue) Reset() { |
| 354 |
*orig = AnyValue{} |
| 355 |
} |
| 356 |
|
| 357 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 358 |
func (orig *AnyValue) MarshalJSON(dest *json.Stream) { |
| 359 |
dest.WriteObjectStart() |
| 360 |
switch orig := orig.Value.(type) { |
| 361 |
case *AnyValue_StringValue: |
| 362 |
dest.WriteObjectField("stringValue") |
| 363 |
dest.WriteString(orig.StringValue) |
| 364 |
case *AnyValue_BoolValue: |
| 365 |
dest.WriteObjectField("boolValue") |
| 366 |
dest.WriteBool(orig.BoolValue) |
| 367 |
case *AnyValue_IntValue: |
| 368 |
dest.WriteObjectField("intValue") |
| 369 |
dest.WriteInt64(orig.IntValue) |
| 370 |
case *AnyValue_DoubleValue: |
| 371 |
dest.WriteObjectField("doubleValue") |
| 372 |
dest.WriteFloat64(orig.DoubleValue) |
| 373 |
case *AnyValue_ArrayValue: |
| 374 |
if orig.ArrayValue != nil { |
| 375 |
dest.WriteObjectField("arrayValue") |
| 376 |
orig.ArrayValue.MarshalJSON(dest) |
| 377 |
} |
| 378 |
case *AnyValue_KvlistValue: |
| 379 |
if orig.KvlistValue != nil { |
| 380 |
dest.WriteObjectField("kvlistValue") |
| 381 |
orig.KvlistValue.MarshalJSON(dest) |
| 382 |
} |
| 383 |
case *AnyValue_BytesValue: |
| 384 |
|
| 385 |
dest.WriteObjectField("bytesValue") |
| 386 |
dest.WriteBytes(orig.BytesValue) |
| 387 |
} |
| 388 |
dest.WriteObjectEnd() |
| 389 |
} |
| 390 |
|
| 391 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 392 |
func (orig *AnyValue) UnmarshalJSON(iter *json.Iterator) { |
| 393 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 394 |
switch f { |
| 395 |
|
| 396 |
case "stringValue", "string_value": |
| 397 |
{ |
| 398 |
var ov *AnyValue_StringValue |
| 399 |
if !UseProtoPooling.IsEnabled() { |
| 400 |
ov = &AnyValue_StringValue{} |
| 401 |
} else { |
| 402 |
ov = ProtoPoolAnyValue_StringValue.Get().(*AnyValue_StringValue) |
| 403 |
} |
| 404 |
ov.StringValue = iter.ReadString() |
| 405 |
orig.Value = ov |
| 406 |
} |
| 407 |
|
| 408 |
case "boolValue", "bool_value": |
| 409 |
{ |
| 410 |
var ov *AnyValue_BoolValue |
| 411 |
if !UseProtoPooling.IsEnabled() { |
| 412 |
ov = &AnyValue_BoolValue{} |
| 413 |
} else { |
| 414 |
ov = ProtoPoolAnyValue_BoolValue.Get().(*AnyValue_BoolValue) |
| 415 |
} |
| 416 |
ov.BoolValue = iter.ReadBool() |
| 417 |
orig.Value = ov |
| 418 |
} |
| 419 |
|
| 420 |
case "intValue", "int_value": |
| 421 |
{ |
| 422 |
var ov *AnyValue_IntValue |
| 423 |
if !UseProtoPooling.IsEnabled() { |
| 424 |
ov = &AnyValue_IntValue{} |
| 425 |
} else { |
| 426 |
ov = ProtoPoolAnyValue_IntValue.Get().(*AnyValue_IntValue) |
| 427 |
} |
| 428 |
ov.IntValue = iter.ReadInt64() |
| 429 |
orig.Value = ov |
| 430 |
} |
| 431 |
|
| 432 |
case "doubleValue", "double_value": |
| 433 |
{ |
| 434 |
var ov *AnyValue_DoubleValue |
| 435 |
if !UseProtoPooling.IsEnabled() { |
| 436 |
ov = &AnyValue_DoubleValue{} |
| 437 |
} else { |
| 438 |
ov = ProtoPoolAnyValue_DoubleValue.Get().(*AnyValue_DoubleValue) |
| 439 |
} |
| 440 |
ov.DoubleValue = iter.ReadFloat64() |
| 441 |
orig.Value = ov |
| 442 |
} |
| 443 |
|
| 444 |
case "arrayValue", "array_value": |
| 445 |
{ |
| 446 |
var ov *AnyValue_ArrayValue |
| 447 |
if !UseProtoPooling.IsEnabled() { |
| 448 |
ov = &AnyValue_ArrayValue{} |
| 449 |
} else { |
| 450 |
ov = ProtoPoolAnyValue_ArrayValue.Get().(*AnyValue_ArrayValue) |
| 451 |
} |
| 452 |
ov.ArrayValue = NewArrayValue() |
| 453 |
ov.ArrayValue.UnmarshalJSON(iter) |
| 454 |
orig.Value = ov |
| 455 |
} |
| 456 |
|
| 457 |
case "kvlistValue", "kvlist_value": |
| 458 |
{ |
| 459 |
var ov *AnyValue_KvlistValue |
| 460 |
if !UseProtoPooling.IsEnabled() { |
| 461 |
ov = &AnyValue_KvlistValue{} |
| 462 |
} else { |
| 463 |
ov = ProtoPoolAnyValue_KvlistValue.Get().(*AnyValue_KvlistValue) |
| 464 |
} |
| 465 |
ov.KvlistValue = NewKeyValueList() |
| 466 |
ov.KvlistValue.UnmarshalJSON(iter) |
| 467 |
orig.Value = ov |
| 468 |
} |
| 469 |
|
| 470 |
case "bytesValue", "bytes_value": |
| 471 |
{ |
| 472 |
var ov *AnyValue_BytesValue |
| 473 |
if !UseProtoPooling.IsEnabled() { |
| 474 |
ov = &AnyValue_BytesValue{} |
| 475 |
} else { |
| 476 |
ov = ProtoPoolAnyValue_BytesValue.Get().(*AnyValue_BytesValue) |
| 477 |
} |
| 478 |
ov.BytesValue = iter.ReadBytes() |
| 479 |
orig.Value = ov |
| 480 |
} |
| 481 |
|
| 482 |
default: |
| 483 |
iter.Skip() |
| 484 |
} |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
func (orig *AnyValue) SizeProto() int { |
| 489 |
var n int |
| 490 |
var l int |
| 491 |
_ = l |
| 492 |
switch orig := orig.Value.(type) { |
| 493 |
case nil: |
| 494 |
_ = orig |
| 495 |
break |
| 496 |
case *AnyValue_StringValue: |
| 497 |
l = len(orig.StringValue) |
| 498 |
n += 1 + proto.Sov(uint64(l)) + l |
| 499 |
case *AnyValue_BoolValue: |
| 500 |
n += 2 |
| 501 |
case *AnyValue_IntValue: |
| 502 |
n += 1 + proto.Sov(uint64(orig.IntValue)) |
| 503 |
case *AnyValue_DoubleValue: |
| 504 |
n += 9 |
| 505 |
case *AnyValue_ArrayValue: |
| 506 |
if orig.ArrayValue != nil { |
| 507 |
l = orig.ArrayValue.SizeProto() |
| 508 |
n += 1 + proto.Sov(uint64(l)) + l |
| 509 |
} |
| 510 |
case *AnyValue_KvlistValue: |
| 511 |
if orig.KvlistValue != nil { |
| 512 |
l = orig.KvlistValue.SizeProto() |
| 513 |
n += 1 + proto.Sov(uint64(l)) + l |
| 514 |
} |
| 515 |
case *AnyValue_BytesValue: |
| 516 |
l = len(orig.BytesValue) |
| 517 |
n += 1 + proto.Sov(uint64(l)) + l |
| 518 |
} |
| 519 |
return n |
| 520 |
} |
| 521 |
|
| 522 |
func (orig *AnyValue) MarshalProto(buf []byte) int { |
| 523 |
pos := len(buf) |
| 524 |
var l int |
| 525 |
_ = l |
| 526 |
switch orig := orig.Value.(type) { |
| 527 |
case *AnyValue_StringValue: |
| 528 |
l = len(orig.StringValue) |
| 529 |
pos -= l |
| 530 |
copy(buf[pos:], orig.StringValue) |
| 531 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 532 |
pos-- |
| 533 |
buf[pos] = 0xa |
| 534 |
|
| 535 |
case *AnyValue_BoolValue: |
| 536 |
pos-- |
| 537 |
if orig.BoolValue { |
| 538 |
buf[pos] = 1 |
| 539 |
} else { |
| 540 |
buf[pos] = 0 |
| 541 |
} |
| 542 |
pos-- |
| 543 |
buf[pos] = 0x10 |
| 544 |
|
| 545 |
case *AnyValue_IntValue: |
| 546 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.IntValue)) |
| 547 |
pos-- |
| 548 |
buf[pos] = 0x18 |
| 549 |
|
| 550 |
case *AnyValue_DoubleValue: |
| 551 |
pos -= 8 |
| 552 |
binary.LittleEndian.PutUint64(buf[pos:], math.Float64bits(orig.DoubleValue)) |
| 553 |
pos-- |
| 554 |
buf[pos] = 0x21 |
| 555 |
|
| 556 |
case *AnyValue_ArrayValue: |
| 557 |
if orig.ArrayValue != nil { |
| 558 |
l = orig.ArrayValue.MarshalProto(buf[:pos]) |
| 559 |
pos -= l |
| 560 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 561 |
pos-- |
| 562 |
buf[pos] = 0x2a |
| 563 |
} |
| 564 |
case *AnyValue_KvlistValue: |
| 565 |
if orig.KvlistValue != nil { |
| 566 |
l = orig.KvlistValue.MarshalProto(buf[:pos]) |
| 567 |
pos -= l |
| 568 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 569 |
pos-- |
| 570 |
buf[pos] = 0x32 |
| 571 |
} |
| 572 |
case *AnyValue_BytesValue: |
| 573 |
l = len(orig.BytesValue) |
| 574 |
pos -= l |
| 575 |
copy(buf[pos:], orig.BytesValue) |
| 576 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 577 |
pos-- |
| 578 |
buf[pos] = 0x3a |
| 579 |
|
| 580 |
} |
| 581 |
return len(buf) - pos |
| 582 |
} |
| 583 |
|
| 584 |
func (orig *AnyValue) UnmarshalProto(buf []byte) error { |
| 585 |
var err error |
| 586 |
var fieldNum int32 |
| 587 |
var wireType proto.WireType |
| 588 |
|
| 589 |
l := len(buf) |
| 590 |
pos := 0 |
| 591 |
for pos < l { |
| 592 |
// If in a group parsing, move to the next tag. |
| 593 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 594 |
if err != nil { |
| 595 |
return err |
| 596 |
} |
| 597 |
switch fieldNum { |
| 598 |
|
| 599 |
case 1: |
| 600 |
if wireType != proto.WireTypeLen { |
| 601 |
return fmt.Errorf("proto: wrong wireType = %d for field StringValue", wireType) |
| 602 |
} |
| 603 |
var length int |
| 604 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 605 |
if err != nil { |
| 606 |
return err |
| 607 |
} |
| 608 |
startPos := pos - length |
| 609 |
var ov *AnyValue_StringValue |
| 610 |
if !UseProtoPooling.IsEnabled() { |
| 611 |
ov = &AnyValue_StringValue{} |
| 612 |
} else { |
| 613 |
ov = ProtoPoolAnyValue_StringValue.Get().(*AnyValue_StringValue) |
| 614 |
} |
| 615 |
ov.StringValue = string(buf[startPos:pos]) |
| 616 |
orig.Value = ov |
| 617 |
|
| 618 |
case 2: |
| 619 |
if wireType != proto.WireTypeVarint { |
| 620 |
return fmt.Errorf("proto: wrong wireType = %d for field BoolValue", wireType) |
| 621 |
} |
| 622 |
var num uint64 |
| 623 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 624 |
if err != nil { |
| 625 |
return err |
| 626 |
} |
| 627 |
var ov *AnyValue_BoolValue |
| 628 |
if !UseProtoPooling.IsEnabled() { |
| 629 |
ov = &AnyValue_BoolValue{} |
| 630 |
} else { |
| 631 |
ov = ProtoPoolAnyValue_BoolValue.Get().(*AnyValue_BoolValue) |
| 632 |
} |
| 633 |
ov.BoolValue = num != 0 |
| 634 |
orig.Value = ov |
| 635 |
|
| 636 |
case 3: |
| 637 |
if wireType != proto.WireTypeVarint { |
| 638 |
return fmt.Errorf("proto: wrong wireType = %d for field IntValue", wireType) |
| 639 |
} |
| 640 |
var num uint64 |
| 641 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 642 |
if err != nil { |
| 643 |
return err |
| 644 |
} |
| 645 |
var ov *AnyValue_IntValue |
| 646 |
if !UseProtoPooling.IsEnabled() { |
| 647 |
ov = &AnyValue_IntValue{} |
| 648 |
} else { |
| 649 |
ov = ProtoPoolAnyValue_IntValue.Get().(*AnyValue_IntValue) |
| 650 |
} |
| 651 |
ov.IntValue = int64(num) |
| 652 |
orig.Value = ov |
| 653 |
|
| 654 |
case 4: |
| 655 |
if wireType != proto.WireTypeI64 { |
| 656 |
return fmt.Errorf("proto: wrong wireType = %d for field DoubleValue", wireType) |
| 657 |
} |
| 658 |
var num uint64 |
| 659 |
num, pos, err = proto.ConsumeI64(buf, pos) |
| 660 |
if err != nil { |
| 661 |
return err |
| 662 |
} |
| 663 |
var ov *AnyValue_DoubleValue |
| 664 |
if !UseProtoPooling.IsEnabled() { |
| 665 |
ov = &AnyValue_DoubleValue{} |
| 666 |
} else { |
| 667 |
ov = ProtoPoolAnyValue_DoubleValue.Get().(*AnyValue_DoubleValue) |
| 668 |
} |
| 669 |
ov.DoubleValue = math.Float64frombits(num) |
| 670 |
orig.Value = ov |
| 671 |
|
| 672 |
case 5: |
| 673 |
if wireType != proto.WireTypeLen { |
| 674 |
return fmt.Errorf("proto: wrong wireType = %d for field ArrayValue", wireType) |
| 675 |
} |
| 676 |
var length int |
| 677 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 678 |
if err != nil { |
| 679 |
return err |
| 680 |
} |
| 681 |
startPos := pos - length |
| 682 |
var ov *AnyValue_ArrayValue |
| 683 |
if !UseProtoPooling.IsEnabled() { |
| 684 |
ov = &AnyValue_ArrayValue{} |
| 685 |
} else { |
| 686 |
ov = ProtoPoolAnyValue_ArrayValue.Get().(*AnyValue_ArrayValue) |
| 687 |
} |
| 688 |
ov.ArrayValue = NewArrayValue() |
| 689 |
err = ov.ArrayValue.UnmarshalProto(buf[startPos:pos]) |
| 690 |
if err != nil { |
| 691 |
return err |
| 692 |
} |
| 693 |
orig.Value = ov |
| 694 |
|
| 695 |
case 6: |
| 696 |
if wireType != proto.WireTypeLen { |
| 697 |
return fmt.Errorf("proto: wrong wireType = %d for field KvlistValue", wireType) |
| 698 |
} |
| 699 |
var length int |
| 700 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 701 |
if err != nil { |
| 702 |
return err |
| 703 |
} |
| 704 |
startPos := pos - length |
| 705 |
var ov *AnyValue_KvlistValue |
| 706 |
if !UseProtoPooling.IsEnabled() { |
| 707 |
ov = &AnyValue_KvlistValue{} |
| 708 |
} else { |
| 709 |
ov = ProtoPoolAnyValue_KvlistValue.Get().(*AnyValue_KvlistValue) |
| 710 |
} |
| 711 |
ov.KvlistValue = NewKeyValueList() |
| 712 |
err = ov.KvlistValue.UnmarshalProto(buf[startPos:pos]) |
| 713 |
if err != nil { |
| 714 |
return err |
| 715 |
} |
| 716 |
orig.Value = ov |
| 717 |
|
| 718 |
case 7: |
| 719 |
if wireType != proto.WireTypeLen { |
| 720 |
return fmt.Errorf("proto: wrong wireType = %d for field BytesValue", wireType) |
| 721 |
} |
| 722 |
var length int |
| 723 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 724 |
if err != nil { |
| 725 |
return err |
| 726 |
} |
| 727 |
startPos := pos - length |
| 728 |
var ov *AnyValue_BytesValue |
| 729 |
if !UseProtoPooling.IsEnabled() { |
| 730 |
ov = &AnyValue_BytesValue{} |
| 731 |
} else { |
| 732 |
ov = ProtoPoolAnyValue_BytesValue.Get().(*AnyValue_BytesValue) |
| 733 |
} |
| 734 |
if length != 0 { |
| 735 |
ov.BytesValue = make([]byte, length) |
| 736 |
copy(ov.BytesValue, buf[startPos:pos]) |
| 737 |
} |
| 738 |
orig.Value = ov |
| 739 |
default: |
| 740 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 741 |
if err != nil { |
| 742 |
return err |
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
return nil |
| 747 |
} |
| 748 |
|
| 749 |
func GenTestAnyValue() *AnyValue { |
| 750 |
orig := NewAnyValue() |
| 751 |
orig.Value = &AnyValue_StringValue{StringValue: "test_stringvalue"} |
| 752 |
return orig |
| 753 |
} |
| 754 |
|
| 755 |
func GenTestAnyValuePtrSlice() []*AnyValue { |
| 756 |
orig := make([]*AnyValue, 5) |
| 757 |
orig[0] = NewAnyValue() |
| 758 |
orig[1] = GenTestAnyValue() |
| 759 |
orig[2] = NewAnyValue() |
| 760 |
orig[3] = GenTestAnyValue() |
| 761 |
orig[4] = NewAnyValue() |
| 762 |
return orig |
| 763 |
} |
| 764 |
|
| 765 |
func GenTestAnyValueSlice() []AnyValue { |
| 766 |
orig := make([]AnyValue, 5) |
| 767 |
orig[1] = *GenTestAnyValue() |
| 768 |
orig[3] = *GenTestAnyValue() |
| 769 |
return orig |
| 770 |
} |