diff options
Diffstat (limited to 'src/google/protobuf/util/field_mask_util.h')
-rw-r--r-- | src/google/protobuf/util/field_mask_util.h | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h index f0299de9..7031442d 100644 --- a/src/google/protobuf/util/field_mask_util.h +++ b/src/google/protobuf/util/field_mask_util.h @@ -39,24 +39,26 @@ #include <google/protobuf/field_mask.pb.h> #include <google/protobuf/stubs/stringpiece.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace util { -class LIBPROTOBUF_EXPORT FieldMaskUtil { +class PROTOBUF_EXPORT FieldMaskUtil { typedef google::protobuf::FieldMask FieldMask; public: // Converts FieldMask to/from string, formatted by separating each path // with a comma (e.g., "foo_bar,baz.quz"). - static string ToString(const FieldMask& mask); + static std::string ToString(const FieldMask& mask); static void FromString(StringPiece str, FieldMask* 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 ToJsonString(const FieldMask& mask, string* out); + static bool ToJsonString(const FieldMask& mask, std::string* out); static bool FromJsonString(StringPiece str, FieldMask* out); // Get the descriptors of the fields which the given path from the message @@ -96,14 +98,18 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { template <typename T> static FieldMask GetFieldMaskForAllFields() { FieldMask out; - InternalGetFieldMaskForAllFields(T::descriptor(), &out); + GetFieldMaskForAllFields(T::descriptor(), &out); return out; } template <typename T> - PROTOBUF_RUNTIME_DEPRECATED("Use *out = GetFieldMaskForAllFields() instead") + PROTOBUF_DEPRECATED_MSG("Use *out = GetFieldMaskForAllFields() instead") static void GetFieldMaskForAllFields(FieldMask* out) { - InternalGetFieldMaskForAllFields(T::descriptor(), out); + GetFieldMaskForAllFields(T::descriptor(), out); } + // This flavor takes the protobuf type descriptor as an argument. + // Useful when the type is not known at compile time. + static void GetFieldMaskForAllFields(const Descriptor* descriptor, + FieldMask* out); // Converts a FieldMask to the canonical form. It will: // 1. Remove paths that are covered by another path. For example, @@ -124,8 +130,13 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { template <typename T> static void Subtract(const FieldMask& mask1, const FieldMask& mask2, FieldMask* out) { - InternalSubtract(T::descriptor(), mask1, mask2, out); + Subtract(T::descriptor(), mask1, mask2, out); } + // This flavor takes the protobuf type descriptor as an argument. + // Useful when the type is not known at compile time. + static void Subtract(const Descriptor* descriptor, + const FieldMask& mask1, const FieldMask& mask2, + FieldMask* out); // 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. @@ -134,21 +145,21 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { static bool IsPathInFieldMask(StringPiece path, const FieldMask& mask); class MergeOptions; - // Merges fields specified in a FieldMask into another message. See the - // comments in MergeOptions regarding compatibility with - // google/protobuf/field_mask.proto + // Merges fields specified in a FieldMask into another message. static void MergeMessageTo(const Message& source, const FieldMask& mask, const MergeOptions& options, Message* destination); class TrimOptions; // Removes from 'message' any field that is not represented in the given // FieldMask. If the FieldMask is empty, does nothing. - static void TrimMessage(const FieldMask& mask, Message* message); + // Returns true if the message is modified. + static bool TrimMessage(const FieldMask& mask, Message* message); // Removes from 'message' any field that is not represented in the given // FieldMask with customized TrimOptions. // If the FieldMask is empty, does nothing. - static void TrimMessage(const FieldMask& mask, Message* message, + // Returns true if the message is modified. + static bool TrimMessage(const FieldMask& mask, Message* message, const TrimOptions& options); private: @@ -166,7 +177,7 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { // Note that the input can contain characters not allowed in C identifiers. // For example, "foo_bar,baz_quz" will be converted to "fooBar,bazQuz" // successfully. - static bool SnakeCaseToCamelCase(StringPiece input, string* output); + static bool SnakeCaseToCamelCase(StringPiece input, std::string* output); // Converts a field name from camelCase to snake_case: // 1. Every uppercase letter is converted to lowercase with a additional // preceding "-". @@ -179,21 +190,10 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { // Note that the input can contain characters not allowed in C identifiers. // For example, "fooBar,bazQuz" will be converted to "foo_bar,baz_quz" // successfully. - static bool CamelCaseToSnakeCase(StringPiece input, string* output); - - static void InternalGetFieldMaskForAllFields(const Descriptor* descriptor, - FieldMask* out); - - static void InternalSubtract(const Descriptor* descriptor, - const FieldMask& mask1, const FieldMask& mask2, - FieldMask* out); + static bool CamelCaseToSnakeCase(StringPiece input, std::string* output); }; -// 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. -class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions { +class PROTOBUF_EXPORT FieldMaskUtil::MergeOptions { public: MergeOptions() : replace_message_fields_(false), replace_repeated_fields_(false) {} @@ -221,7 +221,7 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions { bool replace_repeated_fields_; }; -class LIBPROTOBUF_EXPORT FieldMaskUtil::TrimOptions { +class PROTOBUF_EXPORT FieldMaskUtil::TrimOptions { public: TrimOptions() : keep_required_fields_(false) {} @@ -240,6 +240,8 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil::TrimOptions { } // namespace util } // namespace protobuf - } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ |