Go to the documentation of this file.
35 #include <google/protobuf/message.h>
39 #include <unordered_map>
41 #include <google/protobuf/stubs/casts.h>
42 #include <google/protobuf/stubs/logging.h>
43 #include <google/protobuf/stubs/common.h>
44 #include <google/protobuf/descriptor.pb.h>
45 #include <google/protobuf/parse_context.h>
46 #include <google/protobuf/reflection_internal.h>
47 #include <google/protobuf/io/coded_stream.h>
48 #include <google/protobuf/io/zero_copy_stream_impl.h>
49 #include <google/protobuf/descriptor.h>
50 #include <google/protobuf/generated_message_reflection.h>
51 #include <google/protobuf/generated_message_util.h>
52 #include <google/protobuf/map_field.h>
53 #include <google/protobuf/map_field_inl.h>
54 #include <google/protobuf/reflection_ops.h>
55 #include <google/protobuf/unknown_field_set.h>
56 #include <google/protobuf/wire_format.h>
57 #include <google/protobuf/wire_format_lite.h>
58 #include <google/protobuf/stubs/strutil.h>
59 #include <google/protobuf/stubs/map_util.h>
60 #include <google/protobuf/stubs/stl_util.h>
61 #include <google/protobuf/stubs/hash.h>
63 #include <google/protobuf/port_def.inc>
77 using internal::ReflectionOps;
78 using internal::WireFormat;
79 using internal::WireFormatLite;
83 auto* class_from =
from.GetClassData();
84 auto* merge_to_from = class_to ? class_to->merge_to_from :
nullptr;
85 if (class_to ==
nullptr || class_to != class_from) {
90 merge_to_from(
this,
from);
94 MergeFrom(*down_cast<const Message*>(&other));
98 if (&
from ==
this)
return;
101 auto* class_from =
from.GetClassData();
102 auto* copy_to_from = class_to ? class_to->copy_to_from :
nullptr;
104 if (class_to ==
nullptr || class_to != class_from) {
107 <<
": Tried to copy from a message with a different type. "
112 <<
from.GetDescriptor()->full_name();
117 copy_to_from(
this,
from);
122 size_t from_size =
from.ByteSizeLong();
127 <<
"Source of CopyFrom changed when clearing target. Either "
128 "source is a nested message in target (not allowed), or "
129 "another thread is modifying the source.";
131 to->GetClassData()->merge_to_from(
to,
from);
149 std::vector<std::string>
errors;
156 <<
"\" is missing required fields: "
165 internal::ParseContext*
ctx) {
182 <<
"\" implements neither SetCachedSize() nor ByteSize(). "
183 "Must implement one or the other.";
220 #define HASH_MAP std::unordered_map
221 #define STR_HASH_FXN hash<::google::protobuf::StringPiece>
224 class GeneratedMessageFactory final :
public MessageFactory {
226 static GeneratedMessageFactory* singleton();
242 std::unordered_map<const Descriptor*, const Message*>
type_map_;
245 GeneratedMessageFactory* GeneratedMessageFactory::singleton() {
251 void GeneratedMessageFactory::RegisterFile(
261 <<
"Tried to register a non-generated type with the generated "
286 const internal::DescriptorTable* registration_data =
288 if (registration_data ==
nullptr) {
289 GOOGLE_LOG(DFATAL) <<
"File appears to be in generated pool but wasn't "
291 <<
type->file()->name();
307 GOOGLE_LOG(DFATAL) <<
"Type appears to be in generated pool but wasn't "
308 <<
"registered: " <<
type->full_name();
317 return GeneratedMessageFactory::singleton();
322 GeneratedMessageFactory::singleton()->RegisterFile(
table);
327 GeneratedMessageFactory::singleton()->RegisterType(
descriptor, prototype);
332 template <
typename T>
342 switch (
field->cpp_type()) {
343 #define HANDLE_PRIMITIVE_TYPE(TYPE, type) \
344 case FieldDescriptor::CPPTYPE_##TYPE: \
345 return GetSingleton<internal::RepeatedFieldPrimitiveAccessor<type> >();
354 #undef HANDLE_PRIMITIVE_TYPE
356 switch (
field->options().ctype()) {
359 return GetSingleton<internal::RepeatedPtrFieldStringAccessor>();
363 if (
field->is_map()) {
364 return GetSingleton<internal::MapFieldAccessor>();
366 return GetSingleton<internal::RepeatedPtrFieldMessageAccessor>();
375 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
386 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
393 return value->GetOwningArena();
400 #include <google/protobuf/port_undef.inc>
const std::string & full_name() const
std::string InitializationErrorString() const override
std::unordered_map< const Descriptor *, const Message * > type_map_
#define WriterMutexLock(x)
const Descriptor::ReservedRange value
static void InternalRegisterGeneratedFile(const google::protobuf::internal::DescriptorTable *table)
void RegisterFileLevelMetadata(const DescriptorTable *table)
Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
const Reflection * GetReflection() const
#define HANDLE_PRIMITIVE_TYPE(TYPE, type)
#define GOOGLE_CHECK_EQ(A, B)
HASH_MAP< StringPiece, const google::protobuf::internal::DescriptorTable *, STR_HASH_FXN > file_map_
std::string GetTypeName() const override
static MessageFactory * generated_factory()
static void CopyWithSizeCheck(Message *to, const Message &from)
void CheckTypeAndMergeFrom(const MessageLite &other) override
RefCountedPtr< grpc_tls_certificate_provider > instance
virtual size_t SpaceUsedLong() const
size_t ComputeUnknownFieldsSize(size_t total_size, internal::CachedSize *cached_size) const
bool IsInitialized() const override
virtual ~MessageFactory()
size_t SpaceUsedLong(const Message &message) const
#define T(upbtypeconst, upbtype, ctype, default_value)
T * OnShutdownDelete(T *p)
grpc_core::ScopedArenaPtr arena
static void FindInitializationErrors(const Message &message, const std::string &prefix, std::vector< std::string > *errors)
internal::WrappedMutex mutex_
static void InternalRegisterGeneratedMessage(const Descriptor *descriptor, const Message *prototype)
static void Merge(const Message &from, Message *to)
virtual void SetCachedSize(int size) const
static const UnknownFieldSet * default_instance()
const internal::RepeatedFieldAccessor * RepeatedFieldAccessor(const FieldDescriptor *field) const
void CheckInitialized() const
GRPC_CUSTOM_MESSAGELITE MessageLite
static void DiscardUnknownFields(Message *message)
unsigned __int64 uint64_t
static constexpr CType STRING
size_t MaybeComputeUnknownFieldsSize(size_t total_size, internal::CachedSize *cached_size) const
virtual void DiscardUnknownFields()
size_t ByteSizeLong() const override
virtual void CopyFrom(const Message &from)
const FieldDescriptor * field
const Descriptor * GetDescriptor() const
#define ReaderMutexLock(x)
int ToCachedSize(size_t size)
static GenericType * NewFromPrototype(const GenericType *prototype, Arena *arena=NULL)
static const DescriptorPool * generated_pool()
internal::InternalMetadata _internal_metadata_
#define GOOGLE_CHECK(EXPRESSION)
static uint64_t GetInvariantPerBuild(uint64_t salt)
Message * New() const override=0
static Arena * GetOwningArena(GenericType *value)
static void Copy(const Message &from, Message *to)
virtual const ClassData * GetClassData() const
void Join(Iterator start, Iterator end, const char *delim, string *result)
static bool IsInitialized(const Message &message)
#define GOOGLE_LOG(LEVEL)
void FindInitializationErrors(std::vector< std::string > *errors) const
static const char descriptor[1336]
bool InsertIfNotPresent(Collection *const collection, const typename Collection::value_type &vt)
const char * _InternalParse(const char *ptr, internal::ParseContext *ctx) override
static void Clear(Message *message)
uint8_t * _InternalSerialize(uint8_t *target, io::EpsCopyOutputStream *stream) const override
virtual void MergeFrom(const Message &from)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:25