/src/LPM/external.protobuf/include/google/protobuf/message_lite.h
Line | Count | Source (jump to first uncovered line) |
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 | | // Authors: wink@google.com (Wink Saville), |
32 | | // kenton@google.com (Kenton Varda) |
33 | | // Based on original Protocol Buffers design by |
34 | | // Sanjay Ghemawat, Jeff Dean, and others. |
35 | | // |
36 | | // Defines MessageLite, the abstract interface implemented by all (lite |
37 | | // and non-lite) protocol message objects. |
38 | | |
39 | | #ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ |
40 | | #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ |
41 | | |
42 | | #include <climits> |
43 | | #include <iosfwd> |
44 | | #include <string> |
45 | | |
46 | | #include "google/protobuf/stubs/common.h" |
47 | | #include "google/protobuf/arena.h" |
48 | | #include "google/protobuf/port.h" |
49 | | #include "absl/base/call_once.h" |
50 | | #include "absl/log/absl_check.h" |
51 | | #include "absl/strings/cord.h" |
52 | | #include "absl/strings/string_view.h" |
53 | | #include "google/protobuf/explicitly_constructed.h" |
54 | | #include "google/protobuf/io/coded_stream.h" |
55 | | #include "google/protobuf/metadata_lite.h" |
56 | | #include "google/protobuf/port.h" |
57 | | |
58 | | |
59 | | // clang-format off |
60 | | #include "google/protobuf/port_def.inc" |
61 | | // clang-format on |
62 | | |
63 | | #ifdef SWIG |
64 | | #error "You cannot SWIG proto headers" |
65 | | #endif |
66 | | |
67 | | namespace google { |
68 | | namespace protobuf { |
69 | | |
70 | | template <typename T> |
71 | | class RepeatedPtrField; |
72 | | |
73 | | class FastReflectionMessageMutator; |
74 | | class FastReflectionStringSetter; |
75 | | class Reflection; |
76 | | |
77 | | namespace io { |
78 | | |
79 | | class CodedInputStream; |
80 | | class CodedOutputStream; |
81 | | class ZeroCopyInputStream; |
82 | | class ZeroCopyOutputStream; |
83 | | |
84 | | } // namespace io |
85 | | namespace internal { |
86 | | |
87 | | class SwapFieldHelper; |
88 | | |
89 | | // See parse_context.h for explanation |
90 | | class ParseContext; |
91 | | |
92 | | class ExtensionSet; |
93 | | class LazyField; |
94 | | class RepeatedPtrFieldBase; |
95 | | class TcParser; |
96 | | class WireFormatLite; |
97 | | class WeakFieldMap; |
98 | | |
99 | | template <typename Type> |
100 | | class GenericTypeHandler; // defined in repeated_field.h |
101 | | |
102 | | // We compute sizes as size_t but cache them as int. This function converts a |
103 | | // computed size to a cached size. Since we don't proceed with serialization |
104 | | // if the total size was > INT_MAX, it is not important what this function |
105 | | // returns for inputs > INT_MAX. However this case should not error or |
106 | | // ABSL_CHECK-fail, because the full size_t resolution is still returned from |
107 | | // ByteSizeLong() and checked against INT_MAX; we can catch the overflow |
108 | | // there. |
109 | 0 | inline int ToCachedSize(size_t size) { return static_cast<int>(size); } |
110 | | |
111 | | // We mainly calculate sizes in terms of size_t, but some functions that |
112 | | // compute sizes return "int". These int sizes are expected to always be |
113 | | // positive. This function is more efficient than casting an int to size_t |
114 | | // directly on 64-bit platforms because it avoids making the compiler emit a |
115 | | // sign extending instruction, which we don't want and don't want to pay for. |
116 | 0 | inline size_t FromIntSize(int size) { |
117 | 0 | // Convert to unsigned before widening so sign extension is not necessary. |
118 | 0 | return static_cast<unsigned int>(size); |
119 | 0 | } |
120 | | |
121 | | // For cases where a legacy function returns an integer size. We ABSL_DCHECK() |
122 | | // that the conversion will fit within an integer; if this is false then we |
123 | | // are losing information. |
124 | 0 | inline int ToIntSize(size_t size) { |
125 | 0 | ABSL_DCHECK_LE(size, static_cast<size_t>(INT_MAX)); |
126 | 0 | return static_cast<int>(size); |
127 | 0 | } |
128 | | |
129 | | // Default empty string object. Don't use this directly. Instead, call |
130 | | // GetEmptyString() to get the reference. This empty string is aligned with a |
131 | | // minimum alignment of 8 bytes to match the requirement of ArenaStringPtr. |
132 | | PROTOBUF_EXPORT extern ExplicitlyConstructedArenaString |
133 | | fixed_address_empty_string; |
134 | | |
135 | | |
136 | 0 | PROTOBUF_EXPORT constexpr const std::string& GetEmptyStringAlreadyInited() { |
137 | 0 | return fixed_address_empty_string.get(); |
138 | 0 | } |
139 | | |
140 | | PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str); |
141 | | |
142 | | } // namespace internal |
143 | | |
144 | | // Interface to light weight protocol messages. |
145 | | // |
146 | | // This interface is implemented by all protocol message objects. Non-lite |
147 | | // messages additionally implement the Message interface, which is a |
148 | | // subclass of MessageLite. Use MessageLite instead when you only need |
149 | | // the subset of features which it supports -- namely, nothing that uses |
150 | | // descriptors or reflection. You can instruct the protocol compiler |
151 | | // to generate classes which implement only MessageLite, not the full |
152 | | // Message interface, by adding the following line to the .proto file: |
153 | | // |
154 | | // option optimize_for = LITE_RUNTIME; |
155 | | // |
156 | | // This is particularly useful on resource-constrained systems where |
157 | | // the full protocol buffers runtime library is too big. |
158 | | // |
159 | | // Note that on non-constrained systems (e.g. servers) when you need |
160 | | // to link in lots of protocol definitions, a better way to reduce |
161 | | // total code footprint is to use optimize_for = CODE_SIZE. This |
162 | | // will make the generated code smaller while still supporting all the |
163 | | // same features (at the expense of speed). optimize_for = LITE_RUNTIME |
164 | | // is best when you only have a small number of message types linked |
165 | | // into your binary, in which case the size of the protocol buffers |
166 | | // runtime itself is the biggest problem. |
167 | | // |
168 | | // Users must not derive from this class. Only the protocol compiler and |
169 | | // the internal library are allowed to create subclasses. |
170 | | class PROTOBUF_EXPORT MessageLite { |
171 | | public: |
172 | 0 | constexpr MessageLite() {} |
173 | | MessageLite(const MessageLite&) = delete; |
174 | | MessageLite& operator=(const MessageLite&) = delete; |
175 | 2.38M | virtual ~MessageLite() = default; |
176 | | |
177 | | // Basic Operations ------------------------------------------------ |
178 | | |
179 | | // Get the name of this message type, e.g. "foo.bar.BazProto". |
180 | | virtual std::string GetTypeName() const = 0; |
181 | | |
182 | | // Construct a new instance of the same type. Ownership is passed to the |
183 | | // caller. |
184 | 0 | MessageLite* New() const { return New(nullptr); } |
185 | | |
186 | | // Construct a new instance on the arena. Ownership is passed to the caller |
187 | | // if arena is a nullptr. |
188 | | virtual MessageLite* New(Arena* arena) const = 0; |
189 | | |
190 | 0 | Arena* GetArena() const { return _internal_metadata_.arena(); } |
191 | | |
192 | | // Clear all fields of the message and set them to their default values. |
193 | | // Clear() assumes that any memory allocated to hold parts of the message |
194 | | // will likely be needed again, so the memory used may not be freed. |
195 | | // To ensure that all memory used by a Message is freed, you must delete it. |
196 | | virtual void Clear() = 0; |
197 | | |
198 | | // Quickly check if all required fields have values set. |
199 | | virtual bool IsInitialized() const = 0; |
200 | | |
201 | | // This is not implemented for Lite messages -- it just returns "(cannot |
202 | | // determine missing fields for lite message)". However, it is implemented |
203 | | // for full messages. See message.h. |
204 | | virtual std::string InitializationErrorString() const; |
205 | | |
206 | | // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, |
207 | | // results are undefined (probably crash). |
208 | | virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; |
209 | | |
210 | | // These methods return a human-readable summary of the message. Note that |
211 | | // since the MessageLite interface does not support reflection, there is very |
212 | | // little information that these methods can provide. They are shadowed by |
213 | | // methods of the same name on the Message interface which provide much more |
214 | | // information. The methods here are intended primarily to facilitate code |
215 | | // reuse for logic that needs to interoperate with both full and lite protos. |
216 | | // |
217 | | // The format of the returned string is subject to change, so please do not |
218 | | // assume it will remain stable over time. |
219 | | std::string DebugString() const; |
220 | 0 | std::string ShortDebugString() const { return DebugString(); } |
221 | | // MessageLite::DebugString is already Utf8 Safe. This is to add compatibility |
222 | | // with Message. |
223 | 0 | std::string Utf8DebugString() const { return DebugString(); } |
224 | | |
225 | | // Implementation of the `AbslStringify` interface. This adds `DebugString()` |
226 | | // to the sink. Do not rely on exact format. |
227 | | template <typename Sink> |
228 | | friend void AbslStringify(Sink& sink, const google::protobuf::MessageLite& msg) { |
229 | | sink.Append(msg.DebugString()); |
230 | | } |
231 | | |
232 | | // Parsing --------------------------------------------------------- |
233 | | // Methods for parsing in protocol buffer format. Most of these are |
234 | | // just simple wrappers around MergeFromCodedStream(). Clear() will be |
235 | | // called before merging the input. |
236 | | |
237 | | // Fill the message with a protocol buffer parsed from the given input |
238 | | // stream. Returns false on a read error or if the input is in the wrong |
239 | | // format. A successful return does not indicate the entire input is |
240 | | // consumed, ensure you call ConsumedEntireMessage() to check that if |
241 | | // applicable. |
242 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromCodedStream( |
243 | | io::CodedInputStream* input); |
244 | | // Like ParseFromCodedStream(), but accepts messages that are missing |
245 | | // required fields. |
246 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromCodedStream( |
247 | | io::CodedInputStream* input); |
248 | | // Read a protocol buffer from the given zero-copy input stream. If |
249 | | // successful, the entire input will be consumed. |
250 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromZeroCopyStream( |
251 | | io::ZeroCopyInputStream* input); |
252 | | // Like ParseFromZeroCopyStream(), but accepts messages that are missing |
253 | | // required fields. |
254 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromZeroCopyStream( |
255 | | io::ZeroCopyInputStream* input); |
256 | | // Parse a protocol buffer from a file descriptor. If successful, the entire |
257 | | // input will be consumed. |
258 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromFileDescriptor( |
259 | | int file_descriptor); |
260 | | // Like ParseFromFileDescriptor(), but accepts messages that are missing |
261 | | // required fields. |
262 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromFileDescriptor( |
263 | | int file_descriptor); |
264 | | // Parse a protocol buffer from a C++ istream. If successful, the entire |
265 | | // input will be consumed. |
266 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromIstream(std::istream* input); |
267 | | // Like ParseFromIstream(), but accepts messages that are missing |
268 | | // required fields. |
269 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromIstream( |
270 | | std::istream* input); |
271 | | // Read a protocol buffer from the given zero-copy input stream, expecting |
272 | | // the message to be exactly "size" bytes long. If successful, exactly |
273 | | // this many bytes will have been consumed from the input. |
274 | | bool MergePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, |
275 | | int size); |
276 | | // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are |
277 | | // missing required fields. |
278 | | bool MergeFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); |
279 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromBoundedZeroCopyStream( |
280 | | io::ZeroCopyInputStream* input, int size); |
281 | | // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are |
282 | | // missing required fields. |
283 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromBoundedZeroCopyStream( |
284 | | io::ZeroCopyInputStream* input, int size); |
285 | | // Parses a protocol buffer contained in a string. Returns true on success. |
286 | | // This function takes a string in the (non-human-readable) binary wire |
287 | | // format, matching the encoding output by MessageLite::SerializeToString(). |
288 | | // If you'd like to convert a human-readable string into a protocol buffer |
289 | | // object, see google::protobuf::TextFormat::ParseFromString(). |
290 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromString(absl::string_view data); |
291 | | // Like ParseFromString(), but accepts messages that are missing |
292 | | // required fields. |
293 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromString( |
294 | | absl::string_view data); |
295 | | // Parse a protocol buffer contained in an array of bytes. |
296 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromArray(const void* data, |
297 | | int size); |
298 | | // Like ParseFromArray(), but accepts messages that are missing |
299 | | // required fields. |
300 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromArray(const void* data, |
301 | | int size); |
302 | | |
303 | | |
304 | | // Reads a protocol buffer from the stream and merges it into this |
305 | | // Message. Singular fields read from the what is |
306 | | // already in the Message and repeated fields are appended to those |
307 | | // already present. |
308 | | // |
309 | | // It is the responsibility of the caller to call input->LastTagWas() |
310 | | // (for groups) or input->ConsumedEntireMessage() (for non-groups) after |
311 | | // this returns to verify that the message's end was delimited correctly. |
312 | | // |
313 | | // ParseFromCodedStream() is implemented as Clear() followed by |
314 | | // MergeFromCodedStream(). |
315 | | bool MergeFromCodedStream(io::CodedInputStream* input); |
316 | | |
317 | | // Like MergeFromCodedStream(), but succeeds even if required fields are |
318 | | // missing in the input. |
319 | | // |
320 | | // MergeFromCodedStream() is just implemented as MergePartialFromCodedStream() |
321 | | // followed by IsInitialized(). |
322 | | bool MergePartialFromCodedStream(io::CodedInputStream* input); |
323 | | |
324 | | // Merge a protocol buffer contained in a string. |
325 | | bool MergeFromString(absl::string_view data); |
326 | | |
327 | | |
328 | | // Serialization --------------------------------------------------- |
329 | | // Methods for serializing in protocol buffer format. Most of these |
330 | | // are just simple wrappers around ByteSize() and SerializeWithCachedSizes(). |
331 | | |
332 | | // Write a protocol buffer of this message to the given output. Returns |
333 | | // false on a write error. If the message is missing required fields, |
334 | | // this may ABSL_CHECK-fail. |
335 | | bool SerializeToCodedStream(io::CodedOutputStream* output) const; |
336 | | // Like SerializeToCodedStream(), but allows missing required fields. |
337 | | bool SerializePartialToCodedStream(io::CodedOutputStream* output) const; |
338 | | // Write the message to the given zero-copy output stream. All required |
339 | | // fields must be set. |
340 | | bool SerializeToZeroCopyStream(io::ZeroCopyOutputStream* output) const; |
341 | | // Like SerializeToZeroCopyStream(), but allows missing required fields. |
342 | | bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const; |
343 | | // Serialize the message and store it in the given string. All required |
344 | | // fields must be set. |
345 | | bool SerializeToString(std::string* output) const; |
346 | | // Like SerializeToString(), but allows missing required fields. |
347 | | bool SerializePartialToString(std::string* output) const; |
348 | | // Serialize the message and store it in the given byte array. All required |
349 | | // fields must be set. |
350 | | bool SerializeToArray(void* data, int size) const; |
351 | | // Like SerializeToArray(), but allows missing required fields. |
352 | | bool SerializePartialToArray(void* data, int size) const; |
353 | | |
354 | | // Make a string encoding the message. Is equivalent to calling |
355 | | // SerializeToString() on a string and using that. Returns the empty |
356 | | // string if SerializeToString() would have returned an error. |
357 | | // Note: If you intend to generate many such strings, you may |
358 | | // reduce heap fragmentation by instead re-using the same string |
359 | | // object with calls to SerializeToString(). |
360 | | std::string SerializeAsString() const; |
361 | | // Like SerializeAsString(), but allows missing required fields. |
362 | | std::string SerializePartialAsString() const; |
363 | | |
364 | | // Serialize the message and write it to the given file descriptor. All |
365 | | // required fields must be set. |
366 | | bool SerializeToFileDescriptor(int file_descriptor) const; |
367 | | // Like SerializeToFileDescriptor(), but allows missing required fields. |
368 | | bool SerializePartialToFileDescriptor(int file_descriptor) const; |
369 | | // Serialize the message and write it to the given C++ ostream. All |
370 | | // required fields must be set. |
371 | | bool SerializeToOstream(std::ostream* output) const; |
372 | | // Like SerializeToOstream(), but allows missing required fields. |
373 | | bool SerializePartialToOstream(std::ostream* output) const; |
374 | | |
375 | | // Like SerializeToString(), but appends to the data to the string's |
376 | | // existing contents. All required fields must be set. |
377 | | bool AppendToString(std::string* output) const; |
378 | | // Like AppendToString(), but allows missing required fields. |
379 | | bool AppendPartialToString(std::string* output) const; |
380 | | |
381 | | // Reads a protocol buffer from a Cord and merges it into this message. |
382 | | bool MergeFromCord(const absl::Cord& cord); |
383 | | // Like MergeFromCord(), but accepts messages that are missing |
384 | | // required fields. |
385 | | bool MergePartialFromCord(const absl::Cord& cord); |
386 | | // Parse a protocol buffer contained in a Cord. |
387 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromCord(const absl::Cord& cord); |
388 | | // Like ParseFromCord(), but accepts messages that are missing |
389 | | // required fields. |
390 | | PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromCord( |
391 | | const absl::Cord& cord); |
392 | | |
393 | | // Serialize the message and store it in the given Cord. All required |
394 | | // fields must be set. |
395 | | bool SerializeToCord(absl::Cord* output) const; |
396 | | // Like SerializeToCord(), but allows missing required fields. |
397 | | bool SerializePartialToCord(absl::Cord* output) const; |
398 | | |
399 | | // Make a Cord encoding the message. Is equivalent to calling |
400 | | // SerializeToCord() on a Cord and using that. Returns an empty |
401 | | // Cord if SerializeToCord() would have returned an error. |
402 | | absl::Cord SerializeAsCord() const; |
403 | | // Like SerializeAsCord(), but allows missing required fields. |
404 | | absl::Cord SerializePartialAsCord() const; |
405 | | |
406 | | // Like SerializeToCord(), but appends to the data to the Cord's existing |
407 | | // contents. All required fields must be set. |
408 | | bool AppendToCord(absl::Cord* output) const; |
409 | | // Like AppendToCord(), but allows missing required fields. |
410 | | bool AppendPartialToCord(absl::Cord* output) const; |
411 | | |
412 | | // Computes the serialized size of the message. This recursively calls |
413 | | // ByteSizeLong() on all embedded messages. |
414 | | // |
415 | | // ByteSizeLong() is generally linear in the number of fields defined for the |
416 | | // proto. |
417 | | virtual size_t ByteSizeLong() const = 0; |
418 | | |
419 | | // Legacy ByteSize() API. |
420 | | PROTOBUF_DEPRECATED_MSG("Please use ByteSizeLong() instead") |
421 | 0 | int ByteSize() const { return internal::ToIntSize(ByteSizeLong()); } |
422 | | |
423 | | // Serializes the message without recomputing the size. The message must not |
424 | | // have changed since the last call to ByteSize(), and the value returned by |
425 | | // ByteSize must be non-negative. Otherwise the results are undefined. |
426 | 0 | void SerializeWithCachedSizes(io::CodedOutputStream* output) const { |
427 | 0 | output->SetCur(_InternalSerialize(output->Cur(), output->EpsCopy())); |
428 | 0 | } |
429 | | |
430 | | // Functions below here are not part of the public interface. It isn't |
431 | | // enforced, but they should be treated as private, and will be private |
432 | | // at some future time. Unfortunately the implementation of the "friend" |
433 | | // keyword in GCC is broken at the moment, but we expect it will be fixed. |
434 | | |
435 | | // Like SerializeWithCachedSizes, but writes directly to *target, returning |
436 | | // a pointer to the byte immediately after the last byte written. "target" |
437 | | // must point at a byte array of at least ByteSize() bytes. Whether to use |
438 | | // deterministic serialization, e.g., maps in sorted order, is determined by |
439 | | // CodedOutputStream::IsDefaultSerializationDeterministic(). |
440 | | uint8_t* SerializeWithCachedSizesToArray(uint8_t* target) const; |
441 | | |
442 | | // Returns the result of the last call to ByteSize(). An embedded message's |
443 | | // size is needed both to serialize it (because embedded messages are |
444 | | // length-delimited) and to compute the outer message's size. Caching |
445 | | // the size avoids computing it multiple times. |
446 | | // |
447 | | // ByteSize() does not automatically use the cached size when available |
448 | | // because this would require invalidating it every time the message was |
449 | | // modified, which would be too hard and expensive. (E.g. if a deeply-nested |
450 | | // sub-message is changed, all of its parents' cached sizes would need to be |
451 | | // invalidated, which is too much work for an otherwise inlined setter |
452 | | // method.) |
453 | | virtual int GetCachedSize() const = 0; |
454 | | |
455 | | virtual const char* _InternalParse(const char* /*ptr*/, |
456 | 0 | internal::ParseContext* /*ctx*/) { |
457 | 0 | return nullptr; |
458 | 0 | } |
459 | | |
460 | 0 | virtual void OnDemandRegisterArenaDtor(Arena* /*arena*/) {} |
461 | | |
462 | | protected: |
463 | | template <typename T> |
464 | 2.37M | static T* CreateMaybeMessage(Arena* arena) { |
465 | 2.37M | return Arena::CreateMaybeMessage<T>(arena); |
466 | 2.37M | } Unexecuted instantiation: google::protobuf::Any* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::Any>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::FileDescriptorSet* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::FileDescriptorSet>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::FileDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::FileDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::DescriptorProto_ExtensionRange* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::DescriptorProto_ExtensionRange>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::DescriptorProto_ReservedRange* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::DescriptorProto_ReservedRange>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::DescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::DescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::ExtensionRangeOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::ExtensionRangeOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::FieldDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::FieldDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::OneofDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::OneofDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::EnumDescriptorProto_EnumReservedRange* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::EnumDescriptorProto_EnumReservedRange>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::EnumDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::EnumDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::EnumValueDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::EnumValueDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::ServiceDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::ServiceDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::MethodDescriptorProto* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::MethodDescriptorProto>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::FileOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::FileOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::MessageOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::MessageOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::FieldOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::FieldOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::OneofOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::OneofOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::EnumOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::EnumOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::EnumValueOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::EnumValueOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::ServiceOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::ServiceOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::MethodOptions* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::MethodOptions>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::UninterpretedOption_NamePart* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::UninterpretedOption_NamePart>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::UninterpretedOption* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::UninterpretedOption>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::SourceCodeInfo_Location* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::SourceCodeInfo_Location>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::SourceCodeInfo* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::SourceCodeInfo>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::GeneratedCodeInfo_Annotation* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::GeneratedCodeInfo_Annotation>(google::protobuf::Arena*) Unexecuted instantiation: google::protobuf::GeneratedCodeInfo* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::GeneratedCodeInfo>(google::protobuf::Arena*) ruby_fuzzer::VarRef* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::VarRef>(google::protobuf::Arena*) Line | Count | Source | 464 | 73.2k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 73.2k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 73.2k | } |
ruby_fuzzer::ArrType* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::ArrType>(google::protobuf::Arena*) Line | Count | Source | 464 | 58.5k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 58.5k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 58.5k | } |
ruby_fuzzer::KVPair* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::KVPair>(google::protobuf::Arena*) Line | Count | Source | 464 | 129k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 129k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 129k | } |
ruby_fuzzer::HashType* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::HashType>(google::protobuf::Arena*) Line | Count | Source | 464 | 20.6k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 20.6k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 20.6k | } |
Unexecuted instantiation: ruby_fuzzer::StringExtNoArg* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::StringExtNoArg>(google::protobuf::Arena*) ruby_fuzzer::MathConst* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::MathConst>(google::protobuf::Arena*) Line | Count | Source | 464 | 3.09k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 3.09k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 3.09k | } |
ruby_fuzzer::Const* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Const>(google::protobuf::Arena*) Line | Count | Source | 464 | 291k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 291k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 291k | } |
ruby_fuzzer::BinaryOp* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::BinaryOp>(google::protobuf::Arena*) Line | Count | Source | 464 | 131k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 131k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 131k | } |
ruby_fuzzer::Rvalue* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Rvalue>(google::protobuf::Arena*) Line | Count | Source | 464 | 580k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 580k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 580k | } |
ruby_fuzzer::AssignmentStatement* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::AssignmentStatement>(google::protobuf::Arena*) Line | Count | Source | 464 | 215k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 215k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 215k | } |
ruby_fuzzer::IfElse* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::IfElse>(google::protobuf::Arena*) Line | Count | Source | 464 | 17.5k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 17.5k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 17.5k | } |
ruby_fuzzer::Ternary* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Ternary>(google::protobuf::Arena*) Line | Count | Source | 464 | 8.65k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 8.65k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 8.65k | } |
ruby_fuzzer::ObjectSpace* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::ObjectSpace>(google::protobuf::Arena*) Line | Count | Source | 464 | 20.6k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 20.6k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 20.6k | } |
ruby_fuzzer::Time* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Time>(google::protobuf::Arena*) Line | Count | Source | 464 | 10.2k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 10.2k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 10.2k | } |
ruby_fuzzer::Array* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Array>(google::protobuf::Arena*) Line | Count | Source | 464 | 56.1k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 56.1k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 56.1k | } |
ruby_fuzzer::MathType* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::MathType>(google::protobuf::Arena*) Line | Count | Source | 464 | 9.45k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 9.45k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 9.45k | } |
ruby_fuzzer::MathOps* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::MathOps>(google::protobuf::Arena*) Line | Count | Source | 464 | 9.47k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 9.47k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 9.47k | } |
ruby_fuzzer::BuiltinFuncs* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::BuiltinFuncs>(google::protobuf::Arena*) Line | Count | Source | 464 | 119k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 119k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 119k | } |
ruby_fuzzer::Statement* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Statement>(google::protobuf::Arena*) Line | Count | Source | 464 | 554k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 554k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 554k | } |
ruby_fuzzer::StatementSeq* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::StatementSeq>(google::protobuf::Arena*) Line | Count | Source | 464 | 70.0k | static T* CreateMaybeMessage(Arena* arena) { | 465 | 70.0k | return Arena::CreateMaybeMessage<T>(arena); | 466 | 70.0k | } |
Unexecuted instantiation: ruby_fuzzer::Function* google::protobuf::MessageLite::CreateMaybeMessage<ruby_fuzzer::Function>(google::protobuf::Arena*) |
467 | | |
468 | 2.38M | inline explicit MessageLite(Arena* arena) : _internal_metadata_(arena) {} |
469 | | |
470 | | // Returns the arena, if any, that directly owns this message and its internal |
471 | | // memory (Arena::Own is different in that the arena doesn't directly own the |
472 | | // internal memory). This method is used in proto's implementation for |
473 | | // swapping, moving and setting allocated, for deciding whether the ownership |
474 | | // of this message or its internal memory could be changed. |
475 | 0 | Arena* GetOwningArena() const { return _internal_metadata_.arena(); } |
476 | | |
477 | | // Returns the arena, used for allocating internal objects(e.g., child |
478 | | // messages, etc), or owning incoming objects (e.g., set allocated). |
479 | 738k | Arena* GetArenaForAllocation() const { return _internal_metadata_.arena(); } |
480 | | |
481 | | internal::InternalMetadata _internal_metadata_; |
482 | | |
483 | | public: |
484 | | enum ParseFlags { |
485 | | kMerge = 0, |
486 | | kParse = 1, |
487 | | kMergePartial = 2, |
488 | | kParsePartial = 3, |
489 | | kMergeWithAliasing = 4, |
490 | | kParseWithAliasing = 5, |
491 | | kMergePartialWithAliasing = 6, |
492 | | kParsePartialWithAliasing = 7 |
493 | | }; |
494 | | |
495 | | template <ParseFlags flags, typename T> |
496 | | bool ParseFrom(const T& input); |
497 | | |
498 | | // Fast path when conditions match (ie. non-deterministic) |
499 | | // uint8_t* _InternalSerialize(uint8_t* ptr) const; |
500 | | virtual uint8_t* _InternalSerialize( |
501 | | uint8_t* ptr, io::EpsCopyOutputStream* stream) const = 0; |
502 | | |
503 | | // Identical to IsInitialized() except that it logs an error message. |
504 | 0 | bool IsInitializedWithErrors() const { |
505 | 0 | if (IsInitialized()) return true; |
506 | 0 | LogInitializationErrorMessage(); |
507 | 0 | return false; |
508 | 0 | } |
509 | | |
510 | | private: |
511 | | friend class FastReflectionMessageMutator; |
512 | | friend class FastReflectionStringSetter; |
513 | | friend class Message; |
514 | | friend class Reflection; |
515 | | friend class internal::ExtensionSet; |
516 | | friend class internal::LazyField; |
517 | | friend class internal::SwapFieldHelper; |
518 | | friend class internal::TcParser; |
519 | | friend class internal::WeakFieldMap; |
520 | | friend class internal::WireFormatLite; |
521 | | |
522 | | template <typename Type> |
523 | | friend class Arena::InternalHelper; |
524 | | template <typename Type> |
525 | | friend class internal::GenericTypeHandler; |
526 | | |
527 | | void LogInitializationErrorMessage() const; |
528 | | |
529 | | bool MergeFromImpl(io::CodedInputStream* input, ParseFlags parse_flags); |
530 | | }; |
531 | | |
532 | | namespace internal { |
533 | | |
534 | | template <bool alias> |
535 | | bool MergeFromImpl(absl::string_view input, MessageLite* msg, |
536 | | MessageLite::ParseFlags parse_flags); |
537 | | extern template bool MergeFromImpl<false>(absl::string_view input, |
538 | | MessageLite* msg, |
539 | | MessageLite::ParseFlags parse_flags); |
540 | | extern template bool MergeFromImpl<true>(absl::string_view input, |
541 | | MessageLite* msg, |
542 | | MessageLite::ParseFlags parse_flags); |
543 | | |
544 | | template <bool alias> |
545 | | bool MergeFromImpl(io::ZeroCopyInputStream* input, MessageLite* msg, |
546 | | MessageLite::ParseFlags parse_flags); |
547 | | extern template bool MergeFromImpl<false>(io::ZeroCopyInputStream* input, |
548 | | MessageLite* msg, |
549 | | MessageLite::ParseFlags parse_flags); |
550 | | extern template bool MergeFromImpl<true>(io::ZeroCopyInputStream* input, |
551 | | MessageLite* msg, |
552 | | MessageLite::ParseFlags parse_flags); |
553 | | |
554 | | struct BoundedZCIS { |
555 | | io::ZeroCopyInputStream* zcis; |
556 | | int limit; |
557 | | }; |
558 | | |
559 | | template <bool alias> |
560 | | bool MergeFromImpl(BoundedZCIS input, MessageLite* msg, |
561 | | MessageLite::ParseFlags parse_flags); |
562 | | extern template bool MergeFromImpl<false>(BoundedZCIS input, MessageLite* msg, |
563 | | MessageLite::ParseFlags parse_flags); |
564 | | extern template bool MergeFromImpl<true>(BoundedZCIS input, MessageLite* msg, |
565 | | MessageLite::ParseFlags parse_flags); |
566 | | |
567 | | template <typename T> |
568 | | struct SourceWrapper; |
569 | | |
570 | | template <bool alias, typename T> |
571 | | bool MergeFromImpl(const SourceWrapper<T>& input, MessageLite* msg, |
572 | | MessageLite::ParseFlags parse_flags) { |
573 | | return input.template MergeInto<alias>(msg, parse_flags); |
574 | | } |
575 | | |
576 | | } // namespace internal |
577 | | |
578 | | template <MessageLite::ParseFlags flags, typename T> |
579 | | bool MessageLite::ParseFrom(const T& input) { |
580 | | if (flags & kParse) Clear(); |
581 | | constexpr bool alias = (flags & kMergeWithAliasing) != 0; |
582 | | return internal::MergeFromImpl<alias>(input, this, flags); |
583 | | } |
584 | | |
585 | | // =================================================================== |
586 | | // Shutdown support. |
587 | | |
588 | | |
589 | | // Shut down the entire protocol buffers library, deleting all static-duration |
590 | | // objects allocated by the library or by generated .pb.cc files. |
591 | | // |
592 | | // There are two reasons you might want to call this: |
593 | | // * You use a draconian definition of "memory leak" in which you expect |
594 | | // every single malloc() to have a corresponding free(), even for objects |
595 | | // which live until program exit. |
596 | | // * You are writing a dynamically-loaded library which needs to clean up |
597 | | // after itself when the library is unloaded. |
598 | | // |
599 | | // It is safe to call this multiple times. However, it is not safe to use |
600 | | // any other part of the protocol buffers library after |
601 | | // ShutdownProtobufLibrary() has been called. Furthermore this call is not |
602 | | // thread safe, user needs to synchronize multiple calls. |
603 | | PROTOBUF_EXPORT void ShutdownProtobufLibrary(); |
604 | | |
605 | | namespace internal { |
606 | | |
607 | | // Register a function to be called when ShutdownProtocolBuffers() is called. |
608 | | PROTOBUF_EXPORT void OnShutdown(void (*func)()); |
609 | | // Run an arbitrary function on an arg |
610 | | PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg); |
611 | | |
612 | | template <typename T> |
613 | | T* OnShutdownDelete(T* p) { |
614 | | OnShutdownRun([](const void* pp) { delete static_cast<const T*>(pp); }, p); |
615 | | return p; |
616 | | } |
617 | | |
618 | | } // namespace internal |
619 | | } // namespace protobuf |
620 | | } // namespace google |
621 | | |
622 | | #include "google/protobuf/port_undef.inc" |
623 | | |
624 | | #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ |