You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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.
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:The generated code has no way of not providing a default value
d
.My proposal is to modify the condition from
x != d
tob.forceDefaults || x != d
and to add aForceDefaults(b bool)
method to theBuilder
struct to set the new variable. Happy to provide a pull request.The text was updated successfully, but these errors were encountered: