Go to the documentation of this file.
37 #include <unordered_map>
64 #include <google/protobuf/port_def.inc>
78 using internal::ReflectionOps;
79 using internal::WireFormat;
80 using internal::WireFormatLite;
85 <<
": Tried to merge from a message with a different type. "
95 MergeFrom(*down_cast<const Message*>(&other));
101 <<
": Tried to copy from a message with a different type. "
125 std::vector<std::string>
errors;
132 <<
"\" is missing required fields: "
140 #if !GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
146 #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
149 class ReflectionAccessor {
153 return static_cast<char*
>(msg) +
r->schema_.GetFieldOffset(
f);
156 static void* GetRepeatedEnum(
const Reflection* reflection,
158 return reflection->MutableRawRepeatedField(
162 static InternalMetadataWithArena* MutableInternalMetadataWithArena(
163 const Reflection* reflection, Message* msg) {
164 return reflection->MutableInternalMetadataWithArena(msg);
171 const Reflection* reflection) {
172 #define STORE_TYPE(CPPTYPE_METHOD) \
174 if (field->is_repeated()) { \
175 reflection->Add##CPPTYPE_METHOD(msg, field, value); \
177 reflection->Set##CPPTYPE_METHOD(msg, field, value); \
182 #define HANDLE_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \
183 case FieldDescriptor::TYPE_##TYPE: { \
184 CPPTYPE value = val; \
185 STORE_TYPE(CPPTYPE_METHOD); \
236 GOOGLE_LOG(
FATAL) <<
"Error in descriptors, primitve field with field type "
243 bool ReflectiveValidator(
const void* arg,
int val) {
245 return d->FindValueByNumber(
val) !=
nullptr;
249 const Reflection* reflection,
const char* ptr,
250 internal::ParseContext* ctx) {
252 #define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, METHOD_NAME) \
253 case FieldDescriptor::TYPE_##TYPE: \
254 return internal::Packed##METHOD_NAME##Parser( \
255 reflection->MutableRepeatedField<CPPTYPE>(msg, field), ptr, ctx)
265 internal::ReflectionAccessor::GetRepeatedEnum(reflection,
field, msg);
271 internal::ReflectionAccessor::MutableInternalMetadataWithArena(
282 #undef HANDLE_PACKED_TYPE
291 Message* msg,
const Reflection* reflection,
292 const char* ptr, internal::ParseContext* ctx) {
296 return ParsePackedField(
field, msg, reflection, ptr, ctx);
298 enum { kNone = 0, kVerify, kStrict } utf8_level = kNone;
299 const char* field_name =
nullptr;
301 switch (utf8_level) {
313 bool enforce_utf8 =
true;
314 bool utf8_verification =
true;
317 utf8_level = kStrict;
318 }
else if (utf8_verification) {
319 utf8_level = kVerify;
322 PROTOBUF_FALLTHROUGH_INTENDED;
326 int index = reflection->FieldSize(*msg,
field);
328 reflection->AddString(msg,
field,
"");
343 reflection->SetString(msg,
field,
"");
348 reflection->GetStringReference(*msg,
field,
nullptr));
353 reflection->GetStringReference(*msg,
field,
nullptr));
362 object = reflection->AddMessage(msg,
field, ctx->data().factory);
364 object = reflection->MutableMessage(msg,
field, ctx->data().factory);
366 return ctx->ParseMessage(
object, ptr);
375 const Reflection* reflection) {
377 return reflection->AddMessage(msg,
field,
nullptr);
379 return reflection->MutableMessage(msg,
field,
nullptr);
384 internal::ParseContext* ctx) {
385 class ReflectiveFieldParser {
387 ReflectiveFieldParser(
Message* msg, internal::ParseContext* ctx)
388 : ReflectiveFieldParser(msg, ctx,
false) {}
391 if (is_item_ && num == 2) {
392 if (!payload_.empty()) {
395 auto child = reflection_->MutableMessage(msg_,
field);
397 child->ParsePartialFromString(payload_);
399 MutableUnknown()->AddLengthDelimited(
value)->swap(payload_);
410 MutableUnknown()->AddVarint(num,
value);
418 MutableUnknown()->AddFixed64(num,
value);
421 const char* ParseLengthDelimited(
uint32 num,
const char* ptr,
422 internal::ParseContext* ctx) {
423 if (is_item_ && num == 3) {
432 return ParseLenDelim(num,
field, msg_, reflection_, ptr, ctx);
435 MutableUnknown()->AddLengthDelimited(num), ptr, ctx);
438 const char* ParseGroup(
uint32 num,
const char* ptr,
439 internal::ParseContext* ctx) {
440 if (!is_item_ &&
descriptor_->options().message_set_wire_format() &&
443 ptr = ctx->ParseGroup(
this, ptr, num * 8 + 3);
450 auto msg = GetGroup(num,
field, msg_, reflection_);
451 return ctx->ParseGroup(msg, ptr, num * 8 + 3);
461 MutableUnknown()->AddFixed32(num,
value);
465 const char*
_InternalParse(
const char* ptr, internal::ParseContext* ctx) {
474 const Reflection* reflection_;
475 internal::ParseContext* ctx_;
477 bool is_item_ =
false;
481 ReflectiveFieldParser(
Message* msg, internal::ParseContext* ctx,
499 field = reflection_->FindKnownExtensionByNumber(num);
504 if (
field ==
nullptr)
return nullptr;
508 if (
field->is_packable()) {
520 if (unknown_)
return unknown_;
521 return unknown_ = reflection_->MutableUnknownFields(msg_);
525 ReflectiveFieldParser field_parser(
this, ctx);
528 #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
548 <<
"\" implements neither SetCachedSize() nor ByteSize(). "
549 "Must implement one or the other.";
565 static GeneratedMessageFactory* singleton();
581 std::unordered_map<const Descriptor*, const Message*>
type_map_;
584 GeneratedMessageFactory* GeneratedMessageFactory::singleton() {
585 static auto instance =
590 void GeneratedMessageFactory::RegisterFile(
598 const Message* prototype) {
600 <<
"Tried to register a non-generated type with the generated "
613 const Message* GeneratedMessageFactory::GetPrototype(
const Descriptor*
type) {
617 if (result !=
NULL)
return result;
625 const internal::DescriptorTable* registration_data =
627 if (registration_data ==
NULL) {
628 GOOGLE_LOG(DFATAL) <<
"File appears to be in generated pool but wasn't "
630 <<
type->file()->name();
638 if (result ==
NULL) {
645 if (result ==
NULL) {
646 GOOGLE_LOG(DFATAL) <<
"Type appears to be in generated pool but wasn't "
647 <<
"registered: " <<
type->full_name();
656 return GeneratedMessageFactory::singleton();
661 GeneratedMessageFactory::singleton()->RegisterFile(
table);
666 GeneratedMessageFactory::singleton()->RegisterType(
descriptor, prototype);
671 template <
typename T>
681 switch (
field->cpp_type()) {
682 #define HANDLE_PRIMITIVE_TYPE(TYPE, type) \
683 case FieldDescriptor::CPPTYPE_##TYPE: \
684 return GetSingleton<internal::RepeatedFieldPrimitiveAccessor<type> >();
693 #undef HANDLE_PRIMITIVE_TYPE
695 switch (
field->options().ctype()) {
698 return GetSingleton<internal::RepeatedPtrFieldStringAccessor>();
702 if (
field->is_map()) {
703 return GetSingleton<internal::MapFieldAccessor>();
705 return GetSingleton<internal::RepeatedPtrFieldMessageAccessor>();
714 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
722 return prototype->
New(arena);
725 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
732 return value->GetArena();
735 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
742 return value->GetMaybeArenaPointer();
const std::string & full_name() const
#define GOOGLE_CHECK_EQ(A, B)
unsigned long long int UInt64
const FieldOptions & options() const
const EnumDescriptor * enum_type() const
const Descriptor::ReservedRange value
static void InternalRegisterGeneratedFile(const google::protobuf::internal::DescriptorTable *table)
virtual size_t SpaceUsedLong() const
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)
virtual int GetCachedSize() const =0
const std::string & full_name() const
std::unordered_map< const Descriptor *, const Message * > type_map_
Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
const Reflection * GetReflection() const
virtual void CopyFrom(const Message &from)
static MessageFactory * generated_factory()
GLsizei const GLchar *const * string
void SetField(MessageLite *msg, uint32 *has_bits, uint32 has_bit_index, int64 offset, Type value)
void FindInitializationErrors(std::vector< std::string > *errors) const
virtual ~MessageFactory()
HANDLE_TYPE(int32, FieldDescriptor::CPPTYPE_INT32, -1)
static PyObject * UnknownFieldSet(CMessage *self)
TypeWithSize< 4 >::Int Int32
size_t SpaceUsedLong(const Message &message) const
#define T(upbtypeconst, upbtype, ctype, default_value)
virtual const void * InternalGetTable() const
bool IsInitialized() const override
const char * InlineGreedyStringParserUTF8(std::string *s, const char *ptr, ParseContext *ctx, const char *field_name)
std::string InitializationErrorString() const override
void CheckInitialized() const
FloatingPoint< double > Double
static void FindInitializationErrors(const Message &message, const std::string &prefix, std::vector< std::string > *errors)
TypeWithSize< 4 >::UInt UInt32
static void InternalRegisterGeneratedMessage(const Descriptor *descriptor, const Message *prototype)
static void Merge(const Message &from, Message *to)
T * OnShutdownDelete(T *p)
void SerializeWithCachedSizes(io::CodedOutputStream *output) const override
const internal::RepeatedFieldAccessor * RepeatedFieldAccessor(const FieldDescriptor *field) const
const FileDescriptor * file() const
const DescriptorPool * pool() const
FloatingPoint< float > Float
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)
static void DiscardUnknownFields(Message *message)
#define ReaderMutexLock(x)
const char * UnknownFieldParse(uint32 tag, std::string *unknown, const char *ptr, ParseContext *ctx)
#define GOOGLE_LOG(LEVEL)
internal::WrappedMutex mutex_
virtual void SetCachedSize(int size) const
const FieldDescriptor * field
#define HANDLE_PRIMITIVE_TYPE(TYPE, type)
#define GOOGLE_CHECK(EXPRESSION)
InternalDescriptorPool * pool
static cJSON_bool parse_string(cJSON *const item, parse_buffer *const input_buffer)
void CheckTypeAndMergeFrom(const MessageLite &other) override
const Descriptor * GetDescriptor() const
#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD)
std::unordered_map< const char *, const google::protobuf::internal::DescriptorTable *, hash< const char * >, streq > file_map_
bool MergePartialFromCodedStream(io::CodedInputStream *input) override
static Arena * GetArena(GenericType *value)
int ToCachedSize(size_t size)
const char * PackedEnumParser(void *object, const char *ptr, ParseContext *ctx)
static GenericType * NewFromPrototype(const GenericType *prototype, Arena *arena=NULL)
std::string GetTypeName() const override
static const DescriptorPool * generated_pool()
PROTOBUF_NAMESPACE_ID::FieldOptions_CType ctype() const
virtual void MergeFrom(const Message &from)
const FileDescriptor * file() const
void TableSerialize(const MessageLite &msg, const SerializationTable *table, io::CodedOutputStream *output)
size_t ByteSizeLong() const override
Message * New() const override=0
static void Copy(const Message &from, Message *to)
static constexpr CType STRING
#define WriterMutexLock(x)
void Join(Iterator start, Iterator end, const char *delim, string *result)
GLsizei const GLfloat * value
static bool IsInitialized(const Message &message)
const Descriptor * descriptor_
const char * InlineGreedyStringParser(std::string *s, const char *ptr, ParseContext *ctx)
const upb_json_parsermethod const upb_symtab upb_sink * output
virtual void DiscardUnknownFields()
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)
static void Clear(Message *message)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:56