-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[C#] Optional Scalars #6217
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
[C#] Optional Scalars #6217
Conversation
|
Ran |
|
Implements #6014 in C#. |
We haven't discussed what to do about mutation w.r.t optional scalars. I agree, we should have a way to set the vtable entry to 0 in all languages. This probably would be a one way operation that "leaks memory" inside the buffer, unless the mutation API remembers where the scalar used to be. |
aardappel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this fits C# rather nicely!
I don't think we need to be worried about auto-boxing, since a scalar nullable in C# is equivalent to a struct I presume (value type) whereas the problem in Java was that it became a dynamic memory allocation.
As for mutation: the existing mutation API already doesn't support setting a value that is not present (and it returns false). While the reverse is in theory slightly easier the problem of shared vtables persists, so for consistency I would suggest that this is simply not possible.
|
@CasperN Didnt' know if you wanted to look over things since this is your feature, if not I can submit. |
|
Looks good to me! |
C# implementation of Optional Scalars using Nullable value types (Nullable or T?).
Modified the FlatBufferBuilder library to add methods that handle the Scalar Nullables, and had the code gen use these new methods. I toyed with the idea of doing the same logic in the generated code, but thought I could better test by moving that logic to the library.
This does auto-box the values, so we might want to do what was done in #6212 with emitting
hasMaybe()methods.Much credit to @paulovap for his Java implementation and tests (#6212).
I had a general question about optional scalars, what happens if you write a value to the field, but later want to set it to 'null'. I didn't see a good way to reset the vtable entry to = 0, do we need to add methods to do this in all languages? @aardappel @CasperN