(ctx *ReadContext, targetType reflect.Type, typeID TypeId)
| 495 | } |
| 496 | |
| 497 | func 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 | } |
no test coverage detected