generateReadInterface generates interface compatibility method (ReadData)
(buf *bytes.Buffer, s *StructInfo)
| 61 | |
| 62 | // generateReadInterface generates interface compatibility method (ReadData) |
| 63 | func generateReadInterface(buf *bytes.Buffer, s *StructInfo) error { |
| 64 | // Generate ReadData method (reflect.Value-based API) |
| 65 | fmt.Fprintf(buf, "// ReadData provides reflect.Value interface compatibility (implements fory.Serializer)\n") |
| 66 | fmt.Fprintf(buf, "func (g *%s_ForyGenSerializer) ReadData(ctx *fory.ReadContext, value reflect.Value) {\n", s.Name) |
| 67 | fmt.Fprintf(buf, "\tg.initHash(ctx.TypeResolver())\n") |
| 68 | fmt.Fprintf(buf, "\t// Convert reflect.Value to concrete type and delegate to typed method\n") |
| 69 | fmt.Fprintf(buf, "\tvar v *%s\n", s.Name) |
| 70 | fmt.Fprintf(buf, "\tif value.Kind() == reflect.Ptr {\n") |
| 71 | fmt.Fprintf(buf, "\t\tif value.IsNil() {\n") |
| 72 | fmt.Fprintf(buf, "\t\t\t// For pointer types, allocate using value.Type().Elem()\n") |
| 73 | fmt.Fprintf(buf, "\t\t\tvalue.Set(reflect.New(value.Type().Elem()))\n") |
| 74 | fmt.Fprintf(buf, "\t\t}\n") |
| 75 | fmt.Fprintf(buf, "\t\tv = value.Interface().(*%s)\n", s.Name) |
| 76 | fmt.Fprintf(buf, "\t} else {\n") |
| 77 | fmt.Fprintf(buf, "\t\t// value must be addressable for read\n") |
| 78 | fmt.Fprintf(buf, "\t\tv = value.Addr().Interface().(*%s)\n", s.Name) |
| 79 | fmt.Fprintf(buf, "\t}\n") |
| 80 | fmt.Fprintf(buf, "\t// Delegate to strongly-typed method for maximum performance\n") |
| 81 | fmt.Fprintf(buf, "\tif err := g.ReadTyped(ctx, v); err != nil {\n") |
| 82 | fmt.Fprintf(buf, "\t\tctx.SetError(fory.FromError(err))\n") |
| 83 | fmt.Fprintf(buf, "\t}\n") |
| 84 | fmt.Fprintf(buf, "}\n\n") |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | // generateFieldReadTyped generates field reading code for the typed method |
| 89 | func generateFieldReadTyped(buf *bytes.Buffer, field *FieldInfo) error { |
no outgoing calls
no test coverage detected