Coverage Report

Created: 2024-07-27 06:53

/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
//
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file or at
6
// https://developers.google.com/open-source/licenses/bsd
7
8
// Authors: wink@google.com (Wink Saville),
9
//          kenton@google.com (Kenton Varda)
10
//  Based on original Protocol Buffers design by
11
//  Sanjay Ghemawat, Jeff Dean, and others.
12
//
13
// Defines MessageLite, the abstract interface implemented by all (lite
14
// and non-lite) protocol message objects.
15
16
#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__
17
#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__
18
19
#include <climits>
20
#include <cstddef>
21
#include <cstdint>
22
#include <iosfwd>
23
#include <string>
24
25
#include "absl/base/attributes.h"
26
#include "absl/log/absl_check.h"
27
#include "absl/strings/cord.h"
28
#include "absl/strings/string_view.h"
29
#include "google/protobuf/arena.h"
30
#include "google/protobuf/explicitly_constructed.h"
31
#include "google/protobuf/internal_visibility.h"
32
#include "google/protobuf/io/coded_stream.h"
33
#include "google/protobuf/metadata_lite.h"
34
#include "google/protobuf/port.h"
35
36
37
// clang-format off
38
#include "google/protobuf/port_def.inc"
39
// clang-format on
40
41
#ifdef SWIG
42
#error "You cannot SWIG proto headers"
43
#endif
44
45
namespace google {
46
namespace protobuf {
47
48
template <typename T>
49
class RepeatedPtrField;
50
51
class FastReflectionMessageMutator;
52
class FastReflectionStringSetter;
53
class Reflection;
54
class Descriptor;
55
class AssignDescriptorsHelper;
56
57
namespace io {
58
59
class CodedInputStream;
60
class CodedOutputStream;
61
class ZeroCopyInputStream;
62
class ZeroCopyOutputStream;
63
64
}  // namespace io
65
namespace internal {
66
67
// Allow easy change to regular int on platforms where the atomic might have a
68
// perf impact.
69
//
70
// CachedSize is like std::atomic<int> but with some important changes:
71
//
72
// 1) CachedSize uses Get / Set rather than load / store.
73
// 2) CachedSize always uses relaxed ordering.
74
// 3) CachedSize is assignable and copy-constructible.
75
// 4) CachedSize has a constexpr default constructor, and a constexpr
76
//    constructor that takes an int argument.
77
// 5) If the compiler supports the __atomic_load_n / __atomic_store_n builtins,
78
//    then CachedSize is trivially copyable.
79
//
80
// Developed at https://godbolt.org/z/vYcx7zYs1 ; supports gcc, clang, MSVC.
81
class PROTOBUF_EXPORT CachedSize {
82
 private:
83
  using Scalar = int;
84
85
 public:
86
0
  constexpr CachedSize() noexcept : atom_(Scalar{}) {}
87
  // NOLINTNEXTLINE(google-explicit-constructor)
88
1.57M
  constexpr CachedSize(Scalar desired) noexcept : atom_(desired) {}
89
#if PROTOBUF_BUILTIN_ATOMIC
90
  constexpr CachedSize(const CachedSize& other) = default;
91
92
0
  Scalar Get() const noexcept {
93
0
    return __atomic_load_n(&atom_, __ATOMIC_RELAXED);
94
0
  }
95
96
0
  void Set(Scalar desired) noexcept {
97
0
    __atomic_store_n(&atom_, desired, __ATOMIC_RELAXED);
98
0
  }
99
#else
100
  CachedSize(const CachedSize& other) noexcept : atom_(other.Get()) {}
101
  CachedSize& operator=(const CachedSize& other) noexcept {
102
    Set(other.Get());
103
    return *this;
104
  }
105
106
  Scalar Get() const noexcept {  //
107
    return atom_.load(std::memory_order_relaxed);
108
  }
109
110
  void Set(Scalar desired) noexcept {
111
    atom_.store(desired, std::memory_order_relaxed);
112
  }
113
#endif
114
115
 private:
116
#if PROTOBUF_BUILTIN_ATOMIC
117
  Scalar atom_;
118
#else
119
  std::atomic<Scalar> atom_;
120
#endif
121
};
122
123
class SwapFieldHelper;
124
125
// See parse_context.h for explanation
126
class ParseContext;
127
128
struct DescriptorTable;
129
class DescriptorPoolExtensionFinder;
130
class ExtensionSet;
131
class LazyField;
132
class RepeatedPtrFieldBase;
133
class TcParser;
134
struct TcParseTableBase;
135
class WireFormatLite;
136
class WeakFieldMap;
137
138
template <typename Type>
139
class GenericTypeHandler;  // defined in repeated_field.h
140
141
// We compute sizes as size_t but cache them as int.  This function converts a
142
// computed size to a cached size.  Since we don't proceed with serialization
143
// if the total size was > INT_MAX, it is not important what this function
144
// returns for inputs > INT_MAX.  However this case should not error or
145
// ABSL_CHECK-fail, because the full size_t resolution is still returned from
146
// ByteSizeLong() and checked against INT_MAX; we can catch the overflow
147
// there.
148
0
inline int ToCachedSize(size_t size) { return static_cast<int>(size); }
149
150
// We mainly calculate sizes in terms of size_t, but some functions that
151
// compute sizes return "int".  These int sizes are expected to always be
152
// positive. This function is more efficient than casting an int to size_t
153
// directly on 64-bit platforms because it avoids making the compiler emit a
154
// sign extending instruction, which we don't want and don't want to pay for.
155
0
inline size_t FromIntSize(int size) {
156
0
  // Convert to unsigned before widening so sign extension is not necessary.
157
0
  return static_cast<unsigned int>(size);
158
0
}
159
160
// For cases where a legacy function returns an integer size.  We ABSL_DCHECK()
161
// that the conversion will fit within an integer; if this is false then we
162
// are losing information.
163
0
inline int ToIntSize(size_t size) {
164
0
  ABSL_DCHECK_LE(size, static_cast<size_t>(INT_MAX));
165
0
  return static_cast<int>(size);
166
0
}
167
168
// Default empty string object. Don't use this directly. Instead, call
169
// GetEmptyString() to get the reference. This empty string is aligned with a
170
// minimum alignment of 8 bytes to match the requirement of ArenaStringPtr.
171
PROTOBUF_EXPORT extern ExplicitlyConstructedArenaString
172
    fixed_address_empty_string;
173
174
175
0
PROTOBUF_EXPORT constexpr const std::string& GetEmptyStringAlreadyInited() {
176
0
  return fixed_address_empty_string.get();
177
0
}
178
179
PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str);
180
181
}  // namespace internal
182
183
// Interface to light weight protocol messages.
184
//
185
// This interface is implemented by all protocol message objects.  Non-lite
186
// messages additionally implement the Message interface, which is a
187
// subclass of MessageLite.  Use MessageLite instead when you only need
188
// the subset of features which it supports -- namely, nothing that uses
189
// descriptors or reflection.  You can instruct the protocol compiler
190
// to generate classes which implement only MessageLite, not the full
191
// Message interface, by adding the following line to the .proto file:
192
//
193
//   option optimize_for = LITE_RUNTIME;
194
//
195
// This is particularly useful on resource-constrained systems where
196
// the full protocol buffers runtime library is too big.
197
//
198
// Note that on non-constrained systems (e.g. servers) when you need
199
// to link in lots of protocol definitions, a better way to reduce
200
// total code footprint is to use optimize_for = CODE_SIZE.  This
201
// will make the generated code smaller while still supporting all the
202
// same features (at the expense of speed).  optimize_for = LITE_RUNTIME
203
// is best when you only have a small number of message types linked
204
// into your binary, in which case the size of the protocol buffers
205
// runtime itself is the biggest problem.
206
//
207
// Users must not derive from this class. Only the protocol compiler and
208
// the internal library are allowed to create subclasses.
209
class PROTOBUF_EXPORT MessageLite {
210
 public:
211
  constexpr MessageLite() = default;
212
  MessageLite(const MessageLite&) = delete;
213
  MessageLite& operator=(const MessageLite&) = delete;
214
1.57M
  virtual ~MessageLite() = default;
215
216
  // Basic Operations ------------------------------------------------
217
218
  // Get the name of this message type, e.g. "foo.bar.BazProto".
219
  std::string GetTypeName() const;
220
221
  // Construct a new instance of the same type.  Ownership is passed to the
222
  // caller.
223
0
  MessageLite* New() const { return New(nullptr); }
224
225
  // Construct a new instance on the arena. Ownership is passed to the caller
226
  // if arena is a nullptr.
227
  virtual MessageLite* New(Arena* arena) const = 0;
228
229
  // Returns the arena, if any, that directly owns this message and its internal
230
  // memory (Arena::Own is different in that the arena doesn't directly own the
231
  // internal memory). This method is used in proto's implementation for
232
  // swapping, moving and setting allocated, for deciding whether the ownership
233
  // of this message or its internal memory could be changed.
234
4.29k
  Arena* GetArena() const { return _internal_metadata_.arena(); }
235
236
  // Clear all fields of the message and set them to their default values.
237
  // Clear() assumes that any memory allocated to hold parts of the message
238
  // will likely be needed again, so the memory used may not be freed.
239
  // To ensure that all memory used by a Message is freed, you must delete it.
240
  virtual void Clear() = 0;
241
242
  // Quickly check if all required fields have values set.
243
  bool IsInitialized() const;
244
245
  // This is not implemented for Lite messages -- it just returns "(cannot
246
  // determine missing fields for lite message)".  However, it is implemented
247
  // for full messages.  See message.h.
248
  std::string InitializationErrorString() const;
249
250
  // If |other| is the exact same class as this, calls MergeFrom(). Otherwise,
251
  // results are undefined (probably crash).
252
  virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0;
253
254
  // These methods return a human-readable summary of the message. Note that
255
  // since the MessageLite interface does not support reflection, there is very
256
  // little information that these methods can provide. They are shadowed by
257
  // methods of the same name on the Message interface which provide much more
258
  // information. The methods here are intended primarily to facilitate code
259
  // reuse for logic that needs to interoperate with both full and lite protos.
260
  //
261
  // The format of the returned string is subject to change, so please do not
262
  // assume it will remain stable over time.
263
  std::string DebugString() const;
264
0
  std::string ShortDebugString() const { return DebugString(); }
265
  // MessageLite::DebugString is already Utf8 Safe. This is to add compatibility
266
  // with Message.
267
0
  std::string Utf8DebugString() const { return DebugString(); }
268
269
  // Implementation of the `AbslStringify` interface. This adds `DebugString()`
270
  // to the sink. Do not rely on exact format.
271
  template <typename Sink>
272
  friend void AbslStringify(Sink& sink, const google::protobuf::MessageLite& msg) {
273
    sink.Append(msg.DebugString());
274
  }
275
276
  // Parsing ---------------------------------------------------------
277
  // Methods for parsing in protocol buffer format.  Most of these are
278
  // just simple wrappers around MergeFromCodedStream().  Clear() will be
279
  // called before merging the input.
280
281
  // Fill the message with a protocol buffer parsed from the given input
282
  // stream. Returns false on a read error or if the input is in the wrong
283
  // format.  A successful return does not indicate the entire input is
284
  // consumed, ensure you call ConsumedEntireMessage() to check that if
285
  // applicable.
286
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromCodedStream(
287
      io::CodedInputStream* input);
288
  // Like ParseFromCodedStream(), but accepts messages that are missing
289
  // required fields.
290
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromCodedStream(
291
      io::CodedInputStream* input);
292
  // Read a protocol buffer from the given zero-copy input stream.  If
293
  // successful, the entire input will be consumed.
294
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromZeroCopyStream(
295
      io::ZeroCopyInputStream* input);
296
  // Like ParseFromZeroCopyStream(), but accepts messages that are missing
297
  // required fields.
298
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromZeroCopyStream(
299
      io::ZeroCopyInputStream* input);
300
  // Parse a protocol buffer from a file descriptor.  If successful, the entire
301
  // input will be consumed.
302
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromFileDescriptor(
303
      int file_descriptor);
304
  // Like ParseFromFileDescriptor(), but accepts messages that are missing
305
  // required fields.
306
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromFileDescriptor(
307
      int file_descriptor);
308
  // Parse a protocol buffer from a C++ istream.  If successful, the entire
309
  // input will be consumed.
310
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromIstream(std::istream* input);
311
  // Like ParseFromIstream(), but accepts messages that are missing
312
  // required fields.
313
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromIstream(
314
      std::istream* input);
315
  // Read a protocol buffer from the given zero-copy input stream, expecting
316
  // the message to be exactly "size" bytes long.  If successful, exactly
317
  // this many bytes will have been consumed from the input.
318
  bool MergePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input,
319
                                             int size);
320
  // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are
321
  // missing required fields.
322
  bool MergeFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size);
