temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 2 | // Copyright 2008 Google Inc. All rights reserved. |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 3 | // https://developers.google.com/protocol-buffers/ |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 4 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 8 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 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. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 18 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 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. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 30 | |
| 31 | // Author: kenton@google.com (Kenton Varda) |
| 32 | // Based on original Protocol Buffers design by |
| 33 | // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | // |
| 35 | // Contains classes used to keep track of unrecognized fields seen while |
| 36 | // parsing a protocol message. |
| 37 | |
| 38 | #ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ |
| 39 | #define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ |
| 40 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 41 | #include <assert.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 42 | #include <string> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 43 | #include <vector> |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 44 | #include <google/protobuf/stubs/common.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 45 | |
| 46 | namespace google { |
| 47 | namespace protobuf { |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 48 | namespace io { |
| 49 | class CodedInputStream; // coded_stream.h |
| 50 | class CodedOutputStream; // coded_stream.h |
| 51 | class ZeroCopyInputStream; // zero_copy_stream.h |
| 52 | } |
| 53 | namespace internal { |
| 54 | class WireFormat; // wire_format.h |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 55 | class MessageSetFieldSkipperUsingCord; |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 56 | // extension_set_heavy.cc |
| 57 | } |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 58 | |
| 59 | class Message; // message.h |
| 60 | class UnknownField; // below |
| 61 | |
| 62 | // An UnknownFieldSet contains fields that were encountered while parsing a |
| 63 | // message but were not defined by its type. Keeping track of these can be |
| 64 | // useful, especially in that they may be written if the message is serialized |
| 65 | // again without being cleared in between. This means that software which |
| 66 | // simply receives messages and forwards them to other servers does not need |
| 67 | // to be updated every time a new field is added to the message definition. |
| 68 | // |
| 69 | // To get the UnknownFieldSet attached to any message, call |
temporal | 779f61c | 2008-08-13 03:15:00 +0000 | [diff] [blame] | 70 | // Reflection::GetUnknownFields(). |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 71 | // |
| 72 | // This class is necessarily tied to the protocol buffer wire format, unlike |
| 73 | // the Reflection interface which is independent of any serialization scheme. |
| 74 | class LIBPROTOBUF_EXPORT UnknownFieldSet { |
| 75 | public: |
| 76 | UnknownFieldSet(); |
| 77 | ~UnknownFieldSet(); |
| 78 | |
| 79 | // Remove all fields. |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 80 | inline void Clear(); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 81 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 82 | // Remove all fields and deallocate internal data objects |
| 83 | void ClearAndFreeMemory(); |
| 84 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 85 | // Is this set empty? |
| 86 | inline bool empty() const; |
| 87 | |
| 88 | // Merge the contents of some other UnknownFieldSet with this one. |
| 89 | void MergeFrom(const UnknownFieldSet& other); |
| 90 | |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 91 | // Similar to above, but this function will destroy the contents of other. |
| 92 | void MergeFromAndDestroy(UnknownFieldSet* other); |
| 93 | |
kenton@google.com | 26bd9ee | 2008-11-21 00:06:27 +0000 | [diff] [blame] | 94 | // Swaps the contents of some other UnknownFieldSet with this one. |
| 95 | inline void Swap(UnknownFieldSet* x); |
| 96 | |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 97 | // Computes (an estimate of) the total number of bytes currently used for |
| 98 | // storing the unknown fields in memory. Does NOT include |
| 99 | // sizeof(*this) in the calculation. |
| 100 | int SpaceUsedExcludingSelf() const; |
| 101 | |
| 102 | // Version of SpaceUsed() including sizeof(*this). |
| 103 | int SpaceUsed() const; |
| 104 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 105 | // Returns the number of fields present in the UnknownFieldSet. |
| 106 | inline int field_count() const; |
| 107 | // Get a field in the set, where 0 <= index < field_count(). The fields |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 108 | // appear in the order in which they were added. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 109 | inline const UnknownField& field(int index) const; |
| 110 | // Get a mutable pointer to a field in the set, where |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 111 | // 0 <= index < field_count(). The fields appear in the order in which |
| 112 | // they were added. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 113 | inline UnknownField* mutable_field(int index); |
| 114 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 115 | // Adding fields --------------------------------------------------- |
| 116 | |
| 117 | void AddVarint(int number, uint64 value); |
| 118 | void AddFixed32(int number, uint32 value); |
| 119 | void AddFixed64(int number, uint64 value); |
| 120 | void AddLengthDelimited(int number, const string& value); |
| 121 | string* AddLengthDelimited(int number); |
| 122 | UnknownFieldSet* AddGroup(int number); |
| 123 | |
| 124 | // Adds an unknown field from another set. |
| 125 | void AddField(const UnknownField& field); |
| 126 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 127 | // Delete fields with indices in the range [start .. start+num-1]. |
| 128 | // Caution: implementation moves all fields with indices [start+num .. ]. |
| 129 | void DeleteSubrange(int start, int num); |
| 130 | |
| 131 | // Delete all fields with a specific field number. The order of left fields |
| 132 | // is preserved. |
| 133 | // Caution: implementation moves all fields after the first deleted field. |
| 134 | void DeleteByNumber(int number); |
| 135 | |
temporal | a0f27fc | 2008-08-06 01:12:21 +0000 | [diff] [blame] | 136 | // Parsing helpers ------------------------------------------------- |
| 137 | // These work exactly like the similarly-named methods of Message. |
| 138 | |
| 139 | bool MergeFromCodedStream(io::CodedInputStream* input); |
| 140 | bool ParseFromCodedStream(io::CodedInputStream* input); |
| 141 | bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); |
| 142 | bool ParseFromArray(const void* data, int size); |
| 143 | inline bool ParseFromString(const string& data) { |
Feng Xiao | 84731a1 | 2014-10-03 11:13:58 -0700 | [diff] [blame] | 144 | return ParseFromArray(data.data(), static_cast<int>(data.size())); |
temporal | a0f27fc | 2008-08-06 01:12:21 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 147 | static const UnknownFieldSet* default_instance(); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 148 | private: |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 149 | // For InternalMergeFrom |
| 150 | friend class UnknownField; |
| 151 | // Merges from other UnknownFieldSet. This method assumes, that this object |
| 152 | // is newly created and has fields_ == NULL; |
| 153 | void InternalMergeFrom(const UnknownFieldSet& other); |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 154 | void ClearFallback(); |
| 155 | |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 156 | // fields_ is either NULL, or a pointer to a vector that is *non-empty*. We |
| 157 | // never hold the empty vector because we want the 'do we have any unknown |
| 158 | // fields' check to be fast, and avoid a cache miss: the UFS instance gets |
| 159 | // embedded in the message object, so 'fields_ != NULL' tests a member |
| 160 | // variable hot in the cache, without the need to go touch a vector somewhere |
| 161 | // else in memory. |
Fabrice de Gans-Riberi | 98db495 | 2014-11-03 13:45:55 +0100 | [diff] [blame] | 162 | std::vector<UnknownField>* fields_; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 163 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet); |
| 164 | }; |
| 165 | |
| 166 | // Represents one field in an UnknownFieldSet. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 167 | class LIBPROTOBUF_EXPORT UnknownField { |
| 168 | public: |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 169 | enum Type { |
| 170 | TYPE_VARINT, |
| 171 | TYPE_FIXED32, |
| 172 | TYPE_FIXED64, |
| 173 | TYPE_LENGTH_DELIMITED, |
| 174 | TYPE_GROUP |
| 175 | }; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 176 | |
| 177 | // The field's tag number, as seen on the wire. |
| 178 | inline int number() const; |
| 179 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 180 | // The field type. |
| 181 | inline Type type() const; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 182 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 183 | // Accessors ------------------------------------------------------- |
| 184 | // Each method works only for UnknownFields of the corresponding type. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 185 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 186 | inline uint64 varint() const; |
| 187 | inline uint32 fixed32() const; |
| 188 | inline uint64 fixed64() const; |
| 189 | inline const string& length_delimited() const; |
| 190 | inline const UnknownFieldSet& group() const; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 191 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 192 | inline void set_varint(uint64 value); |
| 193 | inline void set_fixed32(uint32 value); |
| 194 | inline void set_fixed64(uint64 value); |
| 195 | inline void set_length_delimited(const string& value); |
| 196 | inline string* mutable_length_delimited(); |
| 197 | inline UnknownFieldSet* mutable_group(); |
kenton@google.com | 26bd9ee | 2008-11-21 00:06:27 +0000 | [diff] [blame] | 198 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 199 | // Serialization API. |
| 200 | // These methods can take advantage of the underlying implementation and may |
| 201 | // archieve a better performance than using getters to retrieve the data and |
| 202 | // do the serialization yourself. |
| 203 | void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const; |
| 204 | uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const; |
| 205 | |
| 206 | inline int GetLengthDelimitedSize() const; |
| 207 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 208 | private: |
| 209 | friend class UnknownFieldSet; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 210 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 211 | // If this UnknownField contains a pointer, delete it. |
| 212 | void Delete(); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 213 | |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 214 | // Reset all the underlying pointers to NULL. A special function to be only |
| 215 | // used while merging from a temporary UFS. |
| 216 | void Reset(); |
| 217 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 218 | // Make a deep copy of any pointers in this UnknownField. |
| 219 | void DeepCopy(); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 220 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 221 | // Set the wire type of this UnknownField. Should only be used when this |
| 222 | // UnknownField is being created. |
| 223 | inline void SetType(Type type); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 224 | |
Łukasz Twarduś | dd449e1 | 2014-11-25 19:25:38 +0100 | [diff] [blame] | 225 | union LengthDelimited { |
| 226 | string* string_value_; |
| 227 | }; |
| 228 | |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame^] | 229 | uint32 number_; |
| 230 | uint32 type_; |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 231 | union { |
| 232 | uint64 varint_; |
| 233 | uint32 fixed32_; |
| 234 | uint64 fixed64_; |
Łukasz Twarduś | dd449e1 | 2014-11-25 19:25:38 +0100 | [diff] [blame] | 235 | mutable union LengthDelimited length_delimited_; |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 236 | UnknownFieldSet* group_; |
| 237 | }; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | // =================================================================== |
| 241 | // inline implementations |
| 242 | |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 243 | inline void UnknownFieldSet::Clear() { |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 244 | if (fields_) { |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 245 | ClearFallback(); |
| 246 | } |
| 247 | } |
| 248 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 249 | inline bool UnknownFieldSet::empty() const { |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 250 | // Invariant: fields_ is never empty if present. |
| 251 | return !fields_; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 252 | } |
| 253 | |
kenton@google.com | 26bd9ee | 2008-11-21 00:06:27 +0000 | [diff] [blame] | 254 | inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 255 | std::swap(fields_, x->fields_); |
kenton@google.com | 26bd9ee | 2008-11-21 00:06:27 +0000 | [diff] [blame] | 256 | } |
| 257 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 258 | inline int UnknownFieldSet::field_count() const { |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 259 | return fields_ ? static_cast<int>(fields_->size()) : 0; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 260 | } |
| 261 | inline const UnknownField& UnknownFieldSet::field(int index) const { |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 262 | GOOGLE_DCHECK(fields_ != NULL); |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 263 | return (*fields_)[index]; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 264 | } |
| 265 | inline UnknownField* UnknownFieldSet::mutable_field(int index) { |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 266 | return &(*fields_)[index]; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 267 | } |
| 268 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 269 | inline void UnknownFieldSet::AddLengthDelimited( |
| 270 | int number, const string& value) { |
| 271 | AddLengthDelimited(number)->assign(value); |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 272 | } |
| 273 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 274 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 275 | inline int UnknownField::number() const { return number_; } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 276 | inline UnknownField::Type UnknownField::type() const { |
| 277 | return static_cast<Type>(type_); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 278 | } |
| 279 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 280 | inline uint64 UnknownField::varint() const { |
| 281 | assert(type() == TYPE_VARINT); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 282 | return varint_; |
| 283 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 284 | inline uint32 UnknownField::fixed32() const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 285 | assert(type() == TYPE_FIXED32); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 286 | return fixed32_; |
| 287 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 288 | inline uint64 UnknownField::fixed64() const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 289 | assert(type() == TYPE_FIXED64); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 290 | return fixed64_; |
| 291 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 292 | inline const string& UnknownField::length_delimited() const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 293 | assert(type() == TYPE_LENGTH_DELIMITED); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 294 | return *length_delimited_.string_value_; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 295 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 296 | inline const UnknownFieldSet& UnknownField::group() const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 297 | assert(type() == TYPE_GROUP); |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 298 | return *group_; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 299 | } |
| 300 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 301 | inline void UnknownField::set_varint(uint64 value) { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 302 | assert(type() == TYPE_VARINT); |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 303 | varint_ = value; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 304 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 305 | inline void UnknownField::set_fixed32(uint32 value) { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 306 | assert(type() == TYPE_FIXED32); |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 307 | fixed32_ = value; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 308 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 309 | inline void UnknownField::set_fixed64(uint64 value) { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 310 | assert(type() == TYPE_FIXED64); |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 311 | fixed64_ = value; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 312 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 313 | inline void UnknownField::set_length_delimited(const string& value) { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 314 | assert(type() == TYPE_LENGTH_DELIMITED); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 315 | length_delimited_.string_value_->assign(value); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 316 | } |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 317 | inline string* UnknownField::mutable_length_delimited() { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 318 | assert(type() == TYPE_LENGTH_DELIMITED); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 319 | return length_delimited_.string_value_; |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 320 | } |
| 321 | inline UnknownFieldSet* UnknownField::mutable_group() { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 322 | assert(type() == TYPE_GROUP); |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 323 | return group_; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 324 | } |
| 325 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 326 | inline int UnknownField::GetLengthDelimitedSize() const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 327 | GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type()); |
Feng Xiao | 84731a1 | 2014-10-03 11:13:58 -0700 | [diff] [blame] | 328 | return static_cast<int>(length_delimited_.string_value_->size()); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 329 | } |
| 330 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 331 | inline void UnknownField::SetType(Type type) { |
| 332 | type_ = type; |
| 333 | } |
| 334 | |
| 335 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 336 | } // namespace protobuf |
| 337 | |
| 338 | } // namespace google |
| 339 | #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ |