This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 4e2b33eed chore(go): replace all typ to type_ (#2612)
4e2b33eed is described below
commit 4e2b33eed50ef4243b80bfe7adb4cde9e8097fa2
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Sep 15 17:09:10 2025 +0800
chore(go): replace all typ to type_ (#2612)
<!--
**Thanks for contributing to Apache Fory™.**
**If this is your first time opening a PR on fory, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory™** community has requirements on the naming of pr
titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Apache Fory™ has a strong focus on performance. If the PR you submit
will have an impact on performance, please benchmark it first and
provide the benchmark result here.
-->
## Why?
<!-- Describe the purpose of this PR. -->
## What does this PR do?
<!-- Describe the details of this PR. -->
## Related issues
<!--
Is there any related issue? If this PR closes them you say say
fix/closes:
- #xxxx0
- #xxxx1
- Fixes #xxxx2
-->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fory/issues/new/choose) describing the
need to do so and update the document if necessary.
Delete section if not applicable.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
Delete section if not applicable.
-->
---
go/fory/codegen/guard.go | 24 ++++++++++-----------
go/fory/fory.go | 16 +++++++-------
go/fory/map.go | 14 ++++++------
go/fory/type.go | 56 ++++++++++++++++++++++++------------------------
go/fory/type_def.go | 8 +++----
5 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/go/fory/codegen/guard.go b/go/fory/codegen/guard.go
index c8d58c3e1..c346f439d 100644
--- a/go/fory/codegen/guard.go
+++ b/go/fory/codegen/guard.go
@@ -92,20 +92,20 @@ func formatFieldType(field FieldInfo) string {
// formatGoType converts a Go type to its string representation
func formatGoType(t types.Type) string {
- switch typ := t.(type) {
+ switch type_ := t.(type) {
case *types.Basic:
- return typ.Name()
+ return type_.Name()
case *types.Pointer:
- return "*" + formatGoType(typ.Elem())
+ return "*" + formatGoType(type_.Elem())
case *types.Array:
- return fmt.Sprintf("[%d]%s", typ.Len(),
formatGoType(typ.Elem()))
+ return fmt.Sprintf("[%d]%s", type_.Len(),
formatGoType(type_.Elem()))
case *types.Slice:
- return "[]" + formatGoType(typ.Elem())
+ return "[]" + formatGoType(type_.Elem())
case *types.Map:
- return fmt.Sprintf("map[%s]%s", formatGoType(typ.Key()),
formatGoType(typ.Elem()))
+ return fmt.Sprintf("map[%s]%s", formatGoType(type_.Key()),
formatGoType(type_.Elem()))
case *types.Chan:
dir := ""
- switch typ.Dir() {
+ switch type_.Dir() {
case types.SendOnly:
dir = "chan<- "
case types.RecvOnly:
@@ -113,22 +113,22 @@ func formatGoType(t types.Type) string {
default:
dir = "chan "
}
- return dir + formatGoType(typ.Elem())
+ return dir + formatGoType(type_.Elem())
case *types.Named:
// Handle named types like custom structs, interfaces, etc.
- obj := typ.Obj()
+ obj := type_.Obj()
if obj.Pkg() != nil && obj.Pkg().Name() != "" {
return obj.Pkg().Name() + "." + obj.Name()
}
return obj.Name()
case *types.Interface:
- if typ.Empty() {
+ if type_.Empty() {
return "interface{}"
}
// For non-empty interfaces, we need to format method signatures
var methods []string
- for i := 0; i < typ.NumMethods(); i++ {
- method := typ.Method(i)
+ for i := 0; i < type_.NumMethods(); i++ {
+ method := type_.Method(i)
sig := method.Type().(*types.Signature)
methods = append(methods,
formatMethodSignature(method.Name(), sig))
}
diff --git a/go/fory/fory.go b/go/fory/fory.go
index 6431b324c..dbc81d584 100644
--- a/go/fory/fory.go
+++ b/go/fory/fory.go
@@ -36,11 +36,11 @@ func NewFory(referenceTracking bool) *Fory {
// Copy generated serializers from global resolver to this instance
if globalTypeResolver != nil {
- for typ, serializer := range
globalTypeResolver.typeToSerializers {
- fory.typeResolver.typeToSerializers[typ] = serializer
+ for type_, serializer := range
globalTypeResolver.typeToSerializers {
+ fory.typeResolver.typeToSerializers[type_] = serializer
}
- for typeId, typ := range globalTypeResolver.typeIdToType {
- fory.typeResolver.typeIdToType[typeId] = typ
+ for typeId, type_ := range globalTypeResolver.typeIdToType {
+ fory.typeResolver.typeIdToType[typeId] = type_
}
}
@@ -447,7 +447,7 @@ func (f *Fory) readData(buffer *ByteBuffer, value
reflect.Value, serializer Seri
}
serializer = typeInfo.Serializer
var concrete reflect.Value
- var typ reflect.Type
+ var type_ reflect.Type
/*
Added logic to distinguish between:
1. Deserialization into a specified interface type,
@@ -458,12 +458,12 @@ func (f *Fory) readData(buffer *ByteBuffer, value
reflect.Value, serializer Seri
case value.Kind() == reflect.Interface,
!value.CanSet():
concrete = reflect.New(typeInfo.Type).Elem()
- typ = typeInfo.Type
+ type_ = typeInfo.Type
default:
concrete = value
- typ = concrete.Type()
+ type_ = concrete.Type()
}
- if err := serializer.Read(f, buffer, typ, concrete); err != nil
{
+ if err := serializer.Read(f, buffer, type_, concrete); err !=
nil {
return err
}
value.Set(concrete)
diff --git a/go/fory/map.go b/go/fory/map.go
index 2ead33e3e..21e53ea36 100644
--- a/go/fory/map.go
+++ b/go/fory/map.go
@@ -275,9 +275,9 @@ func (s mapSerializer) writeObj(f *Fory, serializer
Serializer, buf *ByteBuffer,
return serializer.Write(f, buf, obj)
}
-func (s mapSerializer) Read(f *Fory, buf *ByteBuffer, typ reflect.Type, value
reflect.Value) error {
+func (s mapSerializer) Read(f *Fory, buf *ByteBuffer, type_ reflect.Type,
value reflect.Value) error {
if s.type_ == nil {
- s.type_ = typ
+ s.type_ = type_
}
if value.IsNil() {
@@ -291,9 +291,9 @@ func (s mapSerializer) Read(f *Fory, buf *ByteBuffer, typ
reflect.Type, value re
// Otherwise, a generic map type will be used
switch {
case s.mapInStruct:
- value.Set(reflect.MakeMap(typ))
- case !isIfaceMap(typ):
- value.Set(reflect.MakeMap(typ))
+ value.Set(reflect.MakeMap(type_))
+ case !isIfaceMap(type_):
+ value.Set(reflect.MakeMap(type_))
default:
iface := reflect.TypeOf((*interface{})(nil)).Elem()
newMapType := reflect.MapOf(iface, iface)
@@ -308,8 +308,8 @@ func (s mapSerializer) Read(f *Fory, buf *ByteBuffer, typ
reflect.Type, value re
chunkHeader = buf.ReadUint8()
}
- keyType := typ.Key()
- valueType := typ.Elem()
+ keyType := type_.Key()
+ valueType := type_.Elem()
keySer := s.keySerializer
valSer := s.valueSerializer
resolver := f.typeResolver
diff --git a/go/fory/type.go b/go/fory/type.go
index 7817a4a33..af30a6dc1 100644
--- a/go/fory/type.go
+++ b/go/fory/type.go
@@ -471,12 +471,12 @@ func (r *typeResolver) RegisterSerializer(type_
reflect.Type, s Serializer) erro
// RegisterGeneratedSerializer registers a generated serializer for a specific
type.
// Generated serializers have priority over reflection-based serializers and
can override existing ones.
-func RegisterGeneratedSerializer(typ interface{}, s Serializer) error {
- if typ == nil {
- return fmt.Errorf("typ cannot be nil")
+func RegisterGeneratedSerializer(type_ interface{}, s Serializer) error {
+ if type_ == nil {
+ return fmt.Errorf("type_ cannot be nil")
}
- reflectType := reflect.TypeOf(typ)
+ reflectType := reflect.TypeOf(type_)
if reflectType.Kind() == reflect.Ptr {
reflectType = reflectType.Elem()
}
@@ -589,13 +589,13 @@ func (r *typeResolver) getTypeInfo(value reflect.Value,
create bool) (TypeInfo,
if value.Kind() == reflect.Interface {
value = value.Elem()
}
- typ := value.Type()
+ type_ := value.Type()
// Get package path and type name for registration
var typeName string
var pkgPath string
- rawInfo, ok := r.typeToTypeInfo[typ]
+ rawInfo, ok := r.typeToTypeInfo[type_]
if !ok {
- fmt.Errorf("type %v not registered with a tag", typ)
+ fmt.Errorf("type %v not registered with a tag", type_)
}
clean := strings.TrimPrefix(rawInfo, "*@")
clean = strings.TrimPrefix(clean, "@")
@@ -604,17 +604,17 @@ func (r *typeResolver) getTypeInfo(value reflect.Value,
create bool) (TypeInfo,
} else {
pkgPath = clean
}
- if typ.Kind() == reflect.Ptr {
- typeName = typ.Elem().Name()
+ if type_.Kind() == reflect.Ptr {
+ typeName = type_.Elem().Name()
} else {
- typeName = typ.Name()
+ typeName = type_.Name()
}
// Handle special types that require explicit registration
switch {
- case typ.Kind() == reflect.Ptr:
+ case type_.Kind() == reflect.Ptr:
fmt.Errorf("pointer types must be registered explicitly")
- case typ.Kind() == reflect.Interface:
+ case type_.Kind() == reflect.Interface:
fmt.Errorf("interface types must be registered explicitly")
case pkgPath == "" && typeName == "":
fmt.Errorf("anonymous types must be registered explicitly")
@@ -627,7 +627,7 @@ func (r *typeResolver) getTypeInfo(value reflect.Value,
create bool) (TypeInfo,
// Auto-assign IDs
typeID = 0
default:
- fmt.Errorf("type %v must be registered explicitly", typ)
+ fmt.Errorf("type %v must be registered explicitly", type_)
}
/*
@@ -650,8 +650,8 @@ func (r *typeResolver) getTypeInfo(value reflect.Value,
create bool) (TypeInfo,
} else if value.Kind() == reflect.Map {
typeID = MAP
} else if value.Kind() == reflect.Array {
- typ = reflect.SliceOf(typ.Elem())
- return r.typesInfo[typ], nil
+ type_ = reflect.SliceOf(type_.Elem())
+ return r.typesInfo[type_], nil
} else if isMultiDimensionaSlice(value) {
typeID = LIST
return r.typeIDToTypeInfo[typeID], nil
@@ -659,7 +659,7 @@ func (r *typeResolver) getTypeInfo(value reflect.Value,
create bool) (TypeInfo,
// Register the type with full metadata
return r.registerType(
- typ,
+ type_,
typeID,
pkgPath,
typeName,
@@ -677,7 +677,7 @@ func isMultiDimensionaSlice(v reflect.Value) bool {
}
func (r *typeResolver) registerType(
- typ reflect.Type,
+ type_ reflect.Type,
typeID int32,
namespace string,
typeName string,
@@ -685,24 +685,24 @@ func (r *typeResolver) registerType(
internal bool,
) (TypeInfo, error) {
// Input validation
- if typ == nil {
+ if type_ == nil {
panic("nil type")
}
if typeName == "" && namespace != "" {
panic("namespace provided without typeName")
}
if internal && serializer != nil {
- if err := r.RegisterSerializer(typ, serializer); err != nil {
+ if err := r.RegisterSerializer(type_, serializer); err != nil {
panic(fmt.Errorf("impossible error: %s", err))
}
}
// Serializer initialization
if !internal && serializer == nil {
var err error
- serializer = r.typeToSerializers[typ] // Check pre-registered
serializers
+ serializer = r.typeToSerializers[type_] // Check pre-registered
serializers
if serializer == nil {
// Create new serializer if not found
- if serializer, err = r.createSerializer(typ, false);
err != nil {
+ if serializer, err = r.createSerializer(type_, false);
err != nil {
panic(fmt.Sprintf("failed to create serializer:
%v", err))
}
}
@@ -735,16 +735,16 @@ func (r *typeResolver) registerType(
// Build complete type information structure
typeInfo := TypeInfo{
- Type: typ,
+ Type: type_,
TypeID: typeID,
Serializer: serializer,
PkgPathBytes: nsBytes, // Encoded namespace bytes
NameBytes: typeBytes, // Encoded type name bytes
IsDynamic: dynamicType,
- hashValue: calcTypeHash(typ), // Precomputed hash for fast
lookups
+ hashValue: calcTypeHash(type_), // Precomputed hash for fast
lookups
}
// Update resolver caches:
- r.typesInfo[typ] = typeInfo // Cache by type string
+ r.typesInfo[type_] = typeInfo // Cache by type string
if typeName != "" {
r.namedTypeToTypeInfo[[2]string{namespace, typeName}] = typeInfo
// Cache by hashed namespace/name bytes
@@ -774,12 +774,12 @@ func (r *typeResolver) registerType(
return typeInfo, nil
}
-func calcTypeHash(typ reflect.Type) uint64 {
+func calcTypeHash(type_ reflect.Type) uint64 {
// Implement proper hash calculation based on type
h := fnv.New64a()
- h.Write([]byte(typ.PkgPath()))
- h.Write([]byte(typ.Name()))
- h.Write([]byte(typ.Kind().String()))
+ h.Write([]byte(type_.PkgPath()))
+ h.Write([]byte(type_.Name()))
+ h.Write([]byte(type_.Kind().String()))
return h.Sum64()
}
diff --git a/go/fory/type_def.go b/go/fory/type_def.go
index 720d9c99e..193dde6f3 100644
--- a/go/fory/type_def.go
+++ b/go/fory/type_def.go
@@ -47,7 +47,7 @@ type TypeDef struct {
registerByName bool
fieldDefs []FieldDef
encoded []byte
- typ reflect.Type
+ type_ reflect.Type
}
func NewTypeDef(typeId TypeId, nsName, typeName *MetaStringBytes,
registerByName, compressed bool, fieldDefs []FieldDef) *TypeDef {
@@ -122,9 +122,9 @@ type FieldDef struct {
func buildFieldDefs(fory *Fory, value reflect.Value) ([]FieldDef, error) {
var fieldInfos []FieldDef
- typ := value.Type()
- for i := 0; i < typ.NumField(); i++ {
- field := typ.Field(i)
+ type_ := value.Type()
+ for i := 0; i < type_.NumField(); i++ {
+ field := type_.Field(i)
fieldValue := value.Field(i)
var fieldInfo FieldDef
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]