| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // Defines utilities for the FieldMask well known type. |
| 32 |
| 31 #ifndef GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ | 33 #ifndef GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ |
| 32 #define GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ | 34 #define GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ |
| 33 | 35 |
| 34 #include <string> | 36 #include <string> |
| 35 | 37 |
| 36 #include <google/protobuf/descriptor.h> | 38 #include <google/protobuf/descriptor.h> |
| 37 #include <google/protobuf/field_mask.pb.h> | 39 #include <google/protobuf/field_mask.pb.h> |
| 38 #include <google/protobuf/stubs/stringpiece.h> | 40 #include <google/protobuf/stubs/stringpiece.h> |
| 39 | 41 |
| 40 namespace google { | 42 namespace google { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 102 |
| 101 // Creates an intersection of two FieldMasks. | 103 // Creates an intersection of two FieldMasks. |
| 102 static void Intersect(const FieldMask& mask1, const FieldMask& mask2, | 104 static void Intersect(const FieldMask& mask1, const FieldMask& mask2, |
| 103 FieldMask* out); | 105 FieldMask* out); |
| 104 | 106 |
| 105 // Returns true if path is covered by the given FieldMask. Note that path | 107 // Returns true if path is covered by the given FieldMask. Note that path |
| 106 // "foo.bar" covers all paths like "foo.bar.baz", "foo.bar.quz.x", etc. | 108 // "foo.bar" covers all paths like "foo.bar.baz", "foo.bar.quz.x", etc. |
| 107 static bool IsPathInFieldMask(StringPiece path, const FieldMask& mask); | 109 static bool IsPathInFieldMask(StringPiece path, const FieldMask& mask); |
| 108 | 110 |
| 109 class MergeOptions; | 111 class MergeOptions; |
| 110 // Merges fields specified in a FieldMask into another message. | 112 // Merges fields specified in a FieldMask into another message. See the |
| 113 // comments in MergeOptions regarding compatibility with |
| 114 // google/protobuf/field_mask.proto |
| 111 static void MergeMessageTo(const Message& source, const FieldMask& mask, | 115 static void MergeMessageTo(const Message& source, const FieldMask& mask, |
| 112 const MergeOptions& options, Message* destination); | 116 const MergeOptions& options, Message* destination); |
| 113 | 117 |
| 118 // Removes from 'message' any field that is not represented in the given |
| 119 // FieldMask. If the FieldMask is empty, does nothing. |
| 120 static void TrimMessage(const FieldMask& mask, Message* message); |
| 121 |
| 114 private: | 122 private: |
| 115 friend class SnakeCaseCamelCaseTest; | 123 friend class SnakeCaseCamelCaseTest; |
| 116 // Converts a field name from snake_case to camelCase: | 124 // Converts a field name from snake_case to camelCase: |
| 117 // 1. Every character after "_" will be converted to uppercase. | 125 // 1. Every character after "_" will be converted to uppercase. |
| 118 // 2. All "_"s are removed. | 126 // 2. All "_"s are removed. |
| 119 // The conversion will fail if: | 127 // The conversion will fail if: |
| 120 // 1. The field name contains uppercase letters. | 128 // 1. The field name contains uppercase letters. |
| 121 // 2. Any character after a "_" is not a lowercase letter. | 129 // 2. Any character after a "_" is not a lowercase letter. |
| 122 // If the conversion succeeds, it's guaranteed that the resulted | 130 // If the conversion succeeds, it's guaranteed that the resulted |
| 123 // camelCase name will yield the original snake_case name when | 131 // camelCase name will yield the original snake_case name when |
| (...skipping 17 matching lines...) Expand all Loading... |
| 141 // successfully. | 149 // successfully. |
| 142 static bool CamelCaseToSnakeCase(StringPiece input, string* output); | 150 static bool CamelCaseToSnakeCase(StringPiece input, string* output); |
| 143 | 151 |
| 144 static bool InternalIsValidPath(const Descriptor* descriptor, | 152 static bool InternalIsValidPath(const Descriptor* descriptor, |
| 145 StringPiece path); | 153 StringPiece path); |
| 146 | 154 |
| 147 static void InternalGetFieldMaskForAllFields(const Descriptor* descriptor, | 155 static void InternalGetFieldMaskForAllFields(const Descriptor* descriptor, |
| 148 FieldMask* out); | 156 FieldMask* out); |
| 149 }; | 157 }; |
| 150 | 158 |
| 159 // Note that for compatibility with the defined behaviour for FieldMask in |
| 160 // google/protobuf/field_mask.proto, set replace_message_fields and |
| 161 // replace_repeated_fields to 'true'. The default options are not compatible |
| 162 // with google/protobuf/field_mask.proto. |
| 151 class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions { | 163 class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions { |
| 152 public: | 164 public: |
| 153 MergeOptions() | 165 MergeOptions() |
| 154 : replace_message_fields_(false), replace_repeated_fields_(false) {} | 166 : replace_message_fields_(false), replace_repeated_fields_(false) {} |
| 155 // When merging message fields, the default behavior is to merge the | 167 // When merging message fields, the default behavior is to merge the |
| 156 // content of two message fields together. If you instead want to use | 168 // content of two message fields together. If you instead want to use |
| 157 // the field from the source message to replace the corresponding field | 169 // the field from the source message to replace the corresponding field |
| 158 // in the destination message, set this flag to true. When this flag is set, | 170 // in the destination message, set this flag to true. When this flag is set, |
| 159 // specified submessage fields that are missing in source will be cleared in | 171 // specified submessage fields that are missing in source will be cleared in |
| 160 // destination. | 172 // destination. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 174 private: | 186 private: |
| 175 bool replace_message_fields_; | 187 bool replace_message_fields_; |
| 176 bool replace_repeated_fields_; | 188 bool replace_repeated_fields_; |
| 177 }; | 189 }; |
| 178 | 190 |
| 179 } // namespace util | 191 } // namespace util |
| 180 } // namespace protobuf | 192 } // namespace protobuf |
| 181 | 193 |
| 182 } // namespace google | 194 } // namespace google |
| 183 #endif // GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ | 195 #endif // GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ |
| OLD | NEW |