generateWriteTyped generates the strongly-typed WriteData method
(buf *bytes.Buffer, s *StructInfo)
| 27 | |
| 28 | // generateWriteTyped generates the strongly-typed WriteData method |
| 29 | func generateWriteTyped(buf *bytes.Buffer, s *StructInfo) error { |
| 30 | fmt.Fprintf(buf, "// WriteTyped provides strongly-typed serialization with no reflection overhead\n") |
| 31 | fmt.Fprintf(buf, "func (g *%s_ForyGenSerializer) WriteTyped(ctx *fory.WriteContext, v *%s) error {\n", s.Name, s.Name) |
| 32 | fmt.Fprintf(buf, "\tbuf := ctx.Buffer()\n") |
| 33 | |
| 34 | // WriteData struct hash |
| 35 | fmt.Fprintf(buf, "\t// WriteData struct hash for compatibility checking\n") |
| 36 | fmt.Fprintf(buf, "\tbuf.WriteInt32(g.structHash)\n\n") |
| 37 | |
| 38 | // WriteData fields in sorted order |
| 39 | fmt.Fprintf(buf, "\t// WriteData fields in sorted order\n") |
| 40 | for _, field := range s.Fields { |
| 41 | if err := generateFieldWriteTyped(buf, field); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | fmt.Fprintf(buf, "\treturn nil\n") |
| 47 | fmt.Fprintf(buf, "}\n\n") |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | // generateWriteInterface generates interface compatibility method (WriteData) |
| 52 | func generateWriteInterface(buf *bytes.Buffer, s *StructInfo) error { |
no test coverage detected