GetDispatchId returns the DispatchId for a reflect.Type. For int32/int64/uint32/uint64, returns varint dispatch IDs by default since that's the default encoding in xlang serialization (VARINT32, VARINT64, VAR_UINT32, VAR_UINT64).
(t reflect.Type)
| 404 | // For int32/int64/uint32/uint64, returns varint dispatch IDs by default since that's |
| 405 | // the default encoding in xlang serialization (VARINT32, VARINT64, VAR_UINT32, VAR_UINT64). |
| 406 | func GetDispatchId(t reflect.Type) DispatchId { |
| 407 | switch t.Kind() { |
| 408 | case reflect.Bool: |
| 409 | return PrimitiveBoolDispatchId |
| 410 | case reflect.Int8: |
| 411 | return PrimitiveInt8DispatchId |
| 412 | case reflect.Int16: |
| 413 | return PrimitiveInt16DispatchId |
| 414 | case reflect.Int32: |
| 415 | // Default to varint encoding (VARINT32) for xlang compatibility |
| 416 | return PrimitiveVarint32DispatchId |
| 417 | case reflect.Int64: |
| 418 | // Default to varint encoding (VARINT64) for xlang compatibility |
| 419 | return PrimitiveVarint64DispatchId |
| 420 | case reflect.Int: |
| 421 | return PrimitiveIntDispatchId |
| 422 | case reflect.Uint8: |
| 423 | return PrimitiveUint8DispatchId |
| 424 | case reflect.Uint16: |
| 425 | // Check for fory.Float16 (aliased to uint16) |
| 426 | if t.Name() == "Float16" && (t.PkgPath() == "github.com/apache/fory/go/fory/float16" || strings.HasSuffix(t.PkgPath(), "/float16")) { |
| 427 | return PrimitiveFloat16DispatchId |
| 428 | } |
| 429 | return PrimitiveUint16DispatchId |
| 430 | case reflect.Uint32: |
| 431 | // Default to varint encoding (VAR_UINT32) for xlang compatibility |
| 432 | return PrimitiveVarUint32DispatchId |
| 433 | case reflect.Uint64: |
| 434 | // Default to varint encoding (VAR_UINT64) for xlang compatibility |
| 435 | return PrimitiveVarUint64DispatchId |
| 436 | case reflect.Uint: |
| 437 | return PrimitiveUintDispatchId |
| 438 | case reflect.Float32: |
| 439 | return PrimitiveFloat32DispatchId |
| 440 | case reflect.Float64: |
| 441 | return PrimitiveFloat64DispatchId |
| 442 | case reflect.String: |
| 443 | return StringDispatchId |
| 444 | case reflect.Slice: |
| 445 | // Check for specific slice types |
| 446 | switch t.Elem().Kind() { |
| 447 | case reflect.Uint8: |
| 448 | return ByteSliceDispatchId |
| 449 | case reflect.Int8: |
| 450 | return Int8SliceDispatchId |
| 451 | case reflect.Int16: |
| 452 | return Int16SliceDispatchId |
| 453 | case reflect.Int32: |
| 454 | return Int32SliceDispatchId |
| 455 | case reflect.Int64: |
| 456 | return Int64SliceDispatchId |
| 457 | case reflect.Int: |
| 458 | return IntSliceDispatchId |
| 459 | case reflect.Uint: |
| 460 | return UintSliceDispatchId |
| 461 | case reflect.Uint16: |
| 462 | // Check if it's float16 slice |
| 463 | if t.Elem().Name() == "Float16" && (t.Elem().PkgPath() == "github.com/apache/fory/go/fory/float16" || strings.HasSuffix(t.Elem().PkgPath(), "/float16")) { |
no test coverage detected