[ https://issues.apache.org/jira/browse/THRIFT-2429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13951003#comment-13951003 ]
Randy Abernethy commented on THRIFT-2429: ----------------------------------------- Hey Chris, I see where you are coming from and you are not the first to bring this up. The only mechanism to suppress serialization/transmission thrift has in IDL presently is "optional". I'm curious if we could kill two birds with one stone here, cleaning up a confusing IDL combination and meeting your needs. The semantics of default (per implementation in most languages) are: * initialize the field with the default value So the client always sends it because it is always set and the server always gets it because even if not overwritten by the client the initial default value is set on the server side in the receiving object. The optional semantics (per implementation in most languages) are: * don't send it unless it is set Default fields are always set by definition so optional is a noop on a field with a default value. What if the clearly defined behavior of optional fields with default values was: * the serializer never initializes an optional/default field, therefore optional/default fields are treated as purely optional (ignoring default values) * the deserializer always initializes optional/default fields with the default value (ignoring the optional flag) In essence this would give us all three possibilities: - To only send/receive if initialized use optional - To always send/receive the client default use default - To always receive the server default unless overridden by the client use optional/default I like this better than the compiler switch because it gives us a clear definition of optional/default and makes the interface behavior explicit in the IDL, which is where it belongs. If we begin describing interface contract features with compiler switches I think we are in trouble. Thoughts? Best, Randy > Provide option to not write default values, rely on receiver default > construction instead > ----------------------------------------------------------------------------------------- > > Key: THRIFT-2429 > URL: https://issues.apache.org/jira/browse/THRIFT-2429 > Project: Thrift > Issue Type: Improvement > Components: C++ - Compiler > Affects Versions: 0.9.1 > Reporter: Chris Stylianou > Labels: thrift > > Would there be any objections to a patch that does not write default values > (essentially the same logic as the optional attributes). This obviously > relies on the receiving application using the same IDL version to ensure the > defaults used on object construction match the senders. -- This message was sent by Atlassian JIRA (v6.2#6252)