MCPcopy Create free account
hub / github.com/apache/fory / generateReadMethod

Function generateReadMethod

go/fory/codegen/generator.go:497–529  ·  view source on GitHub ↗

generateReadMethod generates the Read method that handles ref/type flags

(buf *bytes.Buffer, s *StructInfo)

Source from the content-addressed store, hash-verified

495
496// generateReadMethod generates the Read method that handles ref/type flags
497func generateReadMethod(buf *bytes.Buffer, s *StructInfo) error {
498 fmt.Fprintf(buf, "// Read is the entry point for deserialization with ref/type handling\n")
499 fmt.Fprintf(buf, "func (g *%s_ForyGenSerializer) Read(ctx *fory.ReadContext, refMode fory.RefMode, readType bool, hasGenerics bool, value reflect.Value) {\n", s.Name)
500 fmt.Fprintf(buf, "\tg.initHash(ctx.TypeResolver())\n")
501 fmt.Fprintf(buf, "\t_ = hasGenerics // not used for struct serializers\n")
502 fmt.Fprintf(buf, "\terr := ctx.Err() // Get error pointer for deferred error checking\n")
503 fmt.Fprintf(buf, "\tswitch refMode {\n")
504 fmt.Fprintf(buf, "\tcase fory.RefModeTracking:\n")
505 fmt.Fprintf(buf, "\t\trefID, refErr := ctx.RefResolver().TryPreserveRefId(ctx.Buffer())\n")
506 fmt.Fprintf(buf, "\t\tif refErr != nil {\n")
507 fmt.Fprintf(buf, "\t\t\tctx.SetError(fory.FromError(refErr))\n")
508 fmt.Fprintf(buf, "\t\t\treturn\n")
509 fmt.Fprintf(buf, "\t\t}\n")
510 fmt.Fprintf(buf, "\t\tif int8(refID) < -1 { // NotNullValueFlag\n")
511 fmt.Fprintf(buf, "\t\t\tobj := ctx.RefResolver().GetReadObject(refID)\n")
512 fmt.Fprintf(buf, "\t\t\tif obj.IsValid() {\n")
513 fmt.Fprintf(buf, "\t\t\t\tvalue.Set(obj)\n")
514 fmt.Fprintf(buf, "\t\t\t}\n")
515 fmt.Fprintf(buf, "\t\t\treturn\n")
516 fmt.Fprintf(buf, "\t\t}\n")
517 fmt.Fprintf(buf, "\tcase fory.RefModeNullOnly:\n")
518 fmt.Fprintf(buf, "\t\tflag := ctx.Buffer().ReadInt8(err)\n")
519 fmt.Fprintf(buf, "\t\tif flag == -3 { // NullFlag\n")
520 fmt.Fprintf(buf, "\t\t\treturn\n")
521 fmt.Fprintf(buf, "\t\t}\n")
522 fmt.Fprintf(buf, "\t}\n")
523 fmt.Fprintf(buf, "\tif readType {\n")
524 fmt.Fprintf(buf, "\t\tctx.TypeResolver().ReadTypeInfo(ctx.Buffer(), err)\n")
525 fmt.Fprintf(buf, "\t}\n")
526 fmt.Fprintf(buf, "\tg.ReadData(ctx, value)\n")
527 fmt.Fprintf(buf, "}\n\n")
528 return nil
529}
530
531// generateReadWithTypeInfoMethod generates the ReadWithTypeInfo method
532func generateReadWithTypeInfoMethod(buf *bytes.Buffer, s *StructInfo) error {

Callers 1

generateStructSerializerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected