| OLD | NEW |
| (Empty) | |
| 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ |
| 4 // |
| 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are |
| 7 // met: |
| 8 // |
| 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the |
| 14 // distribution. |
| 15 // * Neither the name of Google Inc. nor the names of its |
| 16 // contributors may be used to endorse or promote products derived from |
| 17 // this software without specific prior written permission. |
| 18 // |
| 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 30 |
| 31 #ifndef GOOGLE_PROTOBUF_UTIL_UNKNOWN_ENUM_IMPL_H__ |
| 32 #define GOOGLE_PROTOBUF_UTIL_UNKNOWN_ENUM_IMPL_H__ |
| 33 |
| 34 #include <stdlib.h> |
| 35 |
| 36 #include <google/protobuf/stubs/common.h> |
| 37 #include "net/proto/tagmapper.h" |
| 38 #include <google/protobuf/bridge/compatibility_mode_support.h> |
| 39 |
| 40 namespace google { |
| 41 namespace protobuf { |
| 42 |
| 43 // google/protobuf/message.h |
| 44 class Message; |
| 45 |
| 46 namespace util { |
| 47 |
| 48 // NOTE: You should not call these functions directly. Instead use either |
| 49 // HAS_UNKNOWN_ENUM() or GET_UNKNOWN_ENUM(), defined in the public header. |
| 50 // The macro-versions operate in a type-safe manner and behave appropriately |
| 51 // for the proto version of the message, whereas these versions assume a |
| 52 // specific proto version and allow the caller to pass in any arbitrary integer |
| 53 // value as a field number. |
| 54 // |
| 55 // Returns whether the message has unrecognized the enum value for a given |
| 56 // field. It also stores the value into the unknown_value parameter if the |
| 57 // function returns true and the pointer is not NULL. |
| 58 // |
| 59 // In proto2, invalid enum values will be treated as unknown fields. This |
| 60 // function checks that case. |
| 61 bool HasUnknownEnum(const Message& message, int32 field_number, |
| 62 int32* unknown_value = nullptr); |
| 63 // Same as above, but returns all unknown enums. |
| 64 bool GetRepeatedEnumUnknowns(const Message& message, int32 field_number, |
| 65 vector<int32>* unknown_values = nullptr); |
| 66 // In proto1, invalue enum values are stored in the same way as valid enum |
| 67 // values. |
| 68 // TODO(karner): Delete this once the migration to proto2 is complete. |
| 69 bool HasUnknownEnumProto1(const Message& message, int32 field_number, |
| 70 int32* unknown_value); |
| 71 // Same as above, but returns all unknown enums. |
| 72 bool GetRepeatedEnumUnknownsProto1(const Message& message, int32 field_number, |
| 73 vector<int32>* unknown_values); |
| 74 // Invokes the appropriate version based on whether the message is proto1 |
| 75 // or proto2. |
| 76 template <typename T> |
| 77 bool HasUnknownEnum_Template(const T& message, int32 field_number, |
| 78 int32* unknown_value = nullptr) { |
| 79 if (internal::is_base_of<bridge::internal::Proto1CompatibleMessage, T>::value
|| |
| 80 !internal::is_base_of<ProtocolMessage, T>::value) { |
| 81 return HasUnknownEnum(message, field_number, unknown_value); |
| 82 } else { |
| 83 return HasUnknownEnumProto1(message, field_number, unknown_value); |
| 84 } |
| 85 } |
| 86 // Invokes the appropriate version based on whether the message is proto1 |
| 87 // or proto2. |
| 88 template <typename T> |
| 89 bool GetRepeatedEnumUnknowns_Template( |
| 90 const T& message, int32 field_number, |
| 91 vector<int32>* unknown_values = nullptr) { |
| 92 if (internal::is_base_of<bridge::internal::Proto1CompatibleMessage, T>::value
|| |
| 93 !internal::is_base_of<ProtocolMessage, T>::value) { |
| 94 return GetRepeatedEnumUnknowns(message, field_number, unknown_values); |
| 95 } else { |
| 96 return GetRepeatedEnumUnknownsProto1(message, field_number, |
| 97 unknown_values); |
| 98 } |
| 99 } |
| 100 |
| 101 // NOTE: You should not call these functions directly. Instead use |
| 102 // CLEAR_UNKNOWN_ENUM(), defined in the public header. The macro-versions |
| 103 // operate in a type-safe manner and behave appropriately for the proto |
| 104 // version of the message, whereas these versions assume a specific proto |
| 105 // version and allow the caller to pass in any arbitrary integer value as a |
| 106 // field number. |
| 107 // |
| 108 // Clears the unknown entries of the given field of the message. |
| 109 void ClearUnknownEnum(Message* message, int32 field_number); |
| 110 // In proto1, clears the field if the value is out of range. |
| 111 // TODO(karner): Delete this or make it proto2-only once the migration |
| 112 // to proto2 is complete. |
| 113 void ClearUnknownEnumProto1(Message* message, int32 field_number); |
| 114 template <typename T> |
| 115 void ClearUnknownEnum_Template(T* message, int32 field_number) { |
| 116 if (internal::is_base_of<bridge::internal::Proto1CompatibleMessage, T>::value
|| |
| 117 !internal::is_base_of<ProtocolMessage, T>::value) { |
| 118 ClearUnknownEnum(message, field_number); |
| 119 } else { |
| 120 ClearUnknownEnumProto1(message, field_number); |
| 121 } |
| 122 } |
| 123 |
| 124 // NOTE: You should not call these functions directly. Instead use |
| 125 // SET_UNKNOWN_ENUM(), defined in the public header. The macro-versions |
| 126 // operate in a type-safe manner and behave appropriately for the proto |
| 127 // version of the message, whereas these versions assume a specific proto |
| 128 // version and allow the caller to pass in any arbitrary integer value as a |
| 129 // field number. |
| 130 // |
| 131 // Sets the given value in the unknown fields of the message. |
| 132 void SetUnknownEnum(Message* message, int32 field_number, int32 unknown_value); |
| 133 // In proto1, invalue enum values are stored in the same way as valid enum |
| 134 // values. |
| 135 // TODO(karner): Delete this once the migration to proto2 is complete. |
| 136 void SetUnknownEnumProto1(Message* message, int32 field_number, |
| 137 int32 unknown_value); |
| 138 // Invokes the appropriate version based on whether the message is proto1 |
| 139 // or proto2. |
| 140 template <typename T> |
| 141 void SetUnknownEnum_Template(T* message, int32 field_number, |
| 142 int32 unknown_value) { |
| 143 if (internal::is_base_of<bridge::internal::Proto1CompatibleMessage, T>::value
|| |
| 144 !internal::is_base_of<ProtocolMessage, T>::value) { |
| 145 SetUnknownEnum(message, field_number, unknown_value); |
| 146 } else { |
| 147 SetUnknownEnumProto1(message, field_number, unknown_value); |
| 148 } |
| 149 } |
| 150 |
| 151 } // namespace util |
| 152 } // namespace protobuf |
| 153 |
| 154 } // namespace google |
| 155 #endif // GOOGLE_PROTOBUF_UTIL_UNKNOWN_ENUM_IMPL_H__ |
| OLD | NEW |