MCPcopy Create free account
hub / github.com/apache/fory / readNumericValueByTypeID

Function readNumericValueByTypeID

go/fory/union.go:497–586  ·  view source on GitHub ↗
(ctx *ReadContext, targetType reflect.Type, typeID TypeId)

Source from the content-addressed store, hash-verified

495}
496
497func readNumericValueByTypeID(ctx *ReadContext, targetType reflect.Type, typeID TypeId) (reflect.Value, bool) {
498 buf := ctx.Buffer()
499 base := targetType
500 isPtr := false
501 if base.Kind() == reflect.Ptr {
502 isPtr = true
503 base = base.Elem()
504 }
505 var v reflect.Value
506 switch base.Kind() {
507 case reflect.Int32:
508 var value int32
509 switch typeID {
510 case INT32:
511 value = buf.ReadInt32(ctx.Err())
512 case VARINT32:
513 value = buf.ReadVarint32(ctx.Err())
514 default:
515 ctx.SetError(DeserializationErrorf("unsupported union int32 type id: %d", typeID))
516 return reflect.Value{}, false
517 }
518 if ctx.HasError() {
519 return reflect.Value{}, false
520 }
521 v = reflect.New(base).Elem()
522 v.SetInt(int64(value))
523 case reflect.Uint32:
524 var value uint32
525 switch typeID {
526 case UINT32:
527 value = buf.ReadUint32(ctx.Err())
528 case VAR_UINT32:
529 value = buf.ReadVarUint32(ctx.Err())
530 default:
531 ctx.SetError(DeserializationErrorf("unsupported union uint32 type id: %d", typeID))
532 return reflect.Value{}, false
533 }
534 if ctx.HasError() {
535 return reflect.Value{}, false
536 }
537 v = reflect.New(base).Elem()
538 v.SetUint(uint64(value))
539 case reflect.Int64:
540 var value int64
541 switch typeID {
542 case INT64:
543 value = buf.ReadInt64(ctx.Err())
544 case VARINT64:
545 value = buf.ReadVarint64(ctx.Err())
546 case TAGGED_INT64:
547 value = buf.ReadTaggedInt64(ctx.Err())
548 default:
549 ctx.SetError(DeserializationErrorf("unsupported union int64 type id: %d", typeID))
550 return reflect.Value{}, false
551 }
552 if ctx.HasError() {
553 return reflect.Value{}, false
554 }

Callers 1

readUnionOverrideValueFunction · 0.85

Calls 15

DeserializationErrorfFunction · 0.85
KindMethod · 0.80
ReadUint32Method · 0.80
ReadUint64Method · 0.80
ReadVarUint64Method · 0.80
ReadTaggedUint64Method · 0.80
int64Function · 0.50
uint64Function · 0.50
BufferMethod · 0.45
ReadInt32Method · 0.45
ErrMethod · 0.45
ReadVarint32Method · 0.45

Tested by

no test coverage detected