ThisingL commented on code in PR #2587:
URL: https://github.com/apache/fory/pull/2587#discussion_r2332524532


##########
go/fory/codegen/encoder.go:
##########
@@ -140,3 +152,166 @@ func generateFieldWriteTyped(buf *bytes.Buffer, field 
*FieldInfo) error {
        fmt.Fprintf(buf, "\t// TODO: unsupported type %s\n", 
field.Type.String())
        return nil
 }
+
+// generateSliceWrite generates code to serialize a slice field
+func generateSliceWrite(buf *bytes.Buffer, fieldAccess string, slice 
*types.Slice) error {
+       elemType := slice.Elem()
+
+       fmt.Fprintf(buf, "\t// Write slice length\n")
+       fmt.Fprintf(buf, "\tbuf.WriteInt32(int32(len(%s)))\n", fieldAccess)
+       fmt.Fprintf(buf, "\t// Write slice elements\n")
+       fmt.Fprintf(buf, "\tfor _, elem := range %s {\n", fieldAccess)
+
+       // Generate element writing code based on element type
+       if err := generateElementWrite(buf, "elem", elemType); err != nil {
+               return err
+       }
+
+       fmt.Fprintf(buf, "\t}\n")
+       return nil
+}
+
+// generateElementWrite generates code to write a single element of any 
supported type
+func generateElementWrite(buf *bytes.Buffer, elemAccess string, elemType 
types.Type) error {

Review Comment:
   Yeah, this is just a simple implementation, has not consistent with spec. I 
will align it with the specification, and also add tests to testify alignmet it 
with the reflection results.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to