Question about google.protobuf.FieldMask in update operations

32 views
Skip to first unread message

Shouichi Kamiya

unread,
Aug 28, 2019, 9:14:44 PM8/28/19
to Protocol Buffers
The following block is the excerpt from google.protobuf.FieldMask.

// # Field Masks in Update Operations
//
// A field mask in update operations specifies which fields of the
// targeted resource are going to be updated. The API is required
// to only change the values of the fields as specified in the mask
// and leave the others untouched. If a resource is passed in to
// describe the updated values, the API ignores the values of all
// fields not covered by the mask.
//
// If a repeated field is specified for an update operation, new values will
// be appended to the existing repeated field in the target resource. Note that
// a repeated field is only allowed in the last position of a `paths` string.
//
// If a sub-message is specified in the last position of the field mask for an
// update operation, then new value will be merged into the existing sub-message
// in the target resource.
//
// For example, given the target message:
//
//     f {
//       b {
//         d: 1
//         x: 2
//       }
//       c: [1]
//     }
//
// And an update message:
//
//     f {
//       b {
//         d: 10
//       }
//       c: [2]
//     }
//
// then if the field mask is:
//
//  paths: ["f.b", "f.c"]
//
// then the result will be:
//
//     f {
//       b {
//         d: 10
//         x: 2
//       }
//       c: [1, 2]
//     }

In the example, the field `f.b.x` is unchanged after merge. Is this behavior
possible in proto3? Because `f.b.x` is an integer and whether `f.b.x` is absent
or is the zero value cannot be distinguished.

Thank you
Reply all
Reply to author
Forward
0 new messages