generateWriteInterface generates interface compatibility method (WriteData)
(buf *bytes.Buffer, s *StructInfo)
| 50 | |
| 51 | // generateWriteInterface generates interface compatibility method (WriteData) |
| 52 | func generateWriteInterface(buf *bytes.Buffer, s *StructInfo) error { |
| 53 | // Generate WriteData method (reflect.Value-based API) |
| 54 | fmt.Fprintf(buf, "// WriteData provides reflect.Value interface compatibility (implements fory.Serializer)\n") |
| 55 | fmt.Fprintf(buf, "func (g *%s_ForyGenSerializer) WriteData(ctx *fory.WriteContext, value reflect.Value) {\n", s.Name) |
| 56 | fmt.Fprintf(buf, "\tg.initHash(ctx.TypeResolver())\n") |
| 57 | fmt.Fprintf(buf, "\t// Convert reflect.Value to concrete type and delegate to typed method\n") |
| 58 | fmt.Fprintf(buf, "\tvar v *%s\n", s.Name) |
| 59 | fmt.Fprintf(buf, "\tif value.Kind() == reflect.Ptr {\n") |
| 60 | fmt.Fprintf(buf, "\t\tv = value.Interface().(*%s)\n", s.Name) |
| 61 | fmt.Fprintf(buf, "\t} else {\n") |
| 62 | fmt.Fprintf(buf, "\t\t// Create a copy to get a pointer\n") |
| 63 | fmt.Fprintf(buf, "\t\ttemp := value.Interface().(%s)\n", s.Name) |
| 64 | fmt.Fprintf(buf, "\t\tv = &temp\n") |
| 65 | fmt.Fprintf(buf, "\t}\n") |
| 66 | fmt.Fprintf(buf, "\t// Delegate to strongly-typed method for maximum performance\n") |
| 67 | fmt.Fprintf(buf, "\tif err := g.WriteTyped(ctx, v); err != nil {\n") |
| 68 | fmt.Fprintf(buf, "\t\tctx.SetError(fory.FromError(err))\n") |
| 69 | fmt.Fprintf(buf, "\t}\n") |
| 70 | fmt.Fprintf(buf, "}\n\n") |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | // generateFieldWriteTyped generates field writing code for the typed method |
| 75 | func generateFieldWriteTyped(buf *bytes.Buffer, field *FieldInfo) error { |
no outgoing calls
no test coverage detected