protobuf/src/google/protobuf/message.h
Go to the documentation of this file.
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 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 //
35 // Defines Message, the abstract interface implemented by non-lite
36 // protocol message objects. Although it's possible to implement this
37 // interface manually, most users will use the protocol compiler to
38 // generate implementations.
39 //
40 // Example usage:
41 //
42 // Say you have a message defined as:
43 //
44 // message Foo {
45 // optional string text = 1;
46 // repeated int32 numbers = 2;
47 // }
48 //
49 // Then, if you used the protocol compiler to generate a class from the above
50 // definition, you could use it like so:
51 //
52 // std::string data; // Will store a serialized version of the message.
53 //
54 // {
55 // // Create a message and serialize it.
56 // Foo foo;
57 // foo.set_text("Hello World!");
58 // foo.add_numbers(1);
59 // foo.add_numbers(5);
60 // foo.add_numbers(42);
61 //
62 // foo.SerializeToString(&data);
63 // }
64 //
65 // {
66 // // Parse the serialized message and check that it contains the
67 // // correct data.
68 // Foo foo;
69 // foo.ParseFromString(data);
70 //
71 // assert(foo.text() == "Hello World!");
72 // assert(foo.numbers_size() == 3);
73 // assert(foo.numbers(0) == 1);
74 // assert(foo.numbers(1) == 5);
75 // assert(foo.numbers(2) == 42);
76 // }
77 //
78 // {
79 // // Same as the last block, but do it dynamically via the Message
80 // // reflection interface.
81 // Message* foo = new Foo;
82 // const Descriptor* descriptor = foo->GetDescriptor();
83 //
84 // // Get the descriptors for the fields we're interested in and verify
85 // // their types.
86 // const FieldDescriptor* text_field = descriptor->FindFieldByName("text");
87 // assert(text_field != nullptr);
88 // assert(text_field->type() == FieldDescriptor::TYPE_STRING);
89 // assert(text_field->label() == FieldDescriptor::LABEL_OPTIONAL);
90 // const FieldDescriptor* numbers_field = descriptor->
91 // FindFieldByName("numbers");
92 // assert(numbers_field != nullptr);
93 // assert(numbers_field->type() == FieldDescriptor::TYPE_INT32);
94 // assert(numbers_field->label() == FieldDescriptor::LABEL_REPEATED);
95 //
96 // // Parse the message.
97 // foo->ParseFromString(data);
98 //
99 // // Use the reflection interface to examine the contents.
100 // const Reflection* reflection = foo->GetReflection();
101 // assert(reflection->GetString(*foo, text_field) == "Hello World!");
102 // assert(reflection->FieldSize(*foo, numbers_field) == 3);
103 // assert(reflection->GetRepeatedInt32(*foo, numbers_field, 0) == 1);
104 // assert(reflection->GetRepeatedInt32(*foo, numbers_field, 1) == 5);
105 // assert(reflection->GetRepeatedInt32(*foo, numbers_field, 2) == 42);
106 //
107 // delete foo;
108 // }
109 
110 #ifndef GOOGLE_PROTOBUF_MESSAGE_H__
111 #define GOOGLE_PROTOBUF_MESSAGE_H__
112 
113 #include <iosfwd>
114 #include <string>
115 #include <type_traits>
116 #include <vector>
117 
118 #include <google/protobuf/stubs/casts.h>
119 #include <google/protobuf/stubs/common.h>
120 #include <google/protobuf/arena.h>
121 #include <google/protobuf/descriptor.h>
122 #include <google/protobuf/generated_message_reflection.h>
123 #include <google/protobuf/generated_message_util.h>
124 #include <google/protobuf/message_lite.h>
125 #include <google/protobuf/port.h>
126 
127 
128 #define GOOGLE_PROTOBUF_HAS_ONEOF
129 #define GOOGLE_PROTOBUF_HAS_ARENAS
130 
131 #include <google/protobuf/port_def.inc>
132 
133 #ifdef SWIG
134 #error "You cannot SWIG proto headers"
135 #endif
136 
137 namespace google {
138 namespace protobuf {
139 
140 // Defined in this file.
141 class Message;
142 class Reflection;
143 class MessageFactory;
144 
145 // Defined in other files.
146 class AssignDescriptorsHelper;
148 class DynamicMessageReflectionHelper;
149 class GeneratedMessageReflectionTestHelper;
150 class MapKey;
151 class MapValueConstRef;
152 class MapValueRef;
153 class MapIterator;
154 class MapReflectionTester;
155 
156 namespace internal {
157 struct DescriptorTable;
158 class MapFieldBase;
159 class SwapFieldHelper;
160 class CachedSize;
161 } // namespace internal
162 class UnknownFieldSet; // unknown_field_set.h
163 namespace io {
164 class ZeroCopyInputStream; // zero_copy_stream.h
165 class ZeroCopyOutputStream; // zero_copy_stream.h
166 class CodedInputStream; // coded_stream.h
167 class CodedOutputStream; // coded_stream.h
168 } // namespace io
169 namespace python {
170 class MapReflectionFriend; // scalar_map_container.h
171 class MessageReflectionFriend;
172 } // namespace python
173 namespace expr {
174 class CelMapReflectionFriend; // field_backed_map_impl.cc
175 }
176 
177 namespace internal {
178 class MapFieldPrinterHelper; // text_format.cc
179 }
180 namespace util {
181 class MessageDifferencer;
182 }
183 
184 
185 namespace internal {
186 class ReflectionAccessor; // message.cc
187 class ReflectionOps; // reflection_ops.h
188 class MapKeySorter; // wire_format.cc
189 class WireFormat; // wire_format.h
190 class MapFieldReflectionTest; // map_test.cc
191 } // namespace internal
192 
193 template <typename T>
194 class RepeatedField; // repeated_field.h
195 
196 template <typename T>
197 class RepeatedPtrField; // repeated_field.h
198 
199 // A container to hold message metadata.
200 struct Metadata {
201  const Descriptor* descriptor;
202  const Reflection* reflection;
203 };
204 
205 namespace internal {
206 template <class To>
208  return reinterpret_cast<To*>(reinterpret_cast<char*>(message) + offset);
209 }
210 
211 template <class To>
213  return reinterpret_cast<const To*>(reinterpret_cast<const char*>(message) +
214  offset);
215 }
216 
217 template <class To>
219  return *GetConstPointerAtOffset<To>(&message, offset);
220 }
221 
223 } // namespace internal
224 
225 // Abstract interface for protocol messages.
226 //
227 // See also MessageLite, which contains most every-day operations. Message
228 // adds descriptors and reflection on top of that.
229 //
230 // The methods of this class that are virtual but not pure-virtual have
231 // default implementations based on reflection. Message classes which are
232 // optimized for speed will want to override these with faster implementations,
233 // but classes optimized for code size may be happy with keeping them. See
234 // the optimize_for option in descriptor.proto.
235 //
236 // Users must not derive from this class. Only the protocol compiler and
237 // the internal library are allowed to create subclasses.
238 class PROTOBUF_EXPORT Message : public MessageLite {
239  public:
240  constexpr Message() {}
241 
242  // Basic Operations ------------------------------------------------
243 
244  // Construct a new instance of the same type. Ownership is passed to the
245  // caller. (This is also defined in MessageLite, but is defined again here
246  // for return-type covariance.)
247  Message* New() const { return New(nullptr); }
248 
249  // Construct a new instance on the arena. Ownership is passed to the caller
250  // if arena is a nullptr.
251  Message* New(Arena* arena) const override = 0;
252 
253  // Make this message into a copy of the given message. The given message
254  // must have the same descriptor, but need not necessarily be the same class.
255  // By default this is just implemented as "Clear(); MergeFrom(from);".
256  virtual void CopyFrom(const Message& from);
257 
258  // Merge the fields from the given message into this message. Singular
259  // fields will be overwritten, if specified in from, except for embedded
260  // messages which will be merged. Repeated fields will be concatenated.
261  // The given message must be of the same type as this message (i.e. the
262  // exact same class).
263  virtual void MergeFrom(const Message& from);
264 
265  // Verifies that IsInitialized() returns true. GOOGLE_CHECK-fails otherwise, with
266  // a nice error message.
267  void CheckInitialized() const;
268 
269  // Slowly build a list of all required fields that are not set.
270  // This is much, much slower than IsInitialized() as it is implemented
271  // purely via reflection. Generally, you should not call this unless you
272  // have already determined that an error exists by calling IsInitialized().
273  void FindInitializationErrors(std::vector<std::string>* errors) const;
274 
275  // Like FindInitializationErrors, but joins all the strings, delimited by
276  // commas, and returns them.
277  std::string InitializationErrorString() const override;
278 
279  // Clears all unknown fields from this message and all embedded messages.
280  // Normally, if unknown tag numbers are encountered when parsing a message,
281  // the tag and value are stored in the message's UnknownFieldSet and
282  // then written back out when the message is serialized. This allows servers
283  // which simply route messages to other servers to pass through messages
284  // that have new field definitions which they don't yet know about. However,
285  // this behavior can have security implications. To avoid it, call this
286  // method after parsing.
287  //
288  // See Reflection::GetUnknownFields() for more on unknown fields.
289  void DiscardUnknownFields();
290 
291  // Computes (an estimate of) the total number of bytes currently used for
292  // storing the message in memory. The default implementation calls the
293  // Reflection object's SpaceUsed() method.
294  //
295  // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented
296  // using reflection (rather than the generated code implementation for
297  // ByteSize()). Like ByteSize(), its CPU time is linear in the number of
298  // fields defined for the proto.
299  virtual size_t SpaceUsedLong() const;
300 
301  PROTOBUF_DEPRECATED_MSG("Please use SpaceUsedLong() instead")
302  int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); }
303 
304  // Debugging & Testing----------------------------------------------
305 
306  // Generates a human readable form of this message, useful for debugging
307  // and other purposes.
308  std::string DebugString() const;
309  // Like DebugString(), but with less whitespace.
310  std::string ShortDebugString() const;
311  // Like DebugString(), but do not escape UTF-8 byte sequences.
312  std::string Utf8DebugString() const;
313  // Convenience function useful in GDB. Prints DebugString() to stdout.
314  void PrintDebugString() const;
315 
316  // Reflection-based methods ----------------------------------------
317  // These methods are pure-virtual in MessageLite, but Message provides
318  // reflection-based default implementations.
319 
320  std::string GetTypeName() const override;
321  void Clear() override;
322 
323  // Returns whether all required fields have been set. Note that required
324  // fields no longer exist starting in proto3.
325  bool IsInitialized() const override;
326 
327  void CheckTypeAndMergeFrom(const MessageLite& other) override;
328  // Reflective parser
329  const char* _InternalParse(const char* ptr,
330  internal::ParseContext* ctx) override;
331  size_t ByteSizeLong() const override;
333  io::EpsCopyOutputStream* stream) const override;
334 
335  private:
336  // This is called only by the default implementation of ByteSize(), to
337  // update the cached size. If you override ByteSize(), you do not need
338  // to override this. If you do not override ByteSize(), you MUST override
339  // this; the default implementation will crash.
340  //
341  // The method is private because subclasses should never call it; only
342  // override it. Yes, C++ lets you do that. Crazy, huh?
343  virtual void SetCachedSize(int size) const;
344 
345  public:
346  // Introspection ---------------------------------------------------
347 
348 
349  // Get a non-owning pointer to a Descriptor for this message's type. This
350  // describes what fields the message contains, the types of those fields, etc.
351  // This object remains property of the Message.
352  const Descriptor* GetDescriptor() const { return GetMetadata().descriptor; }
353 
354  // Get a non-owning pointer to the Reflection interface for this Message,
355  // which can be used to read and modify the fields of the Message dynamically
356  // (in other words, without knowing the message type at compile time). This
357  // object remains property of the Message.
358  const Reflection* GetReflection() const { return GetMetadata().reflection; }
359 
360  protected:
361  // Get a struct containing the metadata for the Message, which is used in turn
362  // to implement GetDescriptor() and GetReflection() above.
363  virtual Metadata GetMetadata() const = 0;
364 
365  struct ClassData {
366  // Note: The order of arguments (to, then from) is chosen so that the ABI
367  // of this function is the same as the CopyFrom method. That is, the
368  // hidden "this" parameter comes first.
369  void (*copy_to_from)(Message* to, const Message& from_msg);
370  void (*merge_to_from)(Message* to, const Message& from_msg);
371  };
372  // GetClassData() returns a pointer to a ClassData struct which
373  // exists in global memory and is unique to each subclass. This uniqueness
374  // property is used in order to quickly determine whether two messages are
375  // of the same type.
376  // TODO(jorg): change to pure virtual
377  virtual const ClassData* GetClassData() const { return nullptr; }
378 
379  // CopyWithSizeCheck calls Clear() and then MergeFrom(), and in debug
380  // builds, checks that calling Clear() on the destination message doesn't
381  // alter the size of the source. It assumes the messages are known to be
382  // of the same type, and thus uses GetClassData().
383  static void CopyWithSizeCheck(Message* to, const Message& from);
384 
385  inline explicit Message(Arena* arena, bool is_message_owned = false)
386  : MessageLite(arena, is_message_owned) {}
387  size_t ComputeUnknownFieldsSize(size_t total_size,
388  internal::CachedSize* cached_size) const;
389  size_t MaybeComputeUnknownFieldsSize(size_t total_size,
390  internal::CachedSize* cached_size) const;
391 
392 
393  protected:
394  static uint64_t GetInvariantPerBuild(uint64_t salt);
395 
396  private:
398 };
399 
400 namespace internal {
401 // Forward-declare interfaces used to implement RepeatedFieldRef.
402 // These are protobuf internals that users shouldn't care about.
403 class RepeatedFieldAccessor;
404 } // namespace internal
405 
406 // Forward-declare RepeatedFieldRef templates. The second type parameter is
407 // used for SFINAE tricks. Users should ignore it.
408 template <typename T, typename Enable = void>
409 class RepeatedFieldRef;
410 
411 template <typename T, typename Enable = void>
412 class MutableRepeatedFieldRef;
413 
414 // This interface contains methods that can be used to dynamically access
415 // and modify the fields of a protocol message. Their semantics are
416 // similar to the accessors the protocol compiler generates.
417 //
418 // To get the Reflection for a given Message, call Message::GetReflection().
419 //
420 // This interface is separate from Message only for efficiency reasons;
421 // the vast majority of implementations of Message will share the same
422 // implementation of Reflection (GeneratedMessageReflection,
423 // defined in generated_message.h), and all Messages of a particular class
424 // should share the same Reflection object (though you should not rely on
425 // the latter fact).
426 //
427 // There are several ways that these methods can be used incorrectly. For
428 // example, any of the following conditions will lead to undefined
429 // results (probably assertion failures):
430 // - The FieldDescriptor is not a field of this message type.
431 // - The method called is not appropriate for the field's type. For
432 // each field type in FieldDescriptor::TYPE_*, there is only one
433 // Get*() method, one Set*() method, and one Add*() method that is
434 // valid for that type. It should be obvious which (except maybe
435 // for TYPE_BYTES, which are represented using strings in C++).
436 // - A Get*() or Set*() method for singular fields is called on a repeated
437 // field.
438 // - GetRepeated*(), SetRepeated*(), or Add*() is called on a non-repeated
439 // field.
440 // - The Message object passed to any method is not of the right type for
441 // this Reflection object (i.e. message.GetReflection() != reflection).
442 //
443 // You might wonder why there is not any abstract representation for a field
444 // of arbitrary type. E.g., why isn't there just a "GetField()" method that
445 // returns "const Field&", where "Field" is some class with accessors like
446 // "GetInt32Value()". The problem is that someone would have to deal with
447 // allocating these Field objects. For generated message classes, having to
448 // allocate space for an additional object to wrap every field would at least
449 // double the message's memory footprint, probably worse. Allocating the
450 // objects on-demand, on the other hand, would be expensive and prone to
451 // memory leaks. So, instead we ended up with this flat interface.
452 class PROTOBUF_EXPORT Reflection final {
453  public:
454  // Get the UnknownFieldSet for the message. This contains fields which
455  // were seen when the Message was parsed but were not recognized according
456  // to the Message's definition.
457  const UnknownFieldSet& GetUnknownFields(const Message& message) const;
458  // Get a mutable pointer to the UnknownFieldSet for the message. This
459  // contains fields which were seen when the Message was parsed but were not
460  // recognized according to the Message's definition.
461  UnknownFieldSet* MutableUnknownFields(Message* message) const;
462 
463  // Estimate the amount of memory used by the message object.
464  size_t SpaceUsedLong(const Message& message) const;
465 
466  PROTOBUF_DEPRECATED_MSG("Please use SpaceUsedLong() instead")
467  int SpaceUsed(const Message& message) const {
468  return internal::ToIntSize(SpaceUsedLong(message));
469  }
470 
471  // Check if the given non-repeated field is set.
472  bool HasField(const Message& message, const FieldDescriptor* field) const;
473 
474  // Get the number of elements of a repeated field.
475  int FieldSize(const Message& message, const FieldDescriptor* field) const;
476 
477  // Clear the value of a field, so that HasField() returns false or
478  // FieldSize() returns zero.
479  void ClearField(Message* message, const FieldDescriptor* field) const;
480 
481  // Check if the oneof is set. Returns true if any field in oneof
482  // is set, false otherwise.
483  bool HasOneof(const Message& message,
484  const OneofDescriptor* oneof_descriptor) const;
485 
486  void ClearOneof(Message* message,
487  const OneofDescriptor* oneof_descriptor) const;
488 
489  // Returns the field descriptor if the oneof is set. nullptr otherwise.
490  const FieldDescriptor* GetOneofFieldDescriptor(
491  const Message& message, const OneofDescriptor* oneof_descriptor) const;
492 
493  // Removes the last element of a repeated field.
494  // We don't provide a way to remove any element other than the last
495  // because it invites inefficient use, such as O(n^2) filtering loops
496  // that should have been O(n). If you want to remove an element other
497  // than the last, the best way to do it is to re-arrange the elements
498  // (using Swap()) so that the one you want removed is at the end, then
499  // call RemoveLast().
500  void RemoveLast(Message* message, const FieldDescriptor* field) const;
501  // Removes the last element of a repeated message field, and returns the
502  // pointer to the caller. Caller takes ownership of the returned pointer.
503  PROTOBUF_NODISCARD Message* ReleaseLast(Message* message,
504  const FieldDescriptor* field) const;
505 
506  // Similar to ReleaseLast() without internal safety and ownershp checks. This
507  // method should only be used when the objects are on the same arena or paired
508  // with a call to `UnsafeArenaAddAllocatedMessage`.
509  Message* UnsafeArenaReleaseLast(Message* message,
510  const FieldDescriptor* field) const;
511 
512  // Swap the complete contents of two messages.
513  void Swap(Message* message1, Message* message2) const;
514 
515  // Swap fields listed in fields vector of two messages.
516  void SwapFields(Message* message1, Message* message2,
517  const std::vector<const FieldDescriptor*>& fields) const;
518 
519  // Swap two elements of a repeated field.
520  void SwapElements(Message* message, const FieldDescriptor* field, int index1,
521  int index2) const;
522 
523  // Swap without internal safety and ownership checks. This method should only
524  // be used when the objects are on the same arena.
525  void UnsafeArenaSwap(Message* lhs, Message* rhs) const;
526 
527  // SwapFields without internal safety and ownership checks. This method should
528  // only be used when the objects are on the same arena.
529  void UnsafeArenaSwapFields(
530  Message* lhs, Message* rhs,
531  const std::vector<const FieldDescriptor*>& fields) const;
532 
533  // List all fields of the message which are currently set, except for unknown
534  // fields, but including extension known to the parser (i.e. compiled in).
535  // Singular fields will only be listed if HasField(field) would return true
536  // and repeated fields will only be listed if FieldSize(field) would return
537  // non-zero. Fields (both normal fields and extension fields) will be listed
538  // ordered by field number.
539  // Use Reflection::GetUnknownFields() or message.unknown_fields() to also get
540  // access to fields/extensions unknown to the parser.
541  void ListFields(const Message& message,
542  std::vector<const FieldDescriptor*>* output) const;
543 
544  // Singular field getters ------------------------------------------
545  // These get the value of a non-repeated field. They return the default
546  // value for fields that aren't set.
547 
548  int32_t GetInt32(const Message& message, const FieldDescriptor* field) const;
549  int64_t GetInt64(const Message& message, const FieldDescriptor* field) const;
550  uint32_t GetUInt32(const Message& message,
551  const FieldDescriptor* field) const;
552  uint64_t GetUInt64(const Message& message,
553  const FieldDescriptor* field) const;
554  float GetFloat(const Message& message, const FieldDescriptor* field) const;
555  double GetDouble(const Message& message, const FieldDescriptor* field) const;
556  bool GetBool(const Message& message, const FieldDescriptor* field) const;
558  const FieldDescriptor* field) const;
559  const EnumValueDescriptor* GetEnum(const Message& message,
560  const FieldDescriptor* field) const;
561 
562  // GetEnumValue() returns an enum field's value as an integer rather than
563  // an EnumValueDescriptor*. If the integer value does not correspond to a
564  // known value descriptor, a new value descriptor is created. (Such a value
565  // will only be present when the new unknown-enum-value semantics are enabled
566  // for a message.)
567  int GetEnumValue(const Message& message, const FieldDescriptor* field) const;
568 
569  // See MutableMessage() for the meaning of the "factory" parameter.
570  const Message& GetMessage(const Message& message,
571  const FieldDescriptor* field,
572  MessageFactory* factory = nullptr) const;
573 
574  // Get a string value without copying, if possible.
575  //
576  // GetString() necessarily returns a copy of the string. This can be
577  // inefficient when the std::string is already stored in a std::string object
578  // in the underlying message. GetStringReference() will return a reference to
579  // the underlying std::string in this case. Otherwise, it will copy the
580  // string into *scratch and return that.
581  //
582  // Note: It is perfectly reasonable and useful to write code like:
583  // str = reflection->GetStringReference(message, field, &str);
584  // This line would ensure that only one copy of the string is made
585  // regardless of the field's underlying representation. When initializing
586  // a newly-constructed string, though, it's just as fast and more
587  // readable to use code like:
588  // std::string str = reflection->GetString(message, field);
589  const std::string& GetStringReference(const Message& message,
590  const FieldDescriptor* field,
591  std::string* scratch) const;
592 
593 
594  // Singular field mutators -----------------------------------------
595  // These mutate the value of a non-repeated field.
596 
597  void SetInt32(Message* message, const FieldDescriptor* field,
598  int32_t value) const;
599  void SetInt64(Message* message, const FieldDescriptor* field,
600  int64_t value) const;
601  void SetUInt32(Message* message, const FieldDescriptor* field,
602  uint32_t value) const;
603  void SetUInt64(Message* message, const FieldDescriptor* field,
604  uint64_t value) const;
605  void SetFloat(Message* message, const FieldDescriptor* field,
606  float value) const;
607  void SetDouble(Message* message, const FieldDescriptor* field,
608  double value) const;
609  void SetBool(Message* message, const FieldDescriptor* field,
610  bool value) const;
611  void SetString(Message* message, const FieldDescriptor* field,
612  std::string value) const;
613  void SetEnum(Message* message, const FieldDescriptor* field,
614  const EnumValueDescriptor* value) const;
615  // Set an enum field's value with an integer rather than EnumValueDescriptor.
616  // For proto3 this is just setting the enum field to the value specified, for
617  // proto2 it's more complicated. If value is a known enum value the field is
618  // set as usual. If the value is unknown then it is added to the unknown field
619  // set. Note this matches the behavior of parsing unknown enum values.
620  // If multiple calls with unknown values happen than they are all added to the
621  // unknown field set in order of the calls.
622  void SetEnumValue(Message* message, const FieldDescriptor* field,
623  int value) const;
624 
625  // Get a mutable pointer to a field with a message type. If a MessageFactory
626  // is provided, it will be used to construct instances of the sub-message;
627  // otherwise, the default factory is used. If the field is an extension that
628  // does not live in the same pool as the containing message's descriptor (e.g.
629  // it lives in an overlay pool), then a MessageFactory must be provided.
630  // If you have no idea what that meant, then you probably don't need to worry
631  // about it (don't provide a MessageFactory). WARNING: If the
632  // FieldDescriptor is for a compiled-in extension, then
633  // factory->GetPrototype(field->message_type()) MUST return an instance of
634  // the compiled-in class for this type, NOT DynamicMessage.
635  Message* MutableMessage(Message* message, const FieldDescriptor* field,
636  MessageFactory* factory = nullptr) const;
637 
638  // Replaces the message specified by 'field' with the already-allocated object
639  // sub_message, passing ownership to the message. If the field contained a
640  // message, that message is deleted. If sub_message is nullptr, the field is
641  // cleared.
642  void SetAllocatedMessage(Message* message, Message* sub_message,
643  const FieldDescriptor* field) const;
644 
645  // Similar to `SetAllocatedMessage`, but omits all internal safety and
646  // ownership checks. This method should only be used when the objects are on
647  // the same arena or paired with a call to `UnsafeArenaReleaseMessage`.
648  void UnsafeArenaSetAllocatedMessage(Message* message, Message* sub_message,
649  const FieldDescriptor* field) const;
650 
651  // Releases the message specified by 'field' and returns the pointer,
652  // ReleaseMessage() will return the message the message object if it exists.
653  // Otherwise, it may or may not return nullptr. In any case, if the return
654  // value is non-null, the caller takes ownership of the pointer.
655  // If the field existed (HasField() is true), then the returned pointer will
656  // be the same as the pointer returned by MutableMessage().
657  // This function has the same effect as ClearField().
658  PROTOBUF_NODISCARD Message* ReleaseMessage(
660  MessageFactory* factory = nullptr) const;
661 
662  // Similar to `ReleaseMessage`, but omits all internal safety and ownership
663  // checks. This method should only be used when the objects are on the same
664  // arena or paired with a call to `UnsafeArenaSetAllocatedMessage`.
665  Message* UnsafeArenaReleaseMessage(Message* message,
666  const FieldDescriptor* field,
667  MessageFactory* factory = nullptr) const;
668 
669 
670  // Repeated field getters ------------------------------------------
671  // These get the value of one element of a repeated field.
672 
673  int32_t GetRepeatedInt32(const Message& message, const FieldDescriptor* field,
674  int index) const;
675  int64_t GetRepeatedInt64(const Message& message, const FieldDescriptor* field,
676  int index) const;
677  uint32_t GetRepeatedUInt32(const Message& message,
678  const FieldDescriptor* field, int index) const;
679  uint64_t GetRepeatedUInt64(const Message& message,
680  const FieldDescriptor* field, int index) const;
681  float GetRepeatedFloat(const Message& message, const FieldDescriptor* field,
682  int index) const;
683  double GetRepeatedDouble(const Message& message, const FieldDescriptor* field,
684  int index) const;
685  bool GetRepeatedBool(const Message& message, const FieldDescriptor* field,
686  int index) const;
687  std::string GetRepeatedString(const Message& message,
688  const FieldDescriptor* field, int index) const;
689  const EnumValueDescriptor* GetRepeatedEnum(const Message& message,
690  const FieldDescriptor* field,
691  int index) const;
692  // GetRepeatedEnumValue() returns an enum field's value as an integer rather
693  // than an EnumValueDescriptor*. If the integer value does not correspond to a
694  // known value descriptor, a new value descriptor is created. (Such a value
695  // will only be present when the new unknown-enum-value semantics are enabled
696  // for a message.)
697  int GetRepeatedEnumValue(const Message& message, const FieldDescriptor* field,
698  int index) const;
699  const Message& GetRepeatedMessage(const Message& message,
700  const FieldDescriptor* field,
701  int index) const;
702 
703  // See GetStringReference(), above.
704  const std::string& GetRepeatedStringReference(const Message& message,
705  const FieldDescriptor* field,
706  int index,
707  std::string* scratch) const;
708 
709 
710  // Repeated field mutators -----------------------------------------
711  // These mutate the value of one element of a repeated field.
712 
713  void SetRepeatedInt32(Message* message, const FieldDescriptor* field,
714  int index, int32_t value) const;
715  void SetRepeatedInt64(Message* message, const FieldDescriptor* field,
716  int index, int64_t value) const;
717  void SetRepeatedUInt32(Message* message, const FieldDescriptor* field,
718  int index, uint32_t value) const;
719  void SetRepeatedUInt64(Message* message, const FieldDescriptor* field,
720  int index, uint64_t value) const;
721  void SetRepeatedFloat(Message* message, const FieldDescriptor* field,
722  int index, float value) const;
723  void SetRepeatedDouble(Message* message, const FieldDescriptor* field,
724  int index, double value) const;
725  void SetRepeatedBool(Message* message, const FieldDescriptor* field,
726  int index, bool value) const;
727  void SetRepeatedString(Message* message, const FieldDescriptor* field,
728  int index, std::string value) const;
729  void SetRepeatedEnum(Message* message, const FieldDescriptor* field,
730  int index, const EnumValueDescriptor* value) const;
731  // Set an enum field's value with an integer rather than EnumValueDescriptor.
732  // For proto3 this is just setting the enum field to the value specified, for
733  // proto2 it's more complicated. If value is a known enum value the field is
734  // set as usual. If the value is unknown then it is added to the unknown field
735  // set. Note this matches the behavior of parsing unknown enum values.
736  // If multiple calls with unknown values happen than they are all added to the
737  // unknown field set in order of the calls.
738  void SetRepeatedEnumValue(Message* message, const FieldDescriptor* field,
739  int index, int value) const;
740  // Get a mutable pointer to an element of a repeated field with a message
741  // type.
742  Message* MutableRepeatedMessage(Message* message,
743  const FieldDescriptor* field,
744  int index) const;
745 
746 
747  // Repeated field adders -------------------------------------------
748  // These add an element to a repeated field.
749 
750  void AddInt32(Message* message, const FieldDescriptor* field,
751  int32_t value) const;
752  void AddInt64(Message* message, const FieldDescriptor* field,
753  int64_t value) const;
754  void AddUInt32(Message* message, const FieldDescriptor* field,
755  uint32_t value) const;
756  void AddUInt64(Message* message, const FieldDescriptor* field,
757  uint64_t value) const;
758  void AddFloat(Message* message, const FieldDescriptor* field,
759  float value) const;
760  void AddDouble(Message* message, const FieldDescriptor* field,
761  double value) const;
762  void AddBool(Message* message, const FieldDescriptor* field,
763  bool value) const;
764  void AddString(Message* message, const FieldDescriptor* field,
765  std::string value) const;
767  const EnumValueDescriptor* value) const;
768  // Add an integer value to a repeated enum field rather than
769  // EnumValueDescriptor. For proto3 this is just setting the enum field to the
770  // value specified, for proto2 it's more complicated. If value is a known enum
771  // value the field is set as usual. If the value is unknown then it is added
772  // to the unknown field set. Note this matches the behavior of parsing unknown
773  // enum values. If multiple calls with unknown values happen than they are all
774  // added to the unknown field set in order of the calls.
776  int value) const;
777  // See MutableMessage() for comments on the "factory" parameter.
779  MessageFactory* factory = nullptr) const;
780 
781  // Appends an already-allocated object 'new_entry' to the repeated field
782  // specified by 'field' passing ownership to the message.
783  void AddAllocatedMessage(Message* message, const FieldDescriptor* field,
784  Message* new_entry) const;
785 
786  // Similar to AddAllocatedMessage() without internal safety and ownership
787  // checks. This method should only be used when the objects are on the same
788  // arena or paired with a call to `UnsafeArenaReleaseLast`.
789  void UnsafeArenaAddAllocatedMessage(Message* message,
790  const FieldDescriptor* field,
791  Message* new_entry) const;
792 
793 
794  // Get a RepeatedFieldRef object that can be used to read the underlying
795  // repeated field. The type parameter T must be set according to the
796  // field's cpp type. The following table shows the mapping from cpp type
797  // to acceptable T.
798  //
799  // field->cpp_type() T
800  // CPPTYPE_INT32 int32_t
801  // CPPTYPE_UINT32 uint32_t
802  // CPPTYPE_INT64 int64_t
803  // CPPTYPE_UINT64 uint64_t
804  // CPPTYPE_DOUBLE double
805  // CPPTYPE_FLOAT float
806  // CPPTYPE_BOOL bool
807  // CPPTYPE_ENUM generated enum type or int32_t
808  // CPPTYPE_STRING std::string
809  // CPPTYPE_MESSAGE generated message type or google::protobuf::Message
810  //
811  // A RepeatedFieldRef object can be copied and the resulted object will point
812  // to the same repeated field in the same message. The object can be used as
813  // long as the message is not destroyed.
814  //
815  // Note that to use this method users need to include the header file
816  // "reflection.h" (which defines the RepeatedFieldRef class templates).
817  template <typename T>
818  RepeatedFieldRef<T> GetRepeatedFieldRef(const Message& message,
819  const FieldDescriptor* field) const;
820 
821  // Like GetRepeatedFieldRef() but return an object that can also be used
822  // manipulate the underlying repeated field.
823  template <typename T>
824  MutableRepeatedFieldRef<T> GetMutableRepeatedFieldRef(
825  Message* message, const FieldDescriptor* field) const;
826 
827  // DEPRECATED. Please use Get(Mutable)RepeatedFieldRef() for repeated field
828  // access. The following repeated field accessors will be removed in the
829  // future.
830  //
831  // Repeated field accessors -------------------------------------------------
832  // The methods above, e.g. GetRepeatedInt32(msg, fd, index), provide singular
833  // access to the data in a RepeatedField. The methods below provide aggregate
834  // access by exposing the RepeatedField object itself with the Message.
835  // Applying these templates to inappropriate types will lead to an undefined
836  // reference at link time (e.g. GetRepeatedField<***double>), or possibly a
837  // template matching error at compile time (e.g. GetRepeatedPtrField<File>).
838  //
839  // Usage example: my_doubs = refl->GetRepeatedField<double>(msg, fd);
840 
841  // DEPRECATED. Please use GetRepeatedFieldRef().
842  //
843  // for T = Cord and all protobuf scalar types except enums.
844  template <typename T>
845  PROTOBUF_DEPRECATED_MSG("Please use GetRepeatedFieldRef() instead")
846  const RepeatedField<T>& GetRepeatedField(const Message& msg,
847  const FieldDescriptor* d) const {
848  return GetRepeatedFieldInternal<T>(msg, d);
849  }
850 
851  // DEPRECATED. Please use GetMutableRepeatedFieldRef().
852  //
853  // for T = Cord and all protobuf scalar types except enums.
854  template <typename T>
855  PROTOBUF_DEPRECATED_MSG("Please use GetMutableRepeatedFieldRef() instead")
856  RepeatedField<T>* MutableRepeatedField(Message* msg,
857  const FieldDescriptor* d) const {
858  return MutableRepeatedFieldInternal<T>(msg, d);
859  }
860 
861  // DEPRECATED. Please use GetRepeatedFieldRef().
862  //
863  // for T = std::string, google::protobuf::internal::StringPieceField
864  // google::protobuf::Message & descendants.
865  template <typename T>
866  PROTOBUF_DEPRECATED_MSG("Please use GetRepeatedFieldRef() instead")
867  const RepeatedPtrField<T>& GetRepeatedPtrField(
868  const Message& msg, const FieldDescriptor* d) const {
869  return GetRepeatedPtrFieldInternal<T>(msg, d);
870  }
871 
872  // DEPRECATED. Please use GetMutableRepeatedFieldRef().
873  //
874  // for T = std::string, google::protobuf::internal::StringPieceField
875  // google::protobuf::Message & descendants.
876  template <typename T>
877  PROTOBUF_DEPRECATED_MSG("Please use GetMutableRepeatedFieldRef() instead")
878  RepeatedPtrField<T>* MutableRepeatedPtrField(Message* msg,
879  const FieldDescriptor* d) const {
880  return MutableRepeatedPtrFieldInternal<T>(msg, d);
881  }
882 
883  // Extensions ----------------------------------------------------------------
884 
885  // Try to find an extension of this message type by fully-qualified field
886  // name. Returns nullptr if no extension is known for this name or number.
887  const FieldDescriptor* FindKnownExtensionByName(
888  const std::string& name) const;
889 
890  // Try to find an extension of this message type by field number.
891  // Returns nullptr if no extension is known for this name or number.
892  const FieldDescriptor* FindKnownExtensionByNumber(int number) const;
893 
894  // Feature Flags -------------------------------------------------------------
895 
896  // Does this message support storing arbitrary integer values in enum fields?
897  // If |true|, GetEnumValue/SetEnumValue and associated repeated-field versions
898  // take arbitrary integer values, and the legacy GetEnum() getter will
899  // dynamically create an EnumValueDescriptor for any integer value without
900  // one. If |false|, setting an unknown enum value via the integer-based
901  // setters results in undefined behavior (in practice, GOOGLE_DCHECK-fails).
902  //
903  // Generic code that uses reflection to handle messages with enum fields
904  // should check this flag before using the integer-based setter, and either
905  // downgrade to a compatible value or use the UnknownFieldSet if not. For
906  // example:
907  //
908  // int new_value = GetValueFromApplicationLogic();
909  // if (reflection->SupportsUnknownEnumValues()) {
910  // reflection->SetEnumValue(message, field, new_value);
911  // } else {
912  // if (field_descriptor->enum_type()->
913  // FindValueByNumber(new_value) != nullptr) {
914  // reflection->SetEnumValue(message, field, new_value);
915  // } else if (emit_unknown_enum_values) {
916  // reflection->MutableUnknownFields(message)->AddVarint(
917  // field->number(), new_value);
918  // } else {
919  // // convert value to a compatible/default value.
920  // new_value = CompatibleDowngrade(new_value);
921  // reflection->SetEnumValue(message, field, new_value);
922  // }
923  // }
924  bool SupportsUnknownEnumValues() const;
925 
926  // Returns the MessageFactory associated with this message. This can be
927  // useful for determining if a message is a generated message or not, for
928  // example:
929  // if (message->GetReflection()->GetMessageFactory() ==
930  // google::protobuf::MessageFactory::generated_factory()) {
931  // // This is a generated message.
932  // }
933  // It can also be used to create more messages of this type, though
934  // Message::New() is an easier way to accomplish this.
935  MessageFactory* GetMessageFactory() const;
936 
937  private:
938  template <typename T>
939  const RepeatedField<T>& GetRepeatedFieldInternal(
940  const Message& message, const FieldDescriptor* field) const;
941  template <typename T>
942  RepeatedField<T>* MutableRepeatedFieldInternal(
943  Message* message, const FieldDescriptor* field) const;
944  template <typename T>
945  const RepeatedPtrField<T>& GetRepeatedPtrFieldInternal(
946  const Message& message, const FieldDescriptor* field) const;
947  template <typename T>
948  RepeatedPtrField<T>* MutableRepeatedPtrFieldInternal(
949  Message* message, const FieldDescriptor* field) const;
950  // Obtain a pointer to a Repeated Field Structure and do some type checking:
951  // on field->cpp_type(),
952  // on field->field_option().ctype() (if ctype >= 0)
953  // of field->message_type() (if message_type != nullptr).
954  // We use 2 routine rather than 4 (const vs mutable) x (scalar vs pointer).
955  void* MutableRawRepeatedField(Message* message, const FieldDescriptor* field,
956  FieldDescriptor::CppType, int ctype,
957  const Descriptor* message_type) const;
958 
959  const void* GetRawRepeatedField(const Message& message,
960  const FieldDescriptor* field,
961  FieldDescriptor::CppType cpptype, int ctype,
962  const Descriptor* message_type) const;
963 
964  // The following methods are used to implement (Mutable)RepeatedFieldRef.
965  // A Ref object will store a raw pointer to the repeated field data (obtained
966  // from RepeatedFieldData()) and a pointer to a Accessor (obtained from
967  // RepeatedFieldAccessor) which will be used to access the raw data.
968 
969  // Returns a raw pointer to the repeated field
970  //
971  // "cpp_type" and "message_type" are deduced from the type parameter T passed
972  // to Get(Mutable)RepeatedFieldRef. If T is a generated message type,
973  // "message_type" should be set to its descriptor. Otherwise "message_type"
974  // should be set to nullptr. Implementations of this method should check
975  // whether "cpp_type"/"message_type" is consistent with the actual type of the
976  // field. We use 1 routine rather than 2 (const vs mutable) because it is
977  // protected and it doesn't change the message.
978  void* RepeatedFieldData(Message* message, const FieldDescriptor* field,
980  const Descriptor* message_type) const;
981 
982  // The returned pointer should point to a singleton instance which implements
983  // the RepeatedFieldAccessor interface.
984  const internal::RepeatedFieldAccessor* RepeatedFieldAccessor(
985  const FieldDescriptor* field) const;
986 
987  // Lists all fields of the message which are currently set, except for unknown
988  // fields and stripped fields. See ListFields for details.
989  void ListFieldsOmitStripped(
990  const Message& message,
991  std::vector<const FieldDescriptor*>* output) const;
992 
994  return schema_.IsMessageStripped(descriptor);
995  }
996 
997  friend class TextFormat;
998 
999  void ListFieldsMayFailOnStripped(
1000  const Message& message, bool should_fail,
1001  std::vector<const FieldDescriptor*>* output) const;
1002 
1003  // Returns true if the message field is backed by a LazyField.
1004  //
1005  // A message field may be backed by a LazyField without the user annotation
1006  // ([lazy = true]). While the user-annotated LazyField is lazily verified on
1007  // first touch (i.e. failure on access rather than parsing if the LazyField is
1008  // not initialized), the inferred LazyField is eagerly verified to avoid lazy
1009  // parsing error at the cost of lower efficiency. When reflecting a message
1010  // field, use this API instead of checking field->options().lazy().
1011  bool IsLazyField(const FieldDescriptor* field) const {
1012  return IsLazilyVerifiedLazyField(field) ||
1013  IsEagerlyVerifiedLazyField(field);
1014  }
1015 
1016  // Returns true if the field is lazy extension. It is meant to allow python
1017  // reparse lazy field until b/157559327 is fixed.
1018  bool IsLazyExtension(const Message& message,
1019  const FieldDescriptor* field) const;
1020 
1021  bool IsLazilyVerifiedLazyField(const FieldDescriptor* field) const;
1022  bool IsEagerlyVerifiedLazyField(const FieldDescriptor* field) const;
1023 
1024  friend class FastReflectionMessageMutator;
1025 
1026  const Descriptor* const descriptor_;
1027  const internal::ReflectionSchema schema_;
1028  const DescriptorPool* const descriptor_pool_;
1029  MessageFactory* const message_factory_;
1030 
1031  // Last non weak field index. This is an optimization when most weak fields
1032  // are at the end of the containing message. If a message proto doesn't
1033  // contain weak fields, then this field equals descriptor_->field_count().
1034  int last_non_weak_field_index_;
1035 
1036  template <typename T, typename Enable>
1037  friend class RepeatedFieldRef;
1038  template <typename T, typename Enable>
1040  friend class ::PROTOBUF_NAMESPACE_ID::MessageLayoutInspector;
1041  friend class ::PROTOBUF_NAMESPACE_ID::AssignDescriptorsHelper;
1042  friend class DynamicMessageFactory;
1045  friend class python::MapReflectionFriend;
1048 #define GOOGLE_PROTOBUF_HAS_CEL_MAP_REFLECTION_FRIEND
1049  friend class expr::CelMapReflectionFriend;
1050  friend class internal::MapFieldReflectionTest;
1051  friend class internal::MapKeySorter;
1052  friend class internal::WireFormat;
1053  friend class internal::ReflectionOps;
1055  // Needed for implementing text format for map.
1056  friend class internal::MapFieldPrinterHelper;
1057 
1059  const internal::ReflectionSchema& schema,
1060  const DescriptorPool* pool, MessageFactory* factory);
1061 
1062  // Special version for specialized implementations of string. We can't
1063  // call MutableRawRepeatedField directly here because we don't have access to
1064  // FieldOptions::* which are defined in descriptor.pb.h. Including that
1065  // file here is not possible because it would cause a circular include cycle.
1066  // We use 1 routine rather than 2 (const vs mutable) because it is private
1067  // and mutable a repeated string field doesn't change the message.
1068  void* MutableRawRepeatedString(Message* message, const FieldDescriptor* field,
1069  bool is_string) const;
1070 
1071  friend class MapReflectionTester;
1072  // Returns true if key is in map. Returns false if key is not in map field.
1073  bool ContainsMapKey(const Message& message, const FieldDescriptor* field,
1074  const MapKey& key) const;
1075 
1076  // If key is in map field: Saves the value pointer to val and returns
1077  // false. If key in not in map field: Insert the key into map, saves
1078  // value pointer to val and returns true. Users are able to modify the
1079  // map value by MapValueRef.
1080  bool InsertOrLookupMapValue(Message* message, const FieldDescriptor* field,
1081  const MapKey& key, MapValueRef* val) const;
1082 
1083  // If key is in map field: Saves the value pointer to val and returns true.
1084  // Returns false if key is not in map field. Users are NOT able to modify
1085  // the value by MapValueConstRef.
1086  bool LookupMapValue(const Message& message, const FieldDescriptor* field,
1087  const MapKey& key, MapValueConstRef* val) const;
1088  bool LookupMapValue(const Message&, const FieldDescriptor*, const MapKey&,
1089  MapValueRef*) const = delete;
1090 
1091  // Delete and returns true if key is in the map field. Returns false
1092  // otherwise.
1093  bool DeleteMapValue(Message* message, const FieldDescriptor* field,
1094  const MapKey& key) const;
1095 
1096  // Returns a MapIterator referring to the first element in the map field.
1097  // If the map field is empty, this function returns the same as
1098  // reflection::MapEnd. Mutation to the field may invalidate the iterator.
1099  MapIterator MapBegin(Message* message, const FieldDescriptor* field) const;
1100 
1101  // Returns a MapIterator referring to the theoretical element that would
1102  // follow the last element in the map field. It does not point to any
1103  // real element. Mutation to the field may invalidate the iterator.
1104  MapIterator MapEnd(Message* message, const FieldDescriptor* field) const;
1105 
1106  // Get the number of <key, value> pair of a map field. The result may be
1107  // different from FieldSize which can have duplicate keys.
1108  int MapSize(const Message& message, const FieldDescriptor* field) const;
1109 
1110  // Help method for MapIterator.
1111  friend class MapIterator;
1112  friend class WireFormatForMapFieldTest;
1113  internal::MapFieldBase* MutableMapData(Message* message,
1114  const FieldDescriptor* field) const;
1115 
1116  const internal::MapFieldBase* GetMapData(const Message& message,
1117  const FieldDescriptor* field) const;
1118 
1119  template <class T>
1120  const T& GetRawNonOneof(const Message& message,
1121  const FieldDescriptor* field) const;
1122  template <class T>
1123  T* MutableRawNonOneof(Message* message, const FieldDescriptor* field) const;
1124 
1125  template <typename Type>
1126  const Type& GetRaw(const Message& message,
1127  const FieldDescriptor* field) const;
1128  template <typename Type>
1129  inline Type* MutableRaw(Message* message, const FieldDescriptor* field) const;
1130  template <typename Type>
1131  const Type& DefaultRaw(const FieldDescriptor* field) const;
1132 
1133  const Message* GetDefaultMessageInstance(const FieldDescriptor* field) const;
1134 
1135  inline const uint32_t* GetHasBits(const Message& message) const;
1136  inline uint32_t* MutableHasBits(Message* message) const;
1137  inline uint32_t GetOneofCase(const Message& message,
1138  const OneofDescriptor* oneof_descriptor) const;
1139  inline uint32_t* MutableOneofCase(
1140  Message* message, const OneofDescriptor* oneof_descriptor) const;
1141  inline bool HasExtensionSet(const Message& /* message */) const {
1142  return schema_.HasExtensionSet();
1143  }
1145  internal::ExtensionSet* MutableExtensionSet(Message* message) const;
1146 
1147  inline const internal::InternalMetadata& GetInternalMetadata(
1148  const Message& message) const;
1149 
1150  internal::InternalMetadata* MutableInternalMetadata(Message* message) const;
1151 
1152  inline bool IsInlined(const FieldDescriptor* field) const;
1153 
1154  inline bool HasBit(const Message& message,
1155  const FieldDescriptor* field) const;
1156  inline void SetBit(Message* message, const FieldDescriptor* field) const;
1157  inline void ClearBit(Message* message, const FieldDescriptor* field) const;
1158  inline void SwapBit(Message* message1, Message* message2,
1159  const FieldDescriptor* field) const;
1160 
1161  inline const uint32_t* GetInlinedStringDonatedArray(
1162  const Message& message) const;
1163  inline uint32_t* MutableInlinedStringDonatedArray(Message* message) const;
1164  inline bool IsInlinedStringDonated(const Message& message,
1165  const FieldDescriptor* field) const;
1166 
1167  // Shallow-swap fields listed in fields vector of two messages. It is the
1168  // caller's responsibility to make sure shallow swap is safe.
1169  void UnsafeShallowSwapFields(
1170  Message* message1, Message* message2,
1171  const std::vector<const FieldDescriptor*>& fields) const;
1172 
1173  // This function only swaps the field. Should swap corresponding has_bit
1174  // before or after using this function.
1175  void SwapField(Message* message1, Message* message2,
1176  const FieldDescriptor* field) const;
1177 
1178  // Unsafe but shallow version of SwapField.
1179  void UnsafeShallowSwapField(Message* message1, Message* message2,
1180  const FieldDescriptor* field) const;
1181 
1182  template <bool unsafe_shallow_swap>
1183  void SwapFieldsImpl(Message* message1, Message* message2,
1184  const std::vector<const FieldDescriptor*>& fields) const;
1185 
1186  template <bool unsafe_shallow_swap>
1187  void SwapOneofField(Message* lhs, Message* rhs,
1188  const OneofDescriptor* oneof_descriptor) const;
1189 
1190  inline bool HasOneofField(const Message& message,
1191  const FieldDescriptor* field) const;
1192  inline void SetOneofCase(Message* message,
1193  const FieldDescriptor* field) const;
1194  inline void ClearOneofField(Message* message,
1195  const FieldDescriptor* field) const;
1196 
1197  template <typename Type>
1198  inline const Type& GetField(const Message& message,
1199  const FieldDescriptor* field) const;
1200  template <typename Type>
1201  inline void SetField(Message* message, const FieldDescriptor* field,
1202  const Type& value) const;
1203  template <typename Type>
1204  inline Type* MutableField(Message* message,
1205  const FieldDescriptor* field) const;
1206  template <typename Type>
1207  inline const Type& GetRepeatedField(const Message& message,
1208  const FieldDescriptor* field,
1209  int index) const;
1210  template <typename Type>
1211  inline const Type& GetRepeatedPtrField(const Message& message,
1212  const FieldDescriptor* field,
1213  int index) const;
1214  template <typename Type>
1215  inline void SetRepeatedField(Message* message, const FieldDescriptor* field,
1216  int index, Type value) const;
1217  template <typename Type>
1218  inline Type* MutableRepeatedField(Message* message,
1219  const FieldDescriptor* field,
1220  int index) const;
1221  template <typename Type>
1222  inline void AddField(Message* message, const FieldDescriptor* field,
1223  const Type& value) const;
1224  template <typename Type>
1225  inline Type* AddField(Message* message, const FieldDescriptor* field) const;
1226 
1227  int GetExtensionNumberOrDie(const Descriptor* type) const;
1228 
1229  // Internal versions of EnumValue API perform no checking. Called after checks
1230  // by public methods.
1231  void SetEnumValueInternal(Message* message, const FieldDescriptor* field,
1232  int value) const;
1233  void SetRepeatedEnumValueInternal(Message* message,
1234  const FieldDescriptor* field, int index,
1235  int value) const;
1236  void AddEnumValueInternal(Message* message, const FieldDescriptor* field,
1237  int value) const;
1238 
1239  friend inline // inline so nobody can call this function.
1240  void
1241  RegisterAllTypesInternal(const Metadata* file_level_metadata, int size);
1242  friend inline const char* ParseLenDelim(int field_number,
1243  const FieldDescriptor* field,
1244  Message* msg,
1245  const Reflection* reflection,
1246  const char* ptr,
1248  friend inline const char* ParsePackedField(const FieldDescriptor* field,
1249  Message* msg,
1250  const Reflection* reflection,
1251  const char* ptr,
1253 
1255 };
1256 
1257 // Abstract interface for a factory for message objects.
1258 class PROTOBUF_EXPORT MessageFactory {
1259  public:
1260  inline MessageFactory() {}
1261  virtual ~MessageFactory();
1262 
1263  // Given a Descriptor, gets or constructs the default (prototype) Message
1264  // of that type. You can then call that message's New() method to construct
1265  // a mutable message of that type.
1266  //
1267  // Calling this method twice with the same Descriptor returns the same
1268  // object. The returned object remains property of the factory. Also, any
1269  // objects created by calling the prototype's New() method share some data
1270  // with the prototype, so these must be destroyed before the MessageFactory
1271  // is destroyed.
1272  //
1273  // The given descriptor must outlive the returned message, and hence must
1274  // outlive the MessageFactory.
1275  //
1276  // Some implementations do not support all types. GetPrototype() will
1277  // return nullptr if the descriptor passed in is not supported.
1278  //
1279  // This method may or may not be thread-safe depending on the implementation.
1280  // Each implementation should document its own degree thread-safety.
1281  virtual const Message* GetPrototype(const Descriptor* type) = 0;
1282 
1283  // Gets a MessageFactory which supports all generated, compiled-in messages.
1284  // In other words, for any compiled-in type FooMessage, the following is true:
1285  // MessageFactory::generated_factory()->GetPrototype(
1286  // FooMessage::descriptor()) == FooMessage::default_instance()
1287  // This factory supports all types which are found in
1288  // DescriptorPool::generated_pool(). If given a descriptor from any other
1289  // pool, GetPrototype() will return nullptr. (You can also check if a
1290  // descriptor is for a generated message by checking if
1291  // descriptor->file()->pool() == DescriptorPool::generated_pool().)
1292  //
1293  // This factory is 100% thread-safe; calling GetPrototype() does not modify
1294  // any shared data.
1295  //
1296  // This factory is a singleton. The caller must not delete the object.
1297  static MessageFactory* generated_factory();
1298 
1299  // For internal use only: Registers a .proto file at static initialization
1300  // time, to be placed in generated_factory. The first time GetPrototype()
1301  // is called with a descriptor from this file, |register_messages| will be
1302  // called, with the file name as the parameter. It must call
1303  // InternalRegisterGeneratedMessage() (below) to register each message type
1304  // in the file. This strange mechanism is necessary because descriptors are
1305  // built lazily, so we can't register types by their descriptor until we
1306  // know that the descriptor exists. |filename| must be a permanent string.
1307  static void InternalRegisterGeneratedFile(
1309 
1310  // For internal use only: Registers a message type. Called only by the
1311  // functions which are registered with InternalRegisterGeneratedFile(),
1312  // above.
1313  static void InternalRegisterGeneratedMessage(const Descriptor* descriptor,
1314  const Message* prototype);
1315 
1316 
1317  private:
1319 };
1320 
1321 #define DECLARE_GET_REPEATED_FIELD(TYPE) \
1322  template <> \
1323  PROTOBUF_EXPORT const RepeatedField<TYPE>& \
1324  Reflection::GetRepeatedFieldInternal<TYPE>( \
1325  const Message& message, const FieldDescriptor* field) const; \
1326  \
1327  template <> \
1328  PROTOBUF_EXPORT RepeatedField<TYPE>* \
1329  Reflection::MutableRepeatedFieldInternal<TYPE>( \
1330  Message * message, const FieldDescriptor* field) const;
1331 
1339 
1340 #undef DECLARE_GET_REPEATED_FIELD
1341 
1342 // Tries to downcast this message to a generated message type. Returns nullptr
1343 // if this class is not an instance of T. This works even if RTTI is disabled.
1344 //
1345 // This also has the effect of creating a strong reference to T that will
1346 // prevent the linker from stripping it out at link time. This can be important
1347 // if you are using a DynamicMessageFactory that delegates to the generated
1348 // factory.
1349 template <typename T>
1350 const T* DynamicCastToGenerated(const Message* from) {
1351  // Compile-time assert that T is a generated type that has a
1352  // default_instance() accessor, but avoid actually calling it.
1353  const T& (*get_default_instance)() = &T::default_instance;
1354  (void)get_default_instance;
1355 
1356  // Compile-time assert that T is a subclass of google::protobuf::Message.
1357  const Message* unused = static_cast<T*>(nullptr);
1358  (void)unused;
1359 
1360 #if PROTOBUF_RTTI
1361  return dynamic_cast<const T*>(from);
1362 #else
1363  bool ok = from != nullptr &&
1364  T::default_instance().GetReflection() == from->GetReflection();
1365  return ok ? down_cast<const T*>(from) : nullptr;
1366 #endif
1367 }
1368 
1369 template <typename T>
1371  const Message* message_const = from;
1372  return const_cast<T*>(DynamicCastToGenerated<T>(message_const));
1373 }
1374 
1375 // Call this function to ensure that this message's reflection is linked into
1376 // the binary:
1377 //
1378 // google::protobuf::LinkMessageReflection<FooMessage>();
1379 //
1380 // This will ensure that the following lookup will succeed:
1381 //
1382 // DescriptorPool::generated_pool()->FindMessageTypeByName("FooMessage");
1383 //
1384 // As a side-effect, it will also guarantee that anything else from the same
1385 // .proto file will also be available for lookup in the generated pool.
1386 //
1387 // This function does not actually register the message, so it does not need
1388 // to be called before the lookup. However it does need to occur in a function
1389 // that cannot be stripped from the binary (ie. it must be reachable from main).
1390 //
1391 // Best practice is to call this function as close as possible to where the
1392 // reflection is actually needed. This function is very cheap to call, so you
1393 // should not need to worry about its runtime overhead except in the tightest
1394 // of loops (on x86-64 it compiles into two "mov" instructions).
1395 template <typename T>
1396 void LinkMessageReflection() {
1397  internal::StrongReference(T::default_instance);
1398 }
1399 
1400 // =============================================================================
1401 // Implementation details for {Get,Mutable}RawRepeatedPtrField. We provide
1402 // specializations for <std::string>, <StringPieceField> and <Message> and
1403 // handle everything else with the default template which will match any type
1404 // having a method with signature "static const google::protobuf::Descriptor*
1405 // descriptor()". Such a type presumably is a descendant of google::protobuf::Message.
1406 
1407 template <>
1408 inline const RepeatedPtrField<std::string>&
1409 Reflection::GetRepeatedPtrFieldInternal<std::string>(
1410  const Message& message, const FieldDescriptor* field) const {
1411  return *static_cast<RepeatedPtrField<std::string>*>(
1412  MutableRawRepeatedString(const_cast<Message*>(&message), field, true));
1413 }
1414 
1415 template <>
1416 inline RepeatedPtrField<std::string>*
1417 Reflection::MutableRepeatedPtrFieldInternal<std::string>(
1418  Message* message, const FieldDescriptor* field) const {
1419  return static_cast<RepeatedPtrField<std::string>*>(
1420  MutableRawRepeatedString(message, field, true));
1421 }
1422 
1423 
1424 // -----
1425 
1426 template <>
1428  const Message& message, const FieldDescriptor* field) const {
1429  return *static_cast<const RepeatedPtrField<Message>*>(GetRawRepeatedField(
1431 }
1432 
1433 template <>
1435  Message* message, const FieldDescriptor* field) const {
1438 }
1439 
1440 template <typename PB>
1442  const Message& message, const FieldDescriptor* field) const {
1443  return *static_cast<const RepeatedPtrField<PB>*>(
1445  PB::default_instance().GetDescriptor()));
1446 }
1447 
1448 template <typename PB>
1449 inline RepeatedPtrField<PB>* Reflection::MutableRepeatedPtrFieldInternal(
1450  Message* message, const FieldDescriptor* field) const {
1451  return static_cast<RepeatedPtrField<PB>*>(
1453  -1, PB::default_instance().GetDescriptor()));
1454 }
1455 
1456 template <typename Type>
1457 const Type& Reflection::DefaultRaw(const FieldDescriptor* field) const {
1458  return *reinterpret_cast<const Type*>(schema_.GetFieldDefault(field));
1459 }
1460 
1462  const Message& message, const OneofDescriptor* oneof_descriptor) const {
1463  GOOGLE_DCHECK(!oneof_descriptor->is_synthetic());
1464  return internal::GetConstRefAtOffset<uint32_t>(
1465  message, schema_.GetOneofCaseOffset(oneof_descriptor));
1466 }
1467 
1469  const FieldDescriptor* field) const {
1470  return (GetOneofCase(message, field->containing_oneof()) ==
1471  static_cast<uint32_t>(field->number()));
1472 }
1473 
1474 template <typename Type>
1475 const Type& Reflection::GetRaw(const Message& message,
1476  const FieldDescriptor* field) const {
1478  << "Field = " << field->full_name();
1479  return internal::GetConstRefAtOffset<Type>(message,
1481 }
1482 } // namespace protobuf
1483 } // namespace google
1484 
1485 #include <google/protobuf/port_undef.inc>
1486 
1487 #endif // GOOGLE_PROTOBUF_MESSAGE_H__
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
google::protobuf.internal::ReflectionSchema::GetOneofCaseOffset
uint32 GetOneofCaseOffset(const OneofDescriptor *oneof_descriptor) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.h:160
google::protobuf::Reflection::GetOneofCase
uint32 GetOneofCase(const Message &message, const OneofDescriptor *oneof_descriptor) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1877
google::protobuf.internal::ExtensionSet
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:175
descriptor_
string_view descriptor_
Definition: elf.cc:154
google::protobuf::RepeatedPtrField
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.h:62
google::protobuf::MutableRepeatedFieldRef
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:357
absl::swap_internal::Swap
void Swap(T &lhs, T &rhs) noexcept(IsNothrowSwappable< T >::value)
Definition: abseil-cpp/absl/meta/type_traits.h:772
google::protobuf::Reflection::HasOneofField
bool HasOneofField(const Message &message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:2027
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
DECLARE_GET_REPEATED_FIELD
#define DECLARE_GET_REPEATED_FIELD(TYPE)
Definition: protobuf/src/google/protobuf/message.h:1321
google::protobuf::FieldDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:515
google::protobuf.internal::GetConstRefAtOffset
const To & GetConstRefAtOffset(const Message &message, uint32_t offset)
Definition: protobuf/src/google/protobuf/message.h:218
google::protobuf::util::MessageDifferencer
Definition: bloaty/third_party/protobuf/src/google/protobuf/util/message_differencer.h:120
google::protobuf::DynamicMessageReflectionHelper
Definition: protobuf/src/google/protobuf/dynamic_message.cc:103
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/macros.h:40
ctx
Definition: benchmark-async.c:30
const
#define const
Definition: bloaty/third_party/zlib/zconf.h:230
google::protobuf::Metadata::reflection
const Reflection * reflection
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:192
grpc::protobuf::io::ZeroCopyInputStream
GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream
Definition: include/grpcpp/impl/codegen/config_protobuf.h:101
google::protobuf.internal.python_message.MergeFrom
MergeFrom
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1339
google::protobuf::Reflection::GetRepeatedPtrFieldInternal
const RepeatedPtrField< T > & GetRepeatedPtrFieldInternal(const Message &message, const FieldDescriptor *field) const
google::protobuf.internal::ReflectionSchema::GetFieldDefault
const void * GetFieldDefault(const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.h:207
GOOGLE_DCHECK
#define GOOGLE_DCHECK
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:194
phone_pb2.message_type
message_type
Definition: phone_pb2.py:200
google::protobuf::python::MapReflectionFriend
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:59
google::protobuf::Message::GetReflection
const Reflection * GetReflection() const
Definition: protobuf/src/google/protobuf/message.h:358
google::protobuf.internal.python_message.DiscardUnknownFields
DiscardUnknownFields
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1432
google::protobuf::python::cmessage::CopyFrom
static PyObject * CopyFrom(CMessage *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1862
Arena
Definition: arena.c:39
DebugString
std::string DebugString(const google::protobuf::Message &message)
Definition: bloaty/tests/test.h:60
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf.internal::ParseContext
Definition: bloaty/third_party/protobuf/src/google/protobuf/parse_context.h:336
New
T * New(Args &&... args)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:195
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
grpc::protobuf::DynamicMessageFactory
GRPC_CUSTOM_DYNAMICMESSAGEFACTORY DynamicMessageFactory
Definition: config_grpc_cli.h:54
google::protobuf::OneofDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:843
setup.name
name
Definition: setup.py:542
grpc::protobuf::io::ZeroCopyOutputStream
GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream
Definition: include/grpcpp/impl/codegen/config_protobuf.h:100
google::protobuf::Message::ClassData
Definition: protobuf/src/google/protobuf/message.h:365
google::protobuf::Reflection::schema_
const internal::ReflectionSchema schema_
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:876
google::protobuf::RepeatedField
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:184
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
testing::internal::GetTypeName
std::string GetTypeName()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-type-util.h:80
google::protobuf::Reflection::IsLazyField
bool IsLazyField(const FieldDescriptor *field) const
Definition: protobuf/src/google/protobuf/message.h:1011
google::protobuf.internal::GetExtensionSet
ExtensionSet * GetExtensionSet(MessageLite *msg, int64 extension_offset)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_table_driven_lite.h:94
google::protobuf::MessageLite
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:184
google::protobuf::Reflection
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:397
google::protobuf::GeneratedMessageReflectionTestHelper
Definition: protobuf/src/google/protobuf/generated_message_reflection_unittest.cc:68
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
google::protobuf.internal.python_message._InternalParse
_InternalParse
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1196
google::protobuf::Message::New
Message * New() const
Definition: protobuf/src/google/protobuf/message.h:247
google::protobuf.internal::ReflectionSchema::GetFieldOffset
uint32 GetFieldOffset(const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.h:138
google::protobuf::python::cmessage::UnknownFieldSet
static PyObject * UnknownFieldSet(CMessage *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2512
google::protobuf::MessageFactory
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:1066
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
T
#define T(upbtypeconst, upbtype, ctype, default_value)
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
google::protobuf::TextFormat
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.h:70
google::protobuf::SetField
void SetField(uint64 val, const FieldDescriptor *field, Message *msg, const Reflection *reflection)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.cc:162
google::protobuf::Message::Message
constexpr Message()
Definition: protobuf/src/google/protobuf/message.h:240
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
FieldDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:133
google::protobuf::io::EpsCopyOutputStream
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream.h:651
google::protobuf::python::repeated_composite_container::AddMessage
static PyObject * AddMessage(RepeatedCompositeContainer *self, PyObject *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc:109
google::protobuf::Message::Message
Message(Arena *arena, bool is_message_owned=false)
Definition: protobuf/src/google/protobuf/message.h:385
xds_interop_client.int
int
Definition: xds_interop_client.py:113
errors
const char * errors
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:841
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
Type
Definition: bloaty/third_party/protobuf/src/google/protobuf/type.pb.h:182
google::protobuf.internal::ToIntSize
int ToIntSize(size_t size)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:105
grpc::protobuf::MessageLite
GRPC_CUSTOM_MESSAGELITE MessageLite
Definition: include/grpcpp/impl/codegen/config_protobuf.h:79
google::protobuf.internal::SwapFieldHelper
Definition: protobuf/src/google/protobuf/generated_message_reflection.cc:462
google::protobuf.internal.python_message._InternalSerialize
_InternalSerialize
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1112
google::protobuf::LinkMessageReflection
void LinkMessageReflection()
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:1202
google::protobuf::MessageFactory::MessageFactory
MessageFactory()
Definition: protobuf/src/google/protobuf/message.h:1260
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
google::protobuf::ParsePackedField
const char * ParsePackedField(const FieldDescriptor *field, Message *msg, const Reflection *reflection, const char *ptr, internal::ParseContext *ctx)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.cc:240
grpc::protobuf::io::CodedInputStream
GRPC_CUSTOM_CODEDINPUTSTREAM CodedInputStream
Definition: include/grpcpp/impl/codegen/config_protobuf.h:102
google::protobuf::DescriptorPool
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1539
google::protobuf.internal::RepeatedFieldAccessor
Definition: bloaty/third_party/protobuf/src/google/protobuf/reflection.h:301
google::protobuf.internal::InternalMetadata
Definition: protobuf/src/google/protobuf/metadata_lite.h:62
grpc_core::ClearBit
T ClearBit(T *i, size_t n)
Definition: useful.h:55
number
int32_t number
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:850
google::protobuf::Reflection::GetRawRepeatedField
const void * GetRawRepeatedField(const Message &message, const FieldDescriptor *field, FieldDescriptor::CppType cpptype, int ctype, const Descriptor *message_type) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1723
io
grpc::protobuf::io::CodedOutputStream
GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream
Definition: src/compiler/config.h:55
google::protobuf.internal::GetConstPointerAtOffset
const To * GetConstPointerAtOffset(const Message *message, uint32_t offset)
Definition: protobuf/src/google/protobuf/message.h:212
google::protobuf.internal::DescriptorTable
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.h:265
google::protobuf.internal.python_message.ListFields
ListFields
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:819
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
google::protobuf.internal.python_message.ClearField
ClearField
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:902
google::protobuf.internal::CreateUnknownEnumValues
bool CreateUnknownEnumValues(const FieldDescriptor *field)
Definition: protobuf/src/google/protobuf/generated_message_reflection.cc:1439
google::protobuf::descriptor_unittest::AddField
FieldDescriptorProto * AddField(DescriptorProto *parent, const std::string &name, int number, FieldDescriptorProto::Label label, FieldDescriptorProto::Type type)
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor_unittest.cc:108
google::protobuf::Metadata::descriptor
const Descriptor * descriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:191
google::protobuf::DynamicMessageFactory
Definition: bloaty/third_party/protobuf/src/google/protobuf/dynamic_message.h:80
google::protobuf::Metadata
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:190
google::protobuf.internal::MutableField
Type * MutableField(MessageLite *msg, uint32 *has_bits, uint32 has_bit_index, int64 offset)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_table_driven_lite.h:135
google::protobuf::Reflection::MutableRawRepeatedField
void * MutableRawRepeatedField(Message *message, const FieldDescriptor *field, FieldDescriptor::CppType, int ctype, const Descriptor *message_type) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1697
GetString
static bool GetString(std::string *out, CBS *cbs)
Definition: ssl_ctx_api.cc:228
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
key
const char * key
Definition: hpack_parser_table.cc:164
google::protobuf::Message::GetDescriptor
const Descriptor * GetDescriptor() const
Definition: protobuf/src/google/protobuf/message.h:352
scratch
static char scratch[256]
Definition: test-random.c:27
google::protobuf::Reflection::HasExtensionSet
bool HasExtensionSet(const Message &) const
Definition: protobuf/src/google/protobuf/message.h:1141
google::protobuf::Reflection::DefaultRaw
const Type & DefaultRaw(const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1916
google::protobuf::Reflection::IsMessageStripped
bool IsMessageStripped(const Descriptor *descriptor) const
Definition: protobuf/src/google/protobuf/message.h:993
google::protobuf.internal.python_message.Clear
Clear
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1430
OneofDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:138
google::protobuf::DynamicCastToGenerated
const T * DynamicCastToGenerated(const Message *from)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:1157
google::protobuf::ParseLenDelim
const char * ParseLenDelim(int field_number, const FieldDescriptor *field, Message *msg, const Reflection *reflection, const char *ptr, internal::ParseContext *ctx)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.cc:282
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
google::protobuf.internal::CachedSize
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_util.h:170
google::protobuf::MapKey
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:371
profile_analyzer.fields
list fields
Definition: profile_analyzer.py:266
google::protobuf::Reflection::GetRaw
const Type & GetRaw(const Message &message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1849
google::protobuf::MapReflectionTester
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_test_util.h:50
ok
bool ok
Definition: async_end2end_test.cc:197
google::protobuf::EnumValueDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1075
google::protobuf::Descriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:231
google::protobuf::RegisterAllTypesInternal
void RegisterAllTypesInternal(const Metadata *file_level_metadata, int size)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:2393
google::protobuf::descriptor_unittest::AddEnum
EnumDescriptorProto * AddEnum(FileDescriptorProto *file, const std::string &name)
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor_unittest.cc:87
grpc_core::SetBit
T SetBit(T *i, size_t n)
Definition: useful.h:49
google::protobuf.internal.python_message.IsInitialized
IsInitialized
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1245
google::protobuf.internal::StrongReference
void StrongReference(const T &var)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/common.h:193
pool
InternalDescriptorPool * pool
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:807
google::protobuf.internal::GetPointerAtOffset
To * GetPointerAtOffset(Message *message, uint32_t offset)
Definition: protobuf/src/google/protobuf/message.h:207
google::protobuf.internal::ReflectionSchema
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.h:125
google::protobuf::Message::GetClassData
virtual const ClassData * GetClassData() const
Definition: protobuf/src/google/protobuf/message.h:377
internal
Definition: benchmark/test/output_test_helper.cc:20
google::protobuf.internal::MapFieldBase
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:69
table
uint8_t table[256]
Definition: hpack_parser.cc:456
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE
@ CPPTYPE_MESSAGE
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:563
google::protobuf::python::MessageReflectionFriend
Definition: protobuf/python/google/protobuf/pyext/message.cc:93
google::protobuf.internal::ComputeUnknownFieldsSize
size_t ComputeUnknownFieldsSize(const InternalMetadataWithArena &metadata, size_t total_size, CachedSize *cached_size)
Definition: bloaty/third_party/protobuf/src/google/protobuf/wire_format.cc:1350
grpc_binder::Metadata
std::vector< std::pair< std::string, std::string > > Metadata
Definition: transaction.h:38
google::protobuf.internal::ClearOneofField
void ClearOneofField(const ParseTableField &field, Arena *arena, MessageLite *msg)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_table_driven_lite.h:159
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
google::protobuf.internal.python_message.HasField
HasField
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:864
google::protobuf::descriptor_unittest::AddEnumValue
EnumValueDescriptorProto * AddEnumValue(EnumDescriptorProto *enum_proto, const std::string &name, int number)
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor_unittest.cc:171
google::protobuf.internal::ReflectionSchema::HasExtensionSet
bool HasExtensionSet() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.h:189
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
google::protobuf::Reflection::MutableRepeatedPtrFieldInternal
RepeatedPtrField< T > * MutableRepeatedPtrFieldInternal(Message *message, const FieldDescriptor *field) const
google::protobuf::MapIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:712
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
setup.target
target
Definition: third_party/bloaty/third_party/protobuf/python/setup.py:179
google::protobuf::FieldDescriptor::CppType
CppType
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:553
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::RepeatedFieldRef
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:354
google::protobuf::python::message_descriptor::GetDescriptor
static ParentDescriptor GetDescriptor(PyContainer *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.cc:951
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
google::protobuf.internal::MapFieldPrinterHelper
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.cc:2073
google::protobuf.internal::cpp_type
FieldDescriptor::CppType cpp_type(FieldType type)
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set_heavy.cc:133
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
google::protobuf::MapValueConstRef
Definition: protobuf/src/google/protobuf/map_field.h:685
google::protobuf::MapValueRef
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:565
google::protobuf.internal.python_message.FindInitializationErrors
FindInitializationErrors
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1291
google::protobuf.internal::ReflectionSchema::InRealOneof
bool InRealOneof(const FieldDescriptor *field) const
Definition: protobuf/src/google/protobuf/generated_message_reflection.h:124
RepeatedField
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:403
stream
voidpf stream
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:25