323
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromBoundedZeroCopyStream(
324
      io::ZeroCopyInputStream* input, int size);
325
  // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are
326
  // missing required fields.
327
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromBoundedZeroCopyStream(
328
      io::ZeroCopyInputStream* input, int size);
329
  // Parses a protocol buffer contained in a string. Returns true on success.
330
  // This function takes a string in the (non-human-readable) binary wire
331
  // format, matching the encoding output by MessageLite::SerializeToString().
332
  // If you'd like to convert a human-readable string into a protocol buffer
333
  // object, see google::protobuf::TextFormat::ParseFromString().
334
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromString(absl::string_view data);
335
  // Like ParseFromString(), but accepts messages that are missing
336
  // required fields.
337
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromString(
338
      absl::string_view data);
339
  // Parse a protocol buffer contained in an array of bytes.
340
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromArray(const void* data, int size);
341
  // Like ParseFromArray(), but accepts messages that are missing
342
  // required fields.
343
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromArray(const void* data,
344
                                                          int size);
345
346
347
  // Reads a protocol buffer from the stream and merges it into this
348
  // Message.  Singular fields read from the what is
349
  // already in the Message and repeated fields are appended to those
350
  // already present.
351
  //
352
  // It is the responsibility of the caller to call input->LastTagWas()
353
  // (for groups) or input->ConsumedEntireMessage() (for non-groups) after
354
  // this returns to verify that the message's end was delimited correctly.
355
  //
356
  // ParseFromCodedStream() is implemented as Clear() followed by
357
  // MergeFromCodedStream().
358
  bool MergeFromCodedStream(io::CodedInputStream* input);
359
360
  // Like MergeFromCodedStream(), but succeeds even if required fields are
361
  // missing in the input.
362
  //
363
  // MergeFromCodedStream() is just implemented as MergePartialFromCodedStream()
364
  // followed by IsInitialized().
365
  bool MergePartialFromCodedStream(io::CodedInputStream* input);
366
367
  // Merge a protocol buffer contained in a string.
368
  bool MergeFromString(absl::string_view data);
369
370
371
  // Serialization ---------------------------------------------------
372
  // Methods for serializing in protocol buffer format.  Most of these
373
  // are just simple wrappers around ByteSize() and SerializeWithCachedSizes().
374
375
  // Write a protocol buffer of this message to the given output.  Returns
376
  // false on a write error.  If the message is missing required fields,
377
  // this may ABSL_CHECK-fail.
378
  bool SerializeToCodedStream(io::CodedOutputStream* output) const;
379
  // Like SerializeToCodedStream(), but allows missing required fields.
380
  bool SerializePartialToCodedStream(io::CodedOutputStream* output) const;
381
  // Write the message to the given zero-copy output stream.  All required
382
  // fields must be set.
383
  bool SerializeToZeroCopyStream(io::ZeroCopyOutputStream* output) const;
384
  // Like SerializeToZeroCopyStream(), but allows missing required fields.
385
  bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const;
386
  // Serialize the message and store it in the given string.  All required
387
  // fields must be set.
388
  bool SerializeToString(std::string* output) const;
389
  // Like SerializeToString(), but allows missing required fields.
390
  bool SerializePartialToString(std::string* output) const;
391
  // Serialize the message and store it in the given byte array.  All required
392
  // fields must be set.
393
  bool SerializeToArray(void* data, int size) const;
394
  // Like SerializeToArray(), but allows missing required fields.
395
  bool SerializePartialToArray(void* data, int size) const;
396
397
  // Make a string encoding the message. Is equivalent to calling
398
  // SerializeToString() on a string and using that.  Returns the empty
399
  // string if SerializeToString() would have returned an error.
400
  // Note: If you intend to generate many such strings, you may
401
  // reduce heap fragmentation by instead re-using the same string
402
  // object with calls to SerializeToString().
403
  std::string SerializeAsString() const;
404
  // Like SerializeAsString(), but allows missing required fields.
405
  std::string SerializePartialAsString() const;
406
407
  // Serialize the message and write it to the given file descriptor.  All
408
  // required fields must be set.
409
  bool SerializeToFileDescriptor(int file_descriptor) const;
410
  // Like SerializeToFileDescriptor(), but allows missing required fields.
411
  bool SerializePartialToFileDescriptor(int file_descriptor) const;
412
  // Serialize the message and write it to the given C++ ostream.  All
413
  // required fields must be set.
414
  bool SerializeToOstream(std::ostream* output) const;
415
  // Like SerializeToOstream(), but allows missing required fields.
416
  bool SerializePartialToOstream(std::ostream* output) const;
417
418
  // Like SerializeToString(), but appends to the data to the string's
419
  // existing contents.  All required fields must be set.
420
  bool AppendToString(std::string* output) const;
421
  // Like AppendToString(), but allows missing required fields.
422
  bool AppendPartialToString(std::string* output) const;
423
424
  // Reads a protocol buffer from a Cord and merges it into this message.
425
  bool MergeFromCord(const absl::Cord& cord);
426
  // Like MergeFromCord(), but accepts messages that are missing
427
  // required fields.
428
  bool MergePartialFromCord(const absl::Cord& cord);
429
  // Parse a protocol buffer contained in a Cord.
430
  ABSL_ATTRIBUTE_REINITIALIZES bool ParseFromCord(const absl::Cord& cord);
431
  // Like ParseFromCord(), but accepts messages that are missing
432
  // required fields.
433
  ABSL_ATTRIBUTE_REINITIALIZES bool ParsePartialFromCord(
434
      const absl::Cord& cord);
435
436
  // Serialize the message and store it in the given Cord.  All required
437
  // fields must be set.
438
  bool SerializeToCord(absl::Cord* output) const;
439
  // Like SerializeToCord(), but allows missing required fields.
440
  bool SerializePartialToCord(absl::Cord* output) const;
441
442
  // Make a Cord encoding the message. Is equivalent to calling
443
  // SerializeToCord() on a Cord and using that.  Returns an empty
444
  // Cord if SerializeToCord() would have returned an error.
445
  absl::Cord SerializeAsCord() const;
446
  // Like SerializeAsCord(), but allows missing required fields.
447
  absl::Cord SerializePartialAsCord() const;
448
449
  // Like SerializeToCord(), but appends to the data to the Cord's existing
450
  // contents.  All required fields must be set.
451
  bool AppendToCord(absl::Cord* output) const;
452
  // Like AppendToCord(), but allows missing required fields.
453
  bool AppendPartialToCord(absl::Cord* output) const;
454
455
  // Computes the serialized size of the message.  This recursively calls
456
  // ByteSizeLong() on all embedded messages.
457
  //
458
  // ByteSizeLong() is generally linear in the number of fields defined for the
459
  // proto.
460
  virtual size_t ByteSizeLong() const = 0;
461
462
  // Legacy ByteSize() API.
463
0
  [[deprecated("Please use ByteSizeLong() instead")]] int ByteSize() const {
464
0
    return internal::ToIntSize(ByteSizeLong());
465
0
  }
466
467
  // Serializes the message without recomputing the size.  The message must not
468
  // have changed since the last call to ByteSize(), and the value returned by
469
  // ByteSize must be non-negative.  Otherwise the results are undefined.
470
0
  void SerializeWithCachedSizes(io::CodedOutputStream* output) const {
471
0
    output->SetCur(_InternalSerialize(output->Cur(), output->EpsCopy()));
472
0
  }
473
474
  // Functions below here are not part of the public interface.  It isn't
475
  // enforced, but they should be treated as private, and will be private
476
  // at some future time.  Unfortunately the implementation of the "friend"
477
  // keyword in GCC is broken at the moment, but we expect it will be fixed.
478
479
  // Like SerializeWithCachedSizes, but writes directly to *target, returning
480
  // a pointer to the byte immediately after the last byte written.  "target"
481
  // must point at a byte array of at least ByteSize() bytes.  Whether to use
482
  // deterministic serialization, e.g., maps in sorted order, is determined by
483
  // CodedOutputStream::IsDefaultSerializationDeterministic().
484
  uint8_t* SerializeWithCachedSizesToArray(uint8_t* target) const;
485
486
  // Returns the result of the last call to ByteSize().  An embedded message's
487
  // size is needed both to serialize it (because embedded messages are
488
  // length-delimited) and to compute the outer message's size.  Caching
489
  // the size avoids computing it multiple times.
490
  //
491
  // ByteSize() does not automatically use the cached size when available
492
  // because this would require invalidating it every time the message was
493
  // modified, which would be too hard and expensive.  (E.g. if a deeply-nested
494
  // sub-message is changed, all of its parents' cached sizes would need to be
495
  // invalidated, which is too much work for an otherwise inlined setter
496
  // method.)
497
  int GetCachedSize() const;
498
499
  const char* _InternalParse(const char* ptr, internal::ParseContext* ctx);
500
501
  void OnDemandRegisterArenaDtor(Arena* arena);
502
503
 protected:
504
  // Message implementations require access to internally visible API.
505
1.57M
  static constexpr internal::InternalVisibility internal_visibility() {
506
1.57M
    return internal::InternalVisibility{};
507
1.57M
  }
508
509
  template <typename T>
510
1.56M
  PROTOBUF_ALWAYS_INLINE static T* DefaultConstruct(Arena* arena) {
511
1.56M
    return static_cast<T*>(Arena::DefaultConstruct<T>(arena));
512
1.56M
  }
DBOperation* google::protobuf::MessageLite::DefaultConstruct<DBOperation>(google::protobuf::Arena*)
Line
Count
Source
510
1.56M
  PROTOBUF_ALWAYS_INLINE static T* DefaultConstruct(Arena* arena) {
511
1.56M
    return static_cast<T*>(Arena::DefaultConstruct<T>(arena));
512
1.56M
  }
Unexecuted instantiation: DBOperations* google::protobuf::MessageLite::DefaultConstruct<DBOperations>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::Any* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::Any>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::UninterpretedOption_NamePart* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::UninterpretedOption_NamePart>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::SourceCodeInfo_Location* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::SourceCodeInfo_Location>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::GeneratedCodeInfo_Annotation* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::GeneratedCodeInfo_Annotation>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FieldOptions_FeatureSupport* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FieldOptions_FeatureSupport>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FieldOptions_EditionDefault* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FieldOptions_EditionDefault>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FeatureSet* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FeatureSet>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::ExtensionRangeOptions_Declaration* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::ExtensionRangeOptions_Declaration>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::EnumDescriptorProto_EnumReservedRange* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::EnumDescriptorProto_EnumReservedRange>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::DescriptorProto_ReservedRange* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::DescriptorProto_ReservedRange>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::UninterpretedOption* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::UninterpretedOption>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::SourceCodeInfo* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::SourceCodeInfo>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::GeneratedCodeInfo* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::GeneratedCodeInfo>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FeatureSetDefaults_FeatureSetEditionDefault* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FeatureSetDefaults_FeatureSetEditionDefault>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::ServiceOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::ServiceOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::OneofOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::OneofOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::MethodOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::MethodOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::MessageOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::MessageOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FileOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FileOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FieldOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FieldOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FeatureSetDefaults* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FeatureSetDefaults>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::ExtensionRangeOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::ExtensionRangeOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::EnumValueOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::EnumValueOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::EnumOptions* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::EnumOptions>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::OneofDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::OneofDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::MethodDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::MethodDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FieldDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FieldDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::EnumValueDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::EnumValueDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::DescriptorProto_ExtensionRange* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::DescriptorProto_ExtensionRange>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::ServiceDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::ServiceDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::EnumDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::EnumDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::DescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::DescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FileDescriptorProto* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FileDescriptorProto>(google::protobuf::Arena*)
Unexecuted instantiation: google::protobuf::FileDescriptorSet* google::protobuf::MessageLite::DefaultConstruct<google::protobuf::FileDescriptorSet>(google::protobuf::Arena*)
513
514
  template <typename T>
515
  PROTOBUF_ALWAYS_INLINE static T* CopyConstruct(Arena* arena, const T& from) {
516
    return static_cast<T*>(Arena::CopyConstruct<T>(arena, &from));
517
  }
518
519
0
  const internal::TcParseTableBase* GetTcParseTable() const {
520
0
    auto* data = GetClassData();
521
0
    ABSL_DCHECK(data != nullptr);
522
0
523
0
    auto* tc_table = data->tc_table;
524
0
    if (ABSL_PREDICT_FALSE(tc_table == nullptr)) {
525
0
      ABSL_DCHECK(!data->is_lite);
526
0
      return data->full().descriptor_methods->get_tc_table(*this);
527
0
    }
528
0
    return tc_table;
529
0
  }
530
531
1.57M
  inline explicit MessageLite(Arena* arena) : _internal_metadata_(arena) {}
532
533
  // We use a secondary vtable for descriptor based methods. This way ClassData
534
  // does not grow with the number of descriptor methods. This avoids extra
535
  // costs in MessageLite.
536
  struct DescriptorMethods {
537
    std::string (*get_type_name)(const MessageLite&);
538
    std::string (*initialization_error_string)(const MessageLite&);
539
    const internal::TcParseTableBase* (*get_tc_table)(const MessageLite&);
540
    size_t (*space_used_long)(const MessageLite&);
541
  };
542
  struct ClassDataFull;
543
  // Note: The order of arguments in the functions is chosen so that it has
544
  // the same ABI as the member function that calls them. Eg the `this`
545
  // pointer becomes the first argument in the free function.
546
  //
547
  // Future work:
548
  // We could save more data by omitting any optional pointer that would
549
  // otherwise be null. We can have some metadata in ClassData telling us if we
550
  // have them and their offset.
551
  struct ClassData {
552
    const internal::TcParseTableBase* tc_table;
553
    void (*on_demand_register_arena_dtor)(MessageLite& msg, Arena& arena);
554
    bool (*is_initialized)(const MessageLite&);
555
556
    // Offset of the CachedSize member.
557
    uint32_t cached_size_offset;
558
    // LITE objects (ie !descriptor_methods) collocate their name as a
559
    // char[] just beyond the ClassData.
560
    bool is_lite;
561
562
    // XXX REMOVE XXX
563
    constexpr ClassData(const internal::TcParseTableBase* tc_table,
564
                        void (*on_demand_register_arena_dtor)(MessageLite&,
565
                                                              Arena&),
566
                        uint32_t cached_size_offset, bool is_lite)
567
        : tc_table(tc_table),
568
          on_demand_register_arena_dtor(on_demand_register_arena_dtor),
569
          is_initialized(nullptr),
570
          cached_size_offset(cached_size_offset),
571
0
          is_lite(is_lite) {}
572
573
    constexpr ClassData(const internal::TcParseTableBase* tc_table,
574
                        void (*on_demand_register_arena_dtor)(MessageLite&,
575
                                                              Arena&),
576
                        bool (*is_initialized)(const MessageLite&),
577
                        uint32_t cached_size_offset, bool is_lite)
578
        : tc_table(tc_table),
579
          on_demand_register_arena_dtor(on_demand_register_arena_dtor),
580
          is_initialized(is_initialized),
581
          cached_size_offset(cached_size_offset),
582
0
          is_lite(is_lite) {}
583
584
2
    const ClassDataFull& full() const {
585
2
      ABSL_DCHECK(!is_lite);
586
2
      return *static_cast<const ClassDataFull*>(this);
587
2
    }
588
  };
589
  template <size_t N>
590
  struct ClassDataLite {
591
    ClassData header;
592
    const char type_name[N];
593
594
    constexpr const ClassData* base() const { return &header; }
595
  };
596
  struct ClassDataFull : ClassData {
597
    constexpr ClassDataFull(ClassData base,
598
                            void (*merge_to_from)(MessageLite& to,
599
                                                  const MessageLite& from_msg),
600
                            const DescriptorMethods* descriptor_methods,
601
                            const internal::DescriptorTable* descriptor_table,
602
                            void (*get_metadata_tracker)())
603
        : ClassData(base),
604
          merge_to_from(merge_to_from),
605
          descriptor_methods(descriptor_methods),
606
          descriptor_table(descriptor_table),
607
          reflection(),
608
          descriptor(),
609
0
          get_metadata_tracker(get_metadata_tracker) {}
610
611
26.0M
    constexpr const ClassData* base() const { return this; }
612
613
    void (*merge_to_from)(MessageLite& to, const MessageLite& from_msg);
614
    const DescriptorMethods* descriptor_methods;
615
616
    // Codegen types will provide a DescriptorTable to do lazy
617
    // registration/initialization of the reflection objects.
618
    // Other types, like DynamicMessage, keep the table as null but eagerly
619
    // populate `reflection`/`descriptor` fields.
620
    const internal::DescriptorTable* descriptor_table;
621
    // Accesses are protected by the once_flag in `descriptor_table`. When the
622
    // table is null these are populated from the beginning and need to
623
    // protection.
624
    mutable const Reflection* reflection;
625
    mutable const Descriptor* descriptor;
626
627
    // When an access tracker is installed, this function notifies the tracker
628
    // that GetMetadata was called.
629
    void (*get_metadata_tracker)();
630
  };
631
632
  // GetClassData() returns a pointer to a ClassData struct which
633
  // exists in global memory and is unique to each subclass.  This uniqueness
634
  // property is used in order to quickly determine whether two messages are
635
  // of the same type.
636
  //
637
  // This is a work in progress. There are still some types (eg MapEntry) that
638
  // return a default table instead of a unique one.
639
  virtual const ClassData* GetClassData() const = 0;
640
641
  internal::InternalMetadata _internal_metadata_;
642
643
  // Return the cached size object as described by
644
  // ClassData::cached_size_offset.
645
  internal::CachedSize& AccessCachedSize() const;
646
647
 public:
648
  enum ParseFlags {
649
    kMerge = 0,
650
    kParse = 1,
651
    kMergePartial = 2,
652
    kParsePartial = 3,
653
    kMergeWithAliasing = 4,
654
    kParseWithAliasing = 5,
655
    kMergePartialWithAliasing = 6,
656
    kParsePartialWithAliasing = 7
657
  };
658
659
  template <ParseFlags flags, typename T>
660
  bool ParseFrom(const T& input);
661
662
  // Fast path when conditions match (ie. non-deterministic)
663
  //  uint8_t* _InternalSerialize(uint8_t* ptr) const;
664
  virtual uint8_t* _InternalSerialize(
665
      uint8_t* ptr, io::EpsCopyOutputStream* stream) const = 0;
666
667
  // Identical to IsInitialized() except that it logs an error message.
668
0
  bool IsInitializedWithErrors() const {
669
0
    if (IsInitialized()) return true;
670
0
    LogInitializationErrorMessage();
671
0
    return false;
672
0
  }
673
674
 private:
675
  friend class FastReflectionMessageMutator;
676
  friend class AssignDescriptorsHelper;
677
  friend class FastReflectionStringSetter;
678
  friend class Message;
679
  friend class Reflection;
680
  friend class internal::DescriptorPoolExtensionFinder;
681
  friend class internal::ExtensionSet;
682
  friend class internal::LazyField;
683
  friend class internal::SwapFieldHelper;
684
  friend class internal::TcParser;
685
  friend class internal::WeakFieldMap;
686
  friend class internal::WireFormatLite;
687
688
  template <typename Type>
689
  friend class Arena::InternalHelper;
690
  template <typename Type>
691
  friend class internal::GenericTypeHandler;
692
693
  void LogInitializationErrorMessage() const;
694
695
  bool MergeFromImpl(io::CodedInputStream* input, ParseFlags parse_flags);
696
697
  template <typename T, const void* ptr = T::_raw_default_instance_>
698
0
  static constexpr auto GetStrongPointerForTypeImpl(int) {
699
0
    return ptr;
700
0
  }
701
  template <typename T>
702
  static constexpr auto GetStrongPointerForTypeImpl(char) {
703
    return &T::default_instance;
704
  }
705
  // Return a pointer we can use to make a strong reference to a type.
706
  // Ideally, this is a pointer to the default instance.
707
  // If we can't get that, then we use a pointer to the `default_instance`
708
  // function. The latter always works but pins the function artificially into
709
  // the binary so we avoid it.
710
  template <typename T>
711
0
  static constexpr auto GetStrongPointerForType() {
712
0
    return GetStrongPointerForTypeImpl<T>(0);
713
0
  }
714
  template <typename T>
715
  friend void internal::StrongReferenceToType();
716
};
717
718
namespace internal {
719
720
template <bool alias>
721
bool MergeFromImpl(absl::string_view input, MessageLite* msg,
722
                   const internal::TcParseTableBase* tc_table,
723
                   MessageLite::ParseFlags parse_flags);
724
extern template PROTOBUF_EXPORT_TEMPLATE_DECLARE bool MergeFromImpl<false>(
725
    absl::string_view input, MessageLite* msg,
726
    const internal::TcParseTableBase* tc_table,
727
    MessageLite::ParseFlags parse_flags);
728
extern template PROTOBUF_EXPORT_TEMPLATE_DECLARE bool MergeFromImpl<true>(
729
    absl::string_view input, MessageLite* msg,
730
    const internal::TcParseTableBase* tc_table,
731
    MessageLite::ParseFlags parse_flags);
732
733
template <bool alias>
734
bool MergeFromImpl(io::ZeroCopyInputStream* input, MessageLite* msg,
735
                   const internal::TcParseTableBase* tc_table,
736
                   MessageLite::ParseFlags parse_flags);
737
extern template PROTOBUF_EXPORT_TEMPLATE_DECLARE bool MergeFromImpl<false>(
738
    io::ZeroCopyInputStream* input, MessageLite* msg,
739
    const internal::TcParseTableBase* tc_table,
740
    MessageLite::ParseFlags parse_flags);
741
extern template PROTOBUF_EXPORT_TEMPLATE_DECLARE bool MergeFromImpl<true>(
742
    io::ZeroCopyInputStream* input, MessageLite* msg,
743
    const internal::TcParseTableBase* tc_table,
744
    MessageLite::ParseFlags parse_flags);
745
746
struct BoundedZCIS {
747
  io::ZeroCopyInputStream* zcis;
748
  int limit;
749
};
750
751
template <bool alias>
752
bool MergeFromImpl(BoundedZCIS input, MessageLite* msg,
753
                   const internal::TcParseTableBase* tc_table,
754
                   MessageLite::ParseFlags parse_flags);
755
extern template PROTOBUF_EXPORT_TEMPLATE_DECLARE bool MergeFromImpl<false>(
756
    BoundedZCIS input, MessageLite* msg,
757
    const internal::TcParseTableBase* tc_table,
758
    MessageLite::ParseFlags parse_flags);
759
extern template PROTOBUF_EXPORT_TEMPLATE_DECLARE bool MergeFromImpl<true>(
760
    BoundedZCIS input, MessageLite* msg,
761
    const internal::TcParseTableBase* tc_table,
762
    MessageLite::ParseFlags parse_flags);
763
764
template <typename T>
765
struct SourceWrapper;
766
767
template <bool alias, typename T>
768
bool MergeFromImpl(const SourceWrapper<T>& input, MessageLite* msg,
769
                   const internal::TcParseTableBase* tc_table,
770
                   MessageLite::ParseFlags parse_flags) {
771
  return input.template MergeInto<alias>(msg, tc_table, parse_flags);
772
}
773
774
}  // namespace internal
775
776
template <MessageLite::ParseFlags flags, typename T>
777
bool MessageLite::ParseFrom(const T& input) {
778
  if (flags & kParse) Clear();
779
  constexpr bool alias = (flags & kMergeWithAliasing) != 0;
780
  const internal::TcParseTableBase* tc_table;
781
  PROTOBUF_ALWAYS_INLINE_CALL tc_table = GetTcParseTable();
782
  return internal::MergeFromImpl<alias>(input, this, tc_table, flags);
783
}
784
785
// ===================================================================
786
// Shutdown support.
787
788
789
// Shut down the entire protocol buffers library, deleting all static-duration
790
// objects allocated by the library or by generated .pb.cc files.
791
//
792
// There are two reasons you might want to call this:
793
// * You use a draconian definition of "memory leak" in which you expect
794
//   every single malloc() to have a corresponding free(), even for objects
795
//   which live until program exit.
796
// * You are writing a dynamically-loaded library which needs to clean up
797
//   after itself when the library is unloaded.
798
//
799
// It is safe to call this multiple times.  However, it is not safe to use
800
// any other part of the protocol buffers library after
801
// ShutdownProtobufLibrary() has been called. Furthermore this call is not
802
// thread safe, user needs to synchronize multiple calls.
803
PROTOBUF_EXPORT void ShutdownProtobufLibrary();
804
805
namespace internal {
806
807
// Register a function to be called when ShutdownProtocolBuffers() is called.
808
PROTOBUF_EXPORT void OnShutdown(void (*func)());
809
// Run an arbitrary function on an arg
810
PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg);
811
812
template <typename T>
813
T* OnShutdownDelete(T* p) {
814
  OnShutdownRun([](const void* pp) { delete static_cast<const T*>(pp); }, p);
815
  return p;
816
}
817
818
}  // namespace internal
819
820
std::string ShortFormat(const MessageLite& message_lite);
821
std::string Utf8Format(const MessageLite& message_lite);
822
823
}  // namespace protobuf
824
}  // namespace google
825
826
#include "google/protobuf/port_undef.inc"
827
828
#endif  // GOOGLE_PROTOBUF_MESSAGE_LITE_H__