Closed andrewcox closed 6 years ago
Does the IDL parser parse the optional keyword correctly?
Yes
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.
In thrift IDL, the "optional" keyword applied to a struct field means that the writer will not serialize the optional value if it is not set, and the reader side will fill in the field with the default value declared in the IDL, or the default for the type if there was no declared default. The reader will have a way to tell if the writer set the field or not.
Currently, swift lets you set a field to null, and when that field is null, the writer will not write the value. The reader will see a null when reading the type. But this leaves a couple of very minor gaps:
Someday it might be nice to add an Optional type, that acts like guava Optional except that it has a "orDefault()" method that would return the set value or the default. The sender could then not send if isPresent()==false, and the receiver could use orDefault() to get the effective value, while using isPresent() to determine whether the value was received from the sender or not.