-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with default values in Go library #7100
Comments
Flatbuffers has an optimization where if the default value is set, we skip writing the value in the binary. This also means it cannot be mutated, since mutation works by modifying an existing value in place and you can't do that if it's simply not there. If you require mutation, I suggest making the default some sentinel value, e.g. -1, and always initialize this inside your application. You could also rebuild the flatbuffer if the code isn't performance sensitive. If you weren't using Go, #6014 allows you to use |
My problem was solved by removing default value from schema. I think, this behaviour is not explicit. In such cases it is required to define default values outside of schema. |
Cool, resolving. Note that removing the default value from the schema makes the default value implicitly zero, so if you fail to initialize
I agree that this behavior is mysterious/complex but its the result of organic evolution and our commitment to not having breaking changes in the binary format or schema language. The in-place mutation API came after the default-elision thing. For what its worth the tutorial does advise on this in the mutation API section
|
Mutation methods in Go library do not apply if default value is set. There was the same issue in C++ library, but it looks line it is not still fixed in Go. I use go1.17 and the latest flatbuffers.
Here is some examples:
The text was updated successfully, but these errors were encountered: