Skip to content

Commit ef25ea2

Browse files
authored
feat(go): add missing type resolver for uint{16,32,64}slice (#3311)
## Why? The `uint` serializer and specific `uint16`, `uint32`, `uint64` slice serializers were implemented but missing from the `TypeResolver` registration and dispatch logic. This caused `not supported` errors when using these types. ## What does this PR do? 1. **Type Registration**: * Registers `uint16Type`, `uint32Type`, and `uint64Type` in `newTypeResolver` initialization to ensure `decodeType` can correctly resolve these type strings. 2. **Serializer Dispatch**: * Updates `createSerializer` in `type_resolver.go` to correctly dispatch to the existing optimized `uint16SliceSerializer`, `uint32SliceSerializer`, and `uint64SliceSerializer` for the corresponding slice types. 3. **Tests**: * Adds test cases in `TestTypeResolver` (`type_test.go`) to verify that `[]uint16`, `[]uint32`, and `[]uint64` are correctly resolved and serialized. ## Related issues ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark
1 parent 9668497 commit ef25ea2

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

go/fory/type_resolver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ func newTypeResolver(fory *Fory) *TypeResolver {
248248
for _, t := range []reflect.Type{
249249
boolType,
250250
byteType,
251+
uint16Type,
252+
uint32Type,
253+
uint64Type,
251254
int8Type,
252255
int16Type,
253256
int32Type,
@@ -1704,6 +1707,12 @@ func (r *TypeResolver) createSerializer(type_ reflect.Type, mapInStruct bool) (s
17041707
case reflect.Uint8:
17051708
// []byte uses byteSliceSerializer
17061709
return byteSliceSerializer{}, nil
1710+
case reflect.Uint16:
1711+
return uint16SliceSerializer{}, nil
1712+
case reflect.Uint32:
1713+
return uint32SliceSerializer{}, nil
1714+
case reflect.Uint64:
1715+
return uint64SliceSerializer{}, nil
17071716
case reflect.String:
17081717
return stringSliceSerializer{}, nil
17091718
}

go/fory/type_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func TestTypeResolver(t *testing.T) {
4343
"[]map[string][]map[string]*interface {}"},
4444
{reflect.TypeOf((*A)(nil)), "*@example.A"},
4545
{reflect.TypeOf((*A)(nil)).Elem(), "@example.A"},
46+
{reflect.TypeOf([]uint16{}), "[]uint16"},
47+
{reflect.TypeOf([]uint32{}), "[]uint32"},
48+
{reflect.TypeOf([]uint64{}), "[]uint64"},
4649
{reflect.TypeOf((*[]map[string]int)(nil)), "*[]map[string]int"},
4750
{reflect.TypeOf((*[]map[A]int)(nil)), "*[]map[@example.A]int"},
4851
{reflect.TypeOf((*[]map[string]*A)(nil)), "*[]map[string]*@example.A"},

0 commit comments

Comments
 (0)