feat(Go): Implement ahead of time codegen for fory-go serialization - #2553
Conversation
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package main |
There was a problem hiding this comment.
I think the name of this file needs to be modified
|
|
||
| package codegen_tests | ||
|
|
||
| // 验证用的基本结构体 (只包含基本类型,因为PR1只支持基本类型) |
There was a problem hiding this comment.
It is more appropriate to use English annotations
| fmt.Printf(" B 匹配: %t (%s == %s)\n", bMatch, result.B, original.B) | ||
| fmt.Printf(" C 匹配: %t (%d == %d)\n", cMatch, result.C, original.C) | ||
|
|
||
| if aMatch && bMatch && cMatch { |
There was a problem hiding this comment.
This testing method is unreasonable. Please refer to other testing documents
| github.com/stretchr/objx v0.1.0 // indirect | ||
| github.com/yuin/goldmark v1.4.13 // indirect | ||
| golang.org/x/crypto v0.41.0 // indirect | ||
| golang.org/x/mod v0.27.0 // indirect |
There was a problem hiding this comment.
This import method seems not elegant enough
| module github.com/apache/fory/go/fory | ||
|
|
||
| go 1.13 | ||
| go 1.23.0 |
There was a problem hiding this comment.
Do not upgrade the version
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/spaolacci/murmur3 v1.1.0 | ||
| github.com/stretchr/testify v1.7.0 | ||
| github.com/stretchr/testify v1.6.1 |
There was a problem hiding this comment.
It seems that lowering the version makes no sense
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package main |
There was a problem hiding this comment.
I still think this name is inappropriate
There was a problem hiding this comment.
forygen.go shoudl be named as generator.go, and you should have a main.go under go/fory. And in that file, you call into this file
|
@ThisingL Please add detailed document about how to use this feature in
|
|
And we should generate some kind of compilation guard, when users update their struct definition, they must reexecute |
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| // Code generated by forygen. DO NOT EDIT. |
There was a problem hiding this comment.
this file should not be check in to github, yo ushould run go generate in ci script under ci and .github/workflows
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package codegen_tests |
There was a problem hiding this comment.
please move this test into tests, it's unnecessary to have another test package
| } | ||
|
|
||
| // Generate the strongly-typed Read method according to the doc | ||
| func generateReadTyped(buf *bytes.Buffer, s *StructInfo) error { |
There was a problem hiding this comment.
Could we make this generate more modular, and separate it into several files? the generator can be the entrance
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| //go:generate go run ../codegen/forygen.go -pkg . -type "ValidationDemo" |
There was a problem hiding this comment.
I don't think users of fory can specify like this. It's OK to have something like this to make debug more easily. But we also should have annotation like go:generate fory ....

What does this PR do?
go/codegenpackage.WriteandReadmethods for struct types to support serialization and deserialization.go:generatedirective to automate the generation of the serialization code.Note: This PR only supports basic struct types and does not yet handle
maporslicetypes.TODO
slicetypes (planned for the next PR).maptypes (planned for a future PR).Related issues
Does this PR introduce any user-facing change?
Benchmark