Go to the documentation of this file.
37 #include <unordered_map>
39 #include <google/protobuf/generated_message_reflection.h>
40 #include <google/protobuf/message.h>
42 #include <google/protobuf/stubs/casts.h>
43 #include <google/protobuf/stubs/logging.h>
44 #include <google/protobuf/stubs/common.h>
45 #include <google/protobuf/descriptor.pb.h>
46 #include <google/protobuf/parse_context.h>
47 #include <google/protobuf/reflection_internal.h>
48 #include <google/protobuf/io/coded_stream.h>
49 #include <google/protobuf/io/zero_copy_stream_impl.h>
50 #include <google/protobuf/descriptor.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;
84 <<
": Tried to merge from a message with a different type. "
89 <<
from.GetDescriptor()->full_name();
94 MergeFrom(*down_cast<const Message*>(&other));
100 <<
": Tried to copy from a message with a different type. "
105 <<
from.GetDescriptor()->full_name();
124 std::vector<std::string>
errors;
131 <<
"\" is missing required fields: "
145 return static_cast<char*
>(
msg) +
r->schema_.GetFieldOffset(f);
164 #define STORE_TYPE(CPPTYPE_METHOD) \
166 if (field->is_repeated()) { \
167 reflection->Add##CPPTYPE_METHOD(msg, field, value); \
169 reflection->Set##CPPTYPE_METHOD(msg, field, value); \
174 #define HANDLE_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \
175 case FieldDescriptor::TYPE_##TYPE: { \
176 CPPTYPE value = val; \
177 STORE_TYPE(CPPTYPE_METHOD); \
228 GOOGLE_LOG(
FATAL) <<
"Error in descriptors, primitve field with field type "
237 return d->FindValueByNumber(val) !=
nullptr;
244 #define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, METHOD_NAME) \
245 case FieldDescriptor::TYPE_##TYPE: \
246 return internal::Packed##METHOD_NAME##Parser( \
247 reflection->MutableRepeatedField<CPPTYPE>(msg, field), ptr, ctx)
274 #undef HANDLE_PACKED_TYPE
290 enum { kNone = 0, kVerify, kStrict } utf8_level = kNone;
291 const char* field_name =
nullptr;
292 auto parse_string = [
ptr,
ctx, &utf8_level,
294 switch (utf8_level) {
308 bool enforce_utf8 =
true;
309 bool utf8_verification =
true;
312 utf8_level = kStrict;
313 }
else if (utf8_verification) {
314 utf8_level = kVerify;
317 PROTOBUF_FALLTHROUGH_INTENDED;
329 return parse_string(
object);
334 return parse_string(
object);
344 return parse_string(
object);
349 return parse_string(
object);
361 return ctx->ParseMessage(
object,
ptr);
380 class ReflectiveFieldParser {
383 : ReflectiveFieldParser(
msg,
ctx,
false) {}
386 if (is_item_ &&
num == 2) {
387 if (!payload_.empty()) {
390 auto child = reflection_->MutableMessage(msg_,
field);
392 child->ParsePartialFromString(payload_);
394 MutableUnknown()->AddLengthDelimited(
value)->swap(payload_);
405 MutableUnknown()->AddVarint(
num,
value);
413 MutableUnknown()->AddFixed64(
num,
value);
416 const char* ParseLengthDelimited(
uint32 num,
const char*
ptr,
418 if (is_item_ &&
num == 3) {
430 MutableUnknown()->AddLengthDelimited(
num),
ptr,
ctx);
435 if (!is_item_ &&
descriptor_->options().message_set_wire_format() &&
456 MutableUnknown()->AddFixed32(
num,
value);
472 bool is_item_ =
false;
480 reflection_(
msg->GetReflection()),
499 if (
field ==
nullptr)
return nullptr;
503 if (
field->is_packable()) {
515 if (unknown_)
return unknown_;
520 ReflectiveFieldParser field_parser(
this,
ctx);
538 <<
"\" implements neither SetCachedSize() nor ByteSize(). "
539 "Must implement one or the other.";
555 static GeneratedMessageFactory* singleton();
571 std::unordered_map<const Descriptor*, const Message*>
type_map_;
574 GeneratedMessageFactory* GeneratedMessageFactory::singleton() {
580 void GeneratedMessageFactory::RegisterFile(
590 <<
"Tried to register a non-generated type with the generated "
615 const internal::DescriptorTable* registration_data =
617 if (registration_data == NULL) {
618 GOOGLE_LOG(DFATAL) <<
"File appears to be in generated pool but wasn't "
620 <<
type->file()->name();
636 GOOGLE_LOG(DFATAL) <<
"Type appears to be in generated pool but wasn't "
637 <<
"registered: " <<
type->full_name();
646 return GeneratedMessageFactory::singleton();
651 GeneratedMessageFactory::singleton()->RegisterFile(
table);
656 GeneratedMessageFactory::singleton()->RegisterType(
descriptor, prototype);
661 template <
typename T>
671 switch (
field->cpp_type()) {
672 #define HANDLE_PRIMITIVE_TYPE(TYPE, type) \
673 case FieldDescriptor::CPPTYPE_##TYPE: \
674 return GetSingleton<internal::RepeatedFieldPrimitiveAccessor<type> >();
683 #undef HANDLE_PRIMITIVE_TYPE
685 switch (
field->options().ctype()) {
688 return GetSingleton<internal::RepeatedPtrFieldStringAccessor>();
692 if (
field->is_map()) {
693 return GetSingleton<internal::MapFieldAccessor>();
695 return GetSingleton<internal::RepeatedPtrFieldMessageAccessor>();
704 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
715 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
722 return value->GetArena();
725 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
732 return value->GetMaybeArenaPointer();
const std::string & full_name() const
std::string InitializationErrorString() const override
const std::string & GetStringReference(const Message &message, const FieldDescriptor *field, std::string *scratch) const
#define HANDLE_PRIMITIVE_TYPE(TYPE, type)
const FieldOptions & options() const
#define WriterMutexLock(x)
const Descriptor::ReservedRange value
static void InternalRegisterGeneratedFile(const google::protobuf::internal::DescriptorTable *table)
static InternalMetadataWithArena * MutableInternalMetadataWithArena(const Reflection *reflection, Message *msg)
TypeWithSize< 4 >::Int Int32
void RegisterFileLevelMetadata(const DescriptorTable *table)
bool is_extension() const
const PROTOBUF_MUST_USE_RESULT char * InlineGreedyStringParserUTF8Verify(std::string *s, const char *ptr, ParseContext *ctx, const char *field_name)
const std::string & full_name() const
const FieldDescriptor * FindKnownExtensionByNumber(int number) const
Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
const Reflection * GetReflection() const
const char * UnknownFieldParse(uint32 tag, std::string *unknown, const char *ptr, ParseContext *ctx)
#define GOOGLE_CHECK_EQ(A, B)
std::string GetTypeName() const override
static MessageFactory * generated_factory()
TypeWithSize< 8 >::UInt UInt64
void CheckTypeAndMergeFrom(const MessageLite &other) override
RefCountedPtr< grpc_tls_certificate_provider > instance
virtual size_t SpaceUsedLong() const
static struct test_ctx ctx
bool IsInitialized() const override
TypeWithSize< 4 >::UInt UInt32
virtual ~MessageFactory()
HANDLE_TYPE(int32, FieldDescriptor::CPPTYPE_INT32, -1)
size_t SpaceUsedLong(const Message &message) const
#define T(upbtypeconst, upbtype, ctype, default_value)
T * OnShutdownDelete(T *p)
grpc_core::ScopedArenaPtr arena
const char * InlineGreedyStringParserUTF8(std::string *s, const char *ptr, ParseContext *ctx, const char *field_name)
void SetField(uint64 val, const FieldDescriptor *field, Message *msg, const Reflection *reflection)
#define STORE_TYPE(CPPTYPE_METHOD)
static void FindInitializationErrors(const Message &message, const std::string &prefix, std::vector< std::string > *errors)
static void InternalRegisterGeneratedMessage(const Descriptor *descriptor, const Message *prototype)
static void Merge(const Message &from, Message *to)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
virtual void SetCachedSize(int size) const
#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, METHOD_NAME)
const char * PackedEnumParser(void *object, const char *ptr, ParseContext *ctx)
const internal::RepeatedFieldAccessor * RepeatedFieldAccessor(const FieldDescriptor *field) const
UnknownFieldSet * MutableUnknownFields(Message *message) const
const FileDescriptor * file() const
void CheckInitialized() const
const char * PackedEnumParserArg(void *object, const char *ptr, ParseContext *ctx, bool(*is_valid)(const void *, int), const void *data, InternalMetadataWithArenaLite *metadata, int field_num)
static void * GetMaybeArenaPointer(GenericType *value)
FloatingPoint< float > Float
static void DiscardUnknownFields(Message *message)
std::unordered_map< const Descriptor *, const Message * > type_map_
const char * ParsePackedField(const FieldDescriptor *field, Message *msg, const Reflection *reflection, const char *ptr, internal::ParseContext *ctx)
static void * GetOffset(void *msg, const google::protobuf::FieldDescriptor *f, const google::protobuf::Reflection *r)
void AddEnumValue(Message *message, const FieldDescriptor *field, int value) const
void SetString(Message *message, const FieldDescriptor *field, std::string value) const
const char * InlineGreedyStringParser(std::string *s, const char *ptr, ParseContext *ctx)
TypeAndValue Fixed64(uint64_t val)
int FieldSize(const Message &message, const FieldDescriptor *field) const
bool ReflectiveValidator(const void *arg, int val)
const EnumDescriptor * enum_type
Message * MutableMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
static constexpr CType STRING
virtual void DiscardUnknownFields()
size_t ByteSizeLong() const override
virtual void CopyFrom(const Message &from)
void * MutableRawRepeatedField(Message *message, const FieldDescriptor *field, FieldDescriptor::CppType, int ctype, const Descriptor *message_type) const
std::unordered_map< const char *, const google::protobuf::internal::DescriptorTable *, hash< const char * >, streq > file_map_
const FieldDescriptor * field
const Descriptor * GetDescriptor() const
static Arena * GetArena(GenericType *value)
#define ReaderMutexLock(x)
int ToCachedSize(size_t size)
static GenericType * NewFromPrototype(const GenericType *prototype, Arena *arena=NULL)
const char * ParseLenDelim(int field_number, const FieldDescriptor *field, Message *msg, const Reflection *reflection, const char *ptr, internal::ParseContext *ctx)
void SetEnumValue(Message *message, const FieldDescriptor *field, int value) const
static void * GetRepeatedEnum(const Reflection *reflection, const FieldDescriptor *field, Message *msg)
static const DescriptorPool * generated_pool()
PROTOBUF_NAMESPACE_ID::FieldOptions_CType ctype() const
FloatingPoint< double > Double
#define GOOGLE_CHECK(EXPRESSION)
uint8 * InternalSerializeWithCachedSizesToArray(uint8 *target, io::EpsCopyOutputStream *stream) const override
void AddString(Message *message, const FieldDescriptor *field, std::string value) const
Message * New() const override=0
static void Copy(const Message &from, Message *to)
InternalDescriptorPool * pool
internal::InternalMetadataWithArena * MutableInternalMetadataWithArena(Message *message) const
TypeWithSize< 8 >::Int Int64
internal::WrappedMutex mutex_
void Join(Iterator start, Iterator end, const char *delim, string *result)
static bool IsInitialized(const Message &message)
TypeAndValue Fixed32(uint32_t val)
const FlagFastTypeId type_id_
Message * AddMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
#define GOOGLE_LOG(LEVEL)
Message * GetGroup(int field_number, const FieldDescriptor *field, Message *msg, const Reflection *reflection)
void FindInitializationErrors(std::vector< std::string > *errors) const
static const char descriptor[1336]
const PROTOBUF_MUST_USE_RESULT char * WireFormatParser(T &field_parser, const char *ptr, ParseContext *ctx)
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)
virtual void MergeFrom(const Message &from)
RepeatedPtrField< T > * MutableRepeatedPtrField(Message *, const FieldDescriptor *) const
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:24