Hacker News new | ask | show | jobs
by tantalor 3612 days ago
One case where this question is important is when you are updating a record stored by the server. You only want to send fields you are changing because the record might be huge. But then how does the server distinguish between fields you didn't set and fields you want to set back to the default? The solution is to also tell the server which fields you are changing in a separate message.

Example:

    {
      'update_record': {
        # Set foo=bar
        'foo': 'bar'
      },
      'fields_to_update': {
        'foo': true,
        # Set some_int_flag=0 (default)
        'some_int_flag': true
      }
    }
See also "Field Masks in Update Operations" https://developers.google.com/protocol-buffers/docs/referenc...
1 comments

Thanks for explaining that and for the reference. It seems like a lot of overhead for a protocol that is designed to be cheap...
There are also wrapper well known types that you can fallback to (in wrappers.proto), when you need to distinguish between, say empty string and null.