This is an automated email from the ASF dual-hosted git repository.

pandalee 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 190d233e2 refactor(go): rename FieldInfo to FieldDef to avoide name 
collision (#2594)
190d233e2 is described below

commit 190d233e2b106bf41392e13b424e1d392cac3683
Author: Zhong Junjie <[email protected]>
AuthorDate: Tue Sep 9 22:11:33 2025 +0800

    refactor(go): rename FieldInfo to FieldDef to avoide name collision (#2594)
    
    <!--
    **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?
    
    Previous PR #2554 introduced a type named "FieldInfo", which conflicts
    with the existing "fieldInfo" in struct.go. This naming collision
    creates confusion, particularly when interacting with both types. This
    PR has been split out from the original for easier review.
    
    <!-- Describe the purpose of this PR. -->
    
    ## What does this PR do?
    
    <!-- Describe the details of this PR. -->
    
    rename FieldInfo to FieldDef to avoide name collision
    
    ## Related issues
    
    <!--
    Is there any related issue? If this PR closes them you say say
    fix/closes:
    
    - #xxxx0
    - #xxxx1
    - Fixes #xxxx2
    -->
    
    #2192
    
    ## 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.
    -->
    
    - [ x ] Does this PR introduce any public API change? no.
    - [ x ] Does this PR introduce any binary protocol compatibility change?
    no.
    
    ## 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/type_def.go              | 27 ++++++++++++++-------------
 go/fory/type_def_decoder.go      | 20 ++++++++++----------
 go/fory/type_def_encoder.go      | 24 ++++++++++++------------
 go/fory/type_def_encoder_test.go |  6 +++---
 4 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/go/fory/type_def.go b/go/fory/type_def.go
index eef803ca4..720d9c99e 100644
--- a/go/fory/type_def.go
+++ b/go/fory/type_def.go
@@ -45,18 +45,19 @@ type TypeDef struct {
        typeName       *MetaStringBytes
        compressed     bool
        registerByName bool
-       fieldInfos     []FieldInfo
+       fieldDefs      []FieldDef
        encoded        []byte
+       typ            reflect.Type
 }
 
-func NewTypeDef(typeId TypeId, nsName, typeName *MetaStringBytes, 
registerByName, compressed bool, fieldInfos []FieldInfo) *TypeDef {
+func NewTypeDef(typeId TypeId, nsName, typeName *MetaStringBytes, 
registerByName, compressed bool, fieldDefs []FieldDef) *TypeDef {
        return &TypeDef{
                typeId:         typeId,
                nsName:         nsName,
                typeName:       typeName,
                compressed:     compressed,
                registerByName: registerByName,
-               fieldInfos:     fieldInfos,
+               fieldDefs:      fieldDefs,
                encoded:        nil,
        }
 }
@@ -79,7 +80,7 @@ func skipTypeDef(buffer *ByteBuffer, header int64) {
 
 // buildTypeDef constructs a TypeDef from a value
 func buildTypeDef(fory *Fory, value reflect.Value) (*TypeDef, error) {
-       fieldInfos, err := buildFieldInfos(fory, value)
+       fieldDefs, err := buildFieldDefs(fory, value)
        if err != nil {
                return nil, fmt.Errorf("failed to extract field infos: %w", err)
        }
@@ -90,7 +91,7 @@ func buildTypeDef(fory *Fory, value reflect.Value) (*TypeDef, 
error) {
        }
        typeId := TypeId(info.TypeID)
        registerByName := IsNamespacedType(typeId)
-       typeDef := NewTypeDef(typeId, info.PkgPathBytes, info.NameBytes, 
registerByName, false, fieldInfos)
+       typeDef := NewTypeDef(typeId, info.PkgPathBytes, info.NameBytes, 
registerByName, false, fieldDefs)
 
        // encoding the typeDef, and save the encoded bytes
        encoded, err := encodingTypeDef(fory.typeResolver, typeDef)
@@ -103,13 +104,13 @@ func buildTypeDef(fory *Fory, value reflect.Value) 
(*TypeDef, error) {
 }
 
 /*
-FieldInfo contains information about a single field in a struct
-field info layout as following:
+FieldDef contains definition of a single field in a struct
+field def layout as following:
   - first 1 byte: header (2 bits field name encoding + 4 bits size + 
nullability flag + ref tracking flag)
   - next variable bytes: FieldType info
   - next variable bytes: field name or tag id
 */
-type FieldInfo struct {
+type FieldDef struct {
        name         string
        nameEncoding meta.Encoding
        nullable     bool
@@ -117,16 +118,16 @@ type FieldInfo struct {
        fieldType    FieldType
 }
 
-// buildFieldInfos extracts field information from a struct value
-func buildFieldInfos(fory *Fory, value reflect.Value) ([]FieldInfo, error) {
-       var fieldInfos []FieldInfo
+// buildFieldDefs extracts field definitions from a struct value
+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)
                fieldValue := value.Field(i)
 
-               var fieldInfo FieldInfo
+               var fieldInfo FieldDef
                fieldName := field.Name
 
                nameEncoding := 
fory.typeResolver.typeNameEncoder.ComputeEncodingWith(fieldName, 
fieldNameEncodings)
@@ -135,7 +136,7 @@ func buildFieldInfos(fory *Fory, value reflect.Value) 
([]FieldInfo, error) {
                if err != nil {
                        return nil, fmt.Errorf("failed to build field type for 
field %s: %w", fieldName, err)
                }
-               fieldInfo = FieldInfo{
+               fieldInfo = FieldDef{
                        name:         fieldName,
                        nameEncoding: nameEncoding,
                        nullable:     nullable(field.Type),
diff --git a/go/fory/type_def_decoder.go b/go/fory/type_def_decoder.go
index cefd8fe02..f4b2d8ec2 100644
--- a/go/fory/type_def_decoder.go
+++ b/go/fory/type_def_decoder.go
@@ -83,12 +83,12 @@ func decodeTypeDef(fory *Fory, buffer *ByteBuffer) 
(*TypeDef, error) {
        }
 
        // Read fields information
-       fieldInfos := make([]FieldInfo, fieldCount)
+       fieldInfos := make([]FieldDef, fieldCount)
        if hasFieldsMeta {
                for i := 0; i < fieldCount; i++ {
-                       fieldInfo, err := readFieldInfo(fory.typeResolver, 
metaBuffer)
+                       fieldInfo, err := readFieldDef(fory.typeResolver, 
metaBuffer)
                        if err != nil {
-                               return nil, fmt.Errorf("failed to read field 
info %d: %w", i, err)
+                               return nil, fmt.Errorf("failed to read field 
def %d: %w", i, err)
                        }
                        fieldInfos[i] = fieldInfo
                }
@@ -102,17 +102,17 @@ func decodeTypeDef(fory *Fory, buffer *ByteBuffer) 
(*TypeDef, error) {
 }
 
 /*
-readFieldInfo reads a single field's information from the buffer
-field info layout as following:
+readFieldDef reads a single field's definition from the buffer
+field def layout as following:
   - first 1 byte: header (2 bits field name encoding + 4 bits size + 
nullability flag + ref tracking flag)
   - next variable bytes: FieldType info
   - next variable bytes: field name or tag id
 */
-func readFieldInfo(typeResolver *typeResolver, buffer *ByteBuffer) (FieldInfo, 
error) {
+func readFieldDef(typeResolver *typeResolver, buffer *ByteBuffer) (FieldDef, 
error) {
        // Read field header
        headerByte, err := buffer.ReadByte()
        if err != nil {
-               return FieldInfo{}, fmt.Errorf("failed to read field header: 
%w", err)
+               return FieldDef{}, fmt.Errorf("failed to read field header: 
%w", err)
        }
 
        // Resolve the header
@@ -130,17 +130,17 @@ func readFieldInfo(typeResolver *typeResolver, buffer 
*ByteBuffer) (FieldInfo, e
        // reading field type
        ft, err := readFieldType(buffer)
        if err != nil {
-               return FieldInfo{}, err
+               return FieldDef{}, err
        }
 
        // Reading field name based on encoding
        nameBytes := buffer.ReadBinary(nameLen)
        fieldName, err := typeResolver.typeNameDecoder.Decode(nameBytes, 
nameEncoding)
        if err != nil {
-               return FieldInfo{}, fmt.Errorf("failed to decode field name: 
%w", err)
+               return FieldDef{}, fmt.Errorf("failed to decode field name: 
%w", err)
        }
 
-       return FieldInfo{
+       return FieldDef{
                name:         fieldName,
                nameEncoding: nameEncoding,
                fieldType:    ft,
diff --git a/go/fory/type_def_encoder.go b/go/fory/type_def_encoder.go
index 03d08731c..866452388 100644
--- a/go/fory/type_def_encoder.go
+++ b/go/fory/type_def_encoder.go
@@ -53,7 +53,7 @@ typeDef are layout as following:
 - first 8 bytes: global header (50 bits hash + 1 bit compress flag + write 
fields meta + 12 bits meta size)
 - next 1 byte: meta header (2 bits reserved + 1 bit register by name flag + 5 
bits num fields)
 - next variable bytes: type id (varint) or ns name + type name
-- next variable bytes: field infos (see below)
+- next variable bytes: field defs (see below)
 */
 func encodingTypeDef(typeResolver *typeResolver, typeDef *TypeDef) ([]byte, 
error) {
        buffer := NewByteBuffer(nil)
@@ -73,11 +73,11 @@ func encodingTypeDef(typeResolver *typeResolver, typeDef 
*TypeDef) ([]byte, erro
                buffer.WriteVarInt32(int32(typeDef.typeId))
        }
 
-       if err := writeFieldsInfo(typeResolver, buffer, typeDef.fieldInfos); 
err != nil {
-               return nil, fmt.Errorf("failed to write fields info: %w", err)
+       if err := writeFieldDefs(typeResolver, buffer, typeDef.fieldDefs); err 
!= nil {
+               return nil, fmt.Errorf("failed to write fields def: %w", err)
        }
 
-       result, err := prependGlobalHeader(buffer, false, 
len(typeDef.fieldInfos) > 0)
+       result, err := prependGlobalHeader(buffer, false, 
len(typeDef.fieldDefs) > 0)
        if err != nil {
                return nil, fmt.Errorf("failed to write global binary header: 
%w", err)
        }
@@ -125,7 +125,7 @@ func writeMetaHeader(buffer *ByteBuffer, typeDef *TypeDef) 
error {
        if err := buffer.WriteByte(0xFF); err != nil {
                return err
        }
-       fieldInfos := typeDef.fieldInfos
+       fieldInfos := typeDef.fieldDefs
        header := len(fieldInfos)
        if header > SmallNumFieldsThreshold {
                header = SmallNumFieldsThreshold
@@ -139,22 +139,22 @@ func writeMetaHeader(buffer *ByteBuffer, typeDef 
*TypeDef) error {
        return nil
 }
 
-// writeFieldsInfo writes field information according to the specification
-// field info layout as following:
+// writeFieldDefs writes field definitions according to the specification
+// field def layout as following:
 //   - first 1 byte: header (2 bits field name encoding + 4 bits size + 
nullability flag + ref tracking flag)
 //   - next variable bytes: FieldType info
 //   - next variable bytes: field name or tag id
-func writeFieldsInfo(typeResolver *typeResolver, buffer *ByteBuffer, 
fieldInfos []FieldInfo) error {
+func writeFieldDefs(typeResolver *typeResolver, buffer *ByteBuffer, fieldInfos 
[]FieldDef) error {
        for _, field := range fieldInfos {
-               if err := writeFieldInfo(typeResolver, buffer, field); err != 
nil {
-                       return fmt.Errorf("failed to write field info for field 
%s: %w", field.name, err)
+               if err := writeFieldDef(typeResolver, buffer, field); err != 
nil {
+                       return fmt.Errorf("failed to write field def for field 
%s: %w", field.name, err)
                }
        }
        return nil
 }
 
-// writeFieldInfo writes a single field's information
-func writeFieldInfo(typeResolver *typeResolver, buffer *ByteBuffer, field 
FieldInfo) error {
+// writeFieldDef writes a single field's definition
+func writeFieldDef(typeResolver *typeResolver, buffer *ByteBuffer, field 
FieldDef) error {
        // Write field header
        // 2 bits field name encoding + 4 bits size + nullability flag + ref 
tracking flag
        offset := buffer.writerIndex
diff --git a/go/fory/type_def_encoder_test.go b/go/fory/type_def_encoder_test.go
index 472249183..0c74954fb 100644
--- a/go/fory/type_def_encoder_test.go
+++ b/go/fory/type_def_encoder_test.go
@@ -68,11 +68,11 @@ func TestTypeDefEncodingDecoding(t *testing.T) {
        assert.Equal(t, originalTypeDef.compressed, decodedTypeDef.compressed, 
"Compressed flag mismatch")
 
        // Verify field count matches
-       assert.Equal(t, len(originalTypeDef.fieldInfos), 
len(decodedTypeDef.fieldInfos), "Field count mismatch")
+       assert.Equal(t, len(originalTypeDef.fieldDefs), 
len(decodedTypeDef.fieldDefs), "Field count mismatch")
 
        // Verify field names match
-       for i, originalField := range originalTypeDef.fieldInfos {
-               decodedField := decodedTypeDef.fieldInfos[i]
+       for i, originalField := range originalTypeDef.fieldDefs {
+               decodedField := decodedTypeDef.fieldDefs[i]
 
                assert.Equal(t, originalField.name, decodedField.name, "Field 
name mismatch at index %d", i)
                assert.Equal(t, originalField.nameEncoding, 
decodedField.nameEncoding, "Field name encoding mismatch at index %d", i)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to