-
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
Go optional scalars #7104
Go optional scalars #7104
Conversation
Can you generate code for optional_scalars.fbs? |
Done - not sure why I left that out of the commit |
I'm not a Go person, but the generated code generally looks good to me
This doesn't align with the other languages. We don't put scalars in the binary if the user doesn't set the field. |
That mainly only applies for the object-api - all fields still need explicit encoding using the imperative API, but with this change values are stored regardless of whether they are the default. That's what I interpreted from these statements from the feature proposal:
Sounds like I've misinterpreted though, so to be clear - the recommended approach is to leave 'non-optional' fields as-is (store only when the value is not the default or the implicit zero-default) and for fields that must always be written but may take any value, they need to be marked null in the schema, and I'll need to specify defaults in my code, migrating scalar fields to be optional instead. |
Yes, that is correct.
Yep, that's the best way.
Yeah that I meant was:
|
I see! Makes sense, thanks for the clarification - I'll update this PR to have the normal behavior for scalars and will add tests. |
b2c3164
to
808ce7f
Compare
Thanks for looking at this - I've added tests |
tests LGTM Pinging @rw, who started the go stuff |
@dbaileychess were you working on windows CI recently? FYI they seem to be broken, unrelated to this PR |
Hmm, nothing that extreme. Some dependency in our CI must have changed. Let me take a look. |
Attempting fix of CI in #7105 |
Seems to be fixed. I restarted the checks here. |
Hmm, maybe a force push is required, It is still using the old CI workflow. |
Ok, seems all checks pass and the code LGTM (with the caveat that I'm not a Go person). @chriscraws, are we good to merge? |
SGTM, thanks for reviewing |
Hi, I'm taking a first pass at adding support for optional scalars to Go.
#6471
#6014
I haven't authored tests yet, but will do so if this approach seems reasonable!
Essentially the changes are the following:
*type
instead oftype
for the object-api and the normal functional API.Example getter:
Example setter
Example setter for non-optional type: