field_mask_util.h

#include <google/protobuf/util/field_mask_util.h>
namespace google::protobuf::util

Defines utilities for the FieldMask well known type.

Classes in this file

Note that for compatibility with the defined behaviour for FieldMask in google/protobuf/field_mask.proto, set replace_message_fields and replace_repeated_fields to 'true'.

class FieldMaskUtil

#include <google/protobuf/util/field_mask_util.h>
namespace google::protobuf::util

Members

static string
ToString(const FieldMask & mask)
Converts FieldMask to/from string, formatted by separating each path with a comma (e.g., "foo_bar,baz.quz").
static void
FromString(StringPiece str, FieldMask * out)
static bool
ToJsonString(const FieldMask & mask, string * out)
Converts FieldMask to/from string, formatted according to proto3 JSON spec for FieldMask (e.g., "fooBar,baz.quz"). more...
static bool
FromJsonString(StringPiece str, FieldMask * out)
static bool
GetFieldDescriptors(const Descriptor * descriptor, StringPiece path, std::vector< const FieldDescriptor * > * field_descriptors)
Get the descriptors of the fields which the given path from the message descriptor traverses, if field_descriptors is not null. more...
template static bool
IsValidPath(StringPiece path)
Checks whether the given path is valid for type T.
template static bool
IsValidFieldMask(const FieldMask & mask)
Checks whether the given FieldMask is valid for type T.
template static void
AddPathToFieldMask(StringPiece path, FieldMask * mask)
Adds a path to FieldMask after checking whether the given path is valid. more...
template static void
GetFieldMaskForAllFields(FieldMask * out)
Creates a FieldMask with all fields of type T. more...
static void
ToCanonicalForm(const FieldMask & mask, FieldMask * out)
Converts a FieldMask to the canonical form. more...
static void
Union(const FieldMask & mask1, const FieldMask & mask2, FieldMask * out)
Creates an union of two FieldMasks.
static void
Intersect(const FieldMask & mask1, const FieldMask & mask2, FieldMask * out)
Creates an intersection of two FieldMasks.
static bool
IsPathInFieldMask(StringPiece path, const FieldMask & mask)
Returns true if path is covered by the given FieldMask. more...
static void
MergeMessageTo(const Message & source, const FieldMask & mask, const MergeOptions & options, Message * destination)
Merges fields specified in a FieldMask into another message. more...
static void
TrimMessage(const FieldMask & mask, Message * message)
Removes from 'message' any field that is not represented in the given FieldMask. more...

static bool FieldMaskUtil::ToJsonString(
        const FieldMask & mask,
        string * out)

Converts FieldMask to/from string, formatted according to proto3 JSON spec for FieldMask (e.g., "fooBar,baz.quz").

If the field name is not style conforming (i.e., not snake_case when converted to string, or not camelCase when converted from string), the conversion will fail.


static bool FieldMaskUtil::GetFieldDescriptors(
        const Descriptor * descriptor,
        StringPiece path,
        std::vector< const FieldDescriptor * > * field_descriptors)

Get the descriptors of the fields which the given path from the message descriptor traverses, if field_descriptors is not null.

Return false if the path is not valid, and the content of field_descriptors is unspecified.


template static void FieldMaskUtil::AddPathToFieldMask(
        StringPiece path,
        FieldMask * mask)

Adds a path to FieldMask after checking whether the given path is valid.

This method check-fails if the path is not a valid path for type T.


template static void FieldMaskUtil::GetFieldMaskForAllFields(
        FieldMask * out)

Creates a FieldMask with all fields of type T.

This FieldMask only contains fields of T but not any sub-message fields.


static void FieldMaskUtil::ToCanonicalForm(
        const FieldMask & mask,
        FieldMask * out)

Converts a FieldMask to the canonical form.

It will:

1. Remove paths that are covered by another path. For example,
   "foo.bar" is covered by "foo" and will be removed if "foo"
   is also in the FieldMask.
2. Sort all paths in alphabetical order.

static bool FieldMaskUtil::IsPathInFieldMask(
        StringPiece path,
        const FieldMask & mask)

Returns true if path is covered by the given FieldMask.

Note that path "foo.bar" covers all paths like "foo.bar.baz", "foo.bar.quz.x", etc.


static void FieldMaskUtil::MergeMessageTo(
        const Message & source,
        const FieldMask & mask,
        const MergeOptions & options,
        Message * destination)

Merges fields specified in a FieldMask into another message.

See the comments in MergeOptions regarding compatibility with google/protobuf/field_mask.proto


static void FieldMaskUtil::TrimMessage(
        const FieldMask & mask,
        Message * message)

Removes from 'message' any field that is not represented in the given FieldMask.

If the FieldMask is empty, does nothing.

class FieldMaskUtil::MergeOptions

#include <google/protobuf/util/field_mask_util.h>
namespace google::protobuf::util

Note that for compatibility with the defined behaviour for FieldMask in google/protobuf/field_mask.proto, set replace_message_fields and replace_repeated_fields to 'true'.

The default options are not compatible with google/protobuf/field_mask.proto.

Members

MergeOptions()
void
set_replace_message_fields(bool value)
When merging message fields, the default behavior is to merge the content of two message fields together. more...
bool
replace_message_fields() const
void
set_replace_repeated_fields(bool value)
The default merging behavior will append entries from the source repeated field to the destination repeated field. more...
bool
replace_repeated_fields() const

void MergeOptions::set_replace_message_fields(
        bool value)

When merging message fields, the default behavior is to merge the content of two message fields together.

If you instead want to use the field from the source message to replace the corresponding field in the destination message, set this flag to true. When this flag is set, specified submessage fields that are missing in source will be cleared in destination.


void MergeOptions::set_replace_repeated_fields(
        bool value)

The default merging behavior will append entries from the source repeated field to the destination repeated field.

If you only want to keep the entries from the source repeated field, set this flag to true.