-
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
HasNullDefault in TypeScript returns null for 0 scalar value input #7395
Comments
Seem like a bug to me. I have vague memory of it being noted in the past but as of yet I've been unable to find anything. I suppose changing this behaviour could potentially be seen as a breaking change, but I think it's likely no one is dependent on that so I think we should just try to find a sensible fix as a patch release. |
It would be good/interesting to find out if this was also the behavior pre TS port (i.e Flatbuffers 1.x). |
I have been looking at this since I posted the issue, hard to think of a portable solution that won’t effect parsing flatbuffers in other languages. The main issue is there doesn’t seem to be a |
I should have read those more closely and then linked them to this issue, thanks. Very strange this was implemented without a |
@TJKoury not sure I agree, it's clear that the intent is that if you describe a scalar type as optional (with |
The issue in this case is that it appears that in all languages an offset of zero is equivalent to zero scalar, to save wire space as you say. To change the interpretation of zero offset to mean “null” in the case of an optional null field would encode that meaning into the flatbuffer without a way to interpret it cross-language. I suppose that’s true now with simply failing to compile in unsupported languages. We could store the default offset for the scalar with a value of |
@TJKoury but the change to make that interpretation has already been done in most implementations? I don't see how it affect the encoding, it's simply a interpretation (schema generated code) change and I don't understand your claim that it's "without a way to interpret cross-lang". |
It seems most implementations regard a zero offset as the value zero, right? |
Picking this back up, I'm going to remove using
|
This issue is stale because it has been open 6 months with no activity. Please comment or label |
This issue was automatically closed due to no activity for 6 months plus the 14 day notice period. |
Flatbuffers 2.0.5
Compiled to WASM (link)
Chrome Version 1.38.111
The offset check here will return
null
for offset0
if theHasNullDefault
flag is set for a property.Setting a
0
value for a scalar results in offset being set to0
, which means a zero can't be stored in an property that can benull
.The text was updated successfully, but these errors were encountered: