Skip to content
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] Support ForceDefaults #6471

Closed
chriscraws opened this issue Feb 16, 2021 · 3 comments
Closed

[Go] Support ForceDefaults #6471

chriscraws opened this issue Feb 16, 2021 · 3 comments
Labels

Comments

@chriscraws
Copy link
Contributor

Go doesn't support the ForceDefaults command, so as far as I know, there's no way to add default values to a vtable (or even zero-values for vtable entries that have no default).

Currently, the VTable methods such as PrependUint64Slot take a value to set, as well as a default value. In cases where there is no default value, the type's zero value is used:

func (b *Builder) PrependUint64Slot(o int, x, d uint64) {
	if x != d {
		b.PrependUint64(x)
		b.Slot(o)
	}
}

The generated code has no way of not providing a default value d.

My proposal is to modify the condition from x != d to b.forceDefaults || x != d and to add a ForceDefaults(b bool) method to the Builder struct to set the new variable. Happy to provide a pull request.

@aardappel
Copy link
Collaborator

force_defaults as in C++ has always been a bit of a hack, and not the way FlatBuffers is intended to be used.

We now have a much better way of doing this on a per-field basis: #6014
So the best way forward would be to implement this functionality in Go.
@CasperN

@CasperN
Copy link
Collaborator

CasperN commented Feb 19, 2021

Yep, I agree. This looks like the optional scalars feature in #6014. It hasn't been implemented in Go since the main maintainer has been unavailable. I recommend implementing that design if you choose to you PR. I'll be happy to review it. The issue is super long but I tried to keep a summary in the top comment along with links to implementations.

@github-actions
Copy link

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants