#include <google/protobuf/generated_message_reflection.h>
#include <algorithm>
#include <set>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/mutex.h>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/inlined_string_field.h>
#include <google/protobuf/map_field.h>
#include <google/protobuf/map_field_inl.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/port_def.inc>
#define GOOGLE_PROTOBUF_HAS_ONEOF
ArenaStringPtr;
DescriptorTable;
ExtensionSet;
GenericTypeHandler;
GetEmptyString;
InlinedStringField;
InternalMetadata;
LazyField;
MapFieldBase;
MigrationSchema;
OnShutdownDelete;
ReflectionSchema;
RepeatedPtrFieldBase;
StringSpaceUsedExcludingSelfLong;
WrappedMutex;
namespace google {
namespace protobuf {
namespace {
bool IsMapFieldInApi(const FieldDescriptor* field) { … }
#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
Message* MaybeForceCopy(Arena* arena, Message* msg) {
if (arena != nullptr || msg == nullptr) return msg;
Message* copy = msg->New();
copy->MergeFrom(*msg);
delete msg;
return copy;
}
#endif
}
namespace internal {
bool ParseNamedEnum(const EnumDescriptor* descriptor, ConstStringParam name,
int* value) { … }
const std::string& NameOfEnum(const EnumDescriptor* descriptor, int value) { … }
}
namespace {
GetConstPointerAtOffset;
GetConstRefAtOffset;
GetPointerAtOffset;
void ReportReflectionUsageError(const Descriptor* descriptor,
const FieldDescriptor* field,
const char* method, const char* description) { … }
const char* cpptype_names_[FieldDescriptor::MAX_CPPTYPE + 1] = …;
static void ReportReflectionUsageTypeError(
const Descriptor* descriptor, const FieldDescriptor* field,
const char* method, FieldDescriptor::CppType expected_type) { … }
static void ReportReflectionUsageEnumTypeError(
const Descriptor* descriptor, const FieldDescriptor* field,
const char* method, const EnumValueDescriptor* value) { … }
inline void CheckInvalidAccess(const internal::ReflectionSchema& schema,
const FieldDescriptor* field) { … }
#define USAGE_CHECK(CONDITION, METHOD, ERROR_DESCRIPTION) …
#define USAGE_CHECK_EQ(A, B, METHOD, ERROR_DESCRIPTION) …
#define USAGE_CHECK_NE(A, B, METHOD, ERROR_DESCRIPTION) …
#define USAGE_CHECK_TYPE(METHOD, CPPTYPE) …
#define USAGE_CHECK_ENUM_VALUE(METHOD) …
#define USAGE_CHECK_MESSAGE_TYPE(METHOD) …
#define USAGE_CHECK_SINGULAR(METHOD) …
#define USAGE_CHECK_REPEATED(METHOD) …
#define USAGE_CHECK_ALL(METHOD, LABEL, CPPTYPE) …
}
Reflection::Reflection(const Descriptor* descriptor,
const internal::ReflectionSchema& schema,
const DescriptorPool* pool, MessageFactory* factory)
: … { … }
const UnknownFieldSet& Reflection::GetUnknownFields(
const Message& message) const { … }
UnknownFieldSet* Reflection::MutableUnknownFields(Message* message) const { … }
bool Reflection::IsLazyExtension(const Message& message,
const FieldDescriptor* field) const { … }
bool Reflection::IsLazilyVerifiedLazyField(const FieldDescriptor* field) const { … }
bool Reflection::IsEagerlyVerifiedLazyField(
const FieldDescriptor* field) const { … }
bool Reflection::IsInlined(const FieldDescriptor* field) const { … }
size_t Reflection::SpaceUsedLong(const Message& message) const { … }
namespace {
template <bool unsafe_shallow_swap>
struct OneofFieldMover { … };
}
namespace internal {
class SwapFieldHelper { … };
template <bool unsafe_shallow_swap>
void SwapFieldHelper::SwapRepeatedStringField(const Reflection* r, Message* lhs,
Message* rhs,
const FieldDescriptor* field) { … }
template <bool unsafe_shallow_swap>
void SwapFieldHelper::SwapInlinedStrings(const Reflection* r, Message* lhs,
Message* rhs,
const FieldDescriptor* field) { … }
template <bool unsafe_shallow_swap>
void SwapFieldHelper::SwapNonInlinedStrings(const Reflection* r, Message* lhs,
Message* rhs,
const FieldDescriptor* field) { … }
template <bool unsafe_shallow_swap>
void SwapFieldHelper::SwapStringField(const Reflection* r, Message* lhs,
Message* rhs,
const FieldDescriptor* field) { … }
void SwapFieldHelper::SwapArenaStringPtr(ArenaStringPtr* lhs, Arena* lhs_arena,
ArenaStringPtr* rhs,
Arena* rhs_arena) { … }
template <bool unsafe_shallow_swap>
void SwapFieldHelper::SwapRepeatedMessageField(const Reflection* r,
Message* lhs, Message* rhs,
const FieldDescriptor* field) { … }
template <bool unsafe_shallow_swap>
void SwapFieldHelper::SwapMessageField(const Reflection* r, Message* lhs,
Message* rhs,
const FieldDescriptor* field) { … }
void SwapFieldHelper::SwapMessage(const Reflection* r, Message* lhs,
Arena* lhs_arena, Message* rhs,
Arena* rhs_arena,
const FieldDescriptor* field) { … }
void SwapFieldHelper::SwapNonMessageNonStringField(
const Reflection* r, Message* lhs, Message* rhs,
const FieldDescriptor* field) { … }
}
void Reflection::SwapField(Message* message1, Message* message2,
const FieldDescriptor* field) const { … }
void Reflection::UnsafeShallowSwapField(Message* message1, Message* message2,
const FieldDescriptor* field) const { … }
template <bool unsafe_shallow_swap>
void Reflection::SwapOneofField(Message* lhs, Message* rhs,
const OneofDescriptor* oneof_descriptor) const { … }
void Reflection::Swap(Message* message1, Message* message2) const { … }
template <bool unsafe_shallow_swap>
void Reflection::SwapFieldsImpl(
Message* message1, Message* message2,
const std::vector<const FieldDescriptor*>& fields) const { … }
void Reflection::SwapFields(
Message* message1, Message* message2,
const std::vector<const FieldDescriptor*>& fields) const { … }
void Reflection::UnsafeShallowSwapFields(
Message* message1, Message* message2,
const std::vector<const FieldDescriptor*>& fields) const { … }
void Reflection::UnsafeArenaSwapFields(
Message* lhs, Message* rhs,
const std::vector<const FieldDescriptor*>& fields) const { … }
bool Reflection::HasField(const Message& message,
const FieldDescriptor* field) const { … }
void Reflection::UnsafeArenaSwap(Message* lhs, Message* rhs) const { … }
int Reflection::FieldSize(const Message& message,
const FieldDescriptor* field) const { … }
void Reflection::ClearField(Message* message,
const FieldDescriptor* field) const { … }
void Reflection::RemoveLast(Message* message,
const FieldDescriptor* field) const { … }
Message* Reflection::ReleaseLast(Message* message,
const FieldDescriptor* field) const { … }
Message* Reflection::UnsafeArenaReleaseLast(
Message* message, const FieldDescriptor* field) const { … }
void Reflection::SwapElements(Message* message, const FieldDescriptor* field,
int index1, int index2) const { … }
namespace {
struct FieldNumberSorter { … };
bool IsIndexInHasBitSet(const uint32_t* has_bit_set, uint32_t has_bit_index) { … }
bool CreateUnknownEnumValues(const FileDescriptor* file) { … }
}
namespace internal {
bool CreateUnknownEnumValues(const FieldDescriptor* field) { … }
}
CreateUnknownEnumValues;
void Reflection::ListFieldsMayFailOnStripped(
const Message& message, bool should_fail,
std::vector<const FieldDescriptor*>* output) const { … }
void Reflection::ListFields(const Message& message,
std::vector<const FieldDescriptor*>* output) const { … }
void Reflection::ListFieldsOmitStripped(
const Message& message, std::vector<const FieldDescriptor*>* output) const { … }
#undef DEFINE_PRIMITIVE_ACCESSORS
#define DEFINE_PRIMITIVE_ACCESSORS …
DEFINE_PRIMITIVE_ACCESSORS
DEFINE_PRIMITIVE_ACCESSORS
DEFINE_PRIMITIVE_ACCESSORS
DEFINE_PRIMITIVE_ACCESSORS
DEFINE_PRIMITIVE_ACCESSORS
DEFINE_PRIMITIVE_ACCESSORS
DEFINE_PRIMITIVE_ACCESSORS
#undef DEFINE_PRIMITIVE_ACCESSORS
std::string Reflection::GetString(const Message& message,
const FieldDescriptor* field) const { … }
const std::string& Reflection::GetStringReference(const Message& message,
const FieldDescriptor* field,
std::string* scratch) const { … }
void Reflection::SetString(Message* message, const FieldDescriptor* field,
std::string value) const { … }
std::string Reflection::GetRepeatedString(const Message& message,
const FieldDescriptor* field,
int index) const { … }
const std::string& Reflection::GetRepeatedStringReference(
const Message& message, const FieldDescriptor* field, int index,
std::string* scratch) const { … }
void Reflection::SetRepeatedString(Message* message,
const FieldDescriptor* field, int index,
std::string value) const { … }
void Reflection::AddString(Message* message, const FieldDescriptor* field,
std::string value) const { … }
const EnumValueDescriptor* Reflection::GetEnum(
const Message& message, const FieldDescriptor* field) const { … }
int Reflection::GetEnumValue(const Message& message,
const FieldDescriptor* field) const { … }
void Reflection::SetEnum(Message* message, const FieldDescriptor* field,
const EnumValueDescriptor* value) const { … }
void Reflection::SetEnumValue(Message* message, const FieldDescriptor* field,
int value) const { … }
void Reflection::SetEnumValueInternal(Message* message,
const FieldDescriptor* field,
int value) const { … }
const EnumValueDescriptor* Reflection::GetRepeatedEnum(
const Message& message, const FieldDescriptor* field, int index) const { … }
int Reflection::GetRepeatedEnumValue(const Message& message,
const FieldDescriptor* field,
int index) const { … }
void Reflection::SetRepeatedEnum(Message* message, const FieldDescriptor* field,
int index,
const EnumValueDescriptor* value) const { … }
void Reflection::SetRepeatedEnumValue(Message* message,
const FieldDescriptor* field, int index,
int value) const { … }
void Reflection::SetRepeatedEnumValueInternal(Message* message,
const FieldDescriptor* field,
int index, int value) const { … }
void Reflection::AddEnum(Message* message, const FieldDescriptor* field,
const EnumValueDescriptor* value) const { … }
void Reflection::AddEnumValue(Message* message, const FieldDescriptor* field,
int value) const { … }
void Reflection::AddEnumValueInternal(Message* message,
const FieldDescriptor* field,
int value) const { … }
const Message* Reflection::GetDefaultMessageInstance(
const FieldDescriptor* field) const { … }
const Message& Reflection::GetMessage(const Message& message,
const FieldDescriptor* field,
MessageFactory* factory) const { … }
Message* Reflection::MutableMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory) const { … }
void Reflection::UnsafeArenaSetAllocatedMessage(
Message* message, Message* sub_message,
const FieldDescriptor* field) const { … }
void Reflection::SetAllocatedMessage(Message* message, Message* sub_message,
const FieldDescriptor* field) const { … }
Message* Reflection::UnsafeArenaReleaseMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory) const { … }
Message* Reflection::ReleaseMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory) const { … }
const Message& Reflection::GetRepeatedMessage(const Message& message,
const FieldDescriptor* field,
int index) const { … }
Message* Reflection::MutableRepeatedMessage(Message* message,
const FieldDescriptor* field,
int index) const { … }
Message* Reflection::AddMessage(Message* message, const FieldDescriptor* field,
MessageFactory* factory) const { … }
void Reflection::AddAllocatedMessage(Message* message,
const FieldDescriptor* field,
Message* new_entry) const { … }
void Reflection::UnsafeArenaAddAllocatedMessage(Message* message,
const FieldDescriptor* field,
Message* new_entry) const { … }
void* Reflection::MutableRawRepeatedField(Message* message,
const FieldDescriptor* field,
FieldDescriptor::CppType cpptype,
int ctype,
const Descriptor* desc) const { … }
const void* Reflection::GetRawRepeatedField(const Message& message,
const FieldDescriptor* field,
FieldDescriptor::CppType cpptype,
int ctype,
const Descriptor* desc) const { … }
const FieldDescriptor* Reflection::GetOneofFieldDescriptor(
const Message& message, const OneofDescriptor* oneof_descriptor) const { … }
bool Reflection::ContainsMapKey(const Message& message,
const FieldDescriptor* field,
const MapKey& key) const { … }
bool Reflection::InsertOrLookupMapValue(Message* message,
const FieldDescriptor* field,
const MapKey& key,
MapValueRef* val) const { … }
bool Reflection::LookupMapValue(const Message& message,
const FieldDescriptor* field, const MapKey& key,
MapValueConstRef* val) const { … }
bool Reflection::DeleteMapValue(Message* message, const FieldDescriptor* field,
const MapKey& key) const { … }
MapIterator Reflection::MapBegin(Message* message,
const FieldDescriptor* field) const { … }
MapIterator Reflection::MapEnd(Message* message,
const FieldDescriptor* field) const { … }
int Reflection::MapSize(const Message& message,
const FieldDescriptor* field) const { … }
const FieldDescriptor* Reflection::FindKnownExtensionByName(
const std::string& name) const { … }
const FieldDescriptor* Reflection::FindKnownExtensionByNumber(
int number) const { … }
bool Reflection::SupportsUnknownEnumValues() const { … }
template <class Type>
const Type& Reflection::GetRawNonOneof(const Message& message,
const FieldDescriptor* field) const { … }
template <class Type>
Type* Reflection::MutableRawNonOneof(Message* message,
const FieldDescriptor* field) const { … }
template <typename Type>
Type* Reflection::MutableRaw(Message* message,
const FieldDescriptor* field) const { … }
const uint32_t* Reflection::GetHasBits(const Message& message) const { … }
uint32_t* Reflection::MutableHasBits(Message* message) const { … }
uint32_t* Reflection::MutableOneofCase(
Message* message, const OneofDescriptor* oneof_descriptor) const { … }
const ExtensionSet& Reflection::GetExtensionSet(const Message& message) const { … }
ExtensionSet* Reflection::MutableExtensionSet(Message* message) const { … }
const InternalMetadata& Reflection::GetInternalMetadata(
const Message& message) const { … }
InternalMetadata* Reflection::MutableInternalMetadata(Message* message) const { … }
const uint32_t* Reflection::GetInlinedStringDonatedArray(
const Message& message) const { … }
uint32_t* Reflection::MutableInlinedStringDonatedArray(Message* message) const { … }
bool Reflection::IsInlinedStringDonated(const Message& message,
const FieldDescriptor* field) const { … }
inline void SetInlinedStringDonated(uint32_t index, uint32_t* array) { … }
inline void ClearInlinedStringDonated(uint32_t index, uint32_t* array) { … }
void Reflection::SwapInlinedStringDonated(Message* lhs, Message* rhs,
const FieldDescriptor* field) const { … }
bool Reflection::HasBit(const Message& message,
const FieldDescriptor* field) const { … }
void Reflection::SetBit(Message* message, const FieldDescriptor* field) const { … }
void Reflection::ClearBit(Message* message,
const FieldDescriptor* field) const { … }
void Reflection::SwapBit(Message* message1, Message* message2,
const FieldDescriptor* field) const { … }
bool Reflection::HasOneof(const Message& message,
const OneofDescriptor* oneof_descriptor) const { … }
void Reflection::SetOneofCase(Message* message,
const FieldDescriptor* field) const { … }
void Reflection::ClearOneofField(Message* message,
const FieldDescriptor* field) const { … }
void Reflection::ClearOneof(Message* message,
const OneofDescriptor* oneof_descriptor) const { … }
#define HANDLE_TYPE …
HANDLE_TYPE(int32_t, FieldDescriptor::CPPTYPE_INT32, -1);
HANDLE_TYPE(int64_t, FieldDescriptor::CPPTYPE_INT64, -1);
HANDLE_TYPE(uint32_t, FieldDescriptor::CPPTYPE_UINT32, -1);
HANDLE_TYPE(uint64_t, FieldDescriptor::CPPTYPE_UINT64, -1);
HANDLE_TYPE(float, FieldDescriptor::CPPTYPE_FLOAT, -1);
HANDLE_TYPE(double, FieldDescriptor::CPPTYPE_DOUBLE, -1);
HANDLE_TYPE(bool, FieldDescriptor::CPPTYPE_BOOL, -1);
#undef HANDLE_TYPE
void* Reflection::MutableRawRepeatedString(Message* message,
const FieldDescriptor* field,
bool is_string) const { … }
template <typename Type>
const Type& Reflection::GetField(const Message& message,
const FieldDescriptor* field) const { … }
template <typename Type>
void Reflection::SetField(Message* message, const FieldDescriptor* field,
const Type& value) const { … }
template <typename Type>
Type* Reflection::MutableField(Message* message,
const FieldDescriptor* field) const { … }
template <typename Type>
const Type& Reflection::GetRepeatedField(const Message& message,
const FieldDescriptor* field,
int index) const { … }
template <typename Type>
const Type& Reflection::GetRepeatedPtrField(const Message& message,
const FieldDescriptor* field,
int index) const { … }
template <typename Type>
void Reflection::SetRepeatedField(Message* message,
const FieldDescriptor* field, int index,
Type value) const { … }
template <typename Type>
Type* Reflection::MutableRepeatedField(Message* message,
const FieldDescriptor* field,
int index) const { … }
template <typename Type>
void Reflection::AddField(Message* message, const FieldDescriptor* field,
const Type& value) const { … }
template <typename Type>
Type* Reflection::AddField(Message* message,
const FieldDescriptor* field) const { … }
MessageFactory* Reflection::GetMessageFactory() const { … }
void* Reflection::RepeatedFieldData(Message* message,
const FieldDescriptor* field,
FieldDescriptor::CppType cpp_type,
const Descriptor* message_type) const { … }
MapFieldBase* Reflection::MutableMapData(Message* message,
const FieldDescriptor* field) const { … }
const MapFieldBase* Reflection::GetMapData(const Message& message,
const FieldDescriptor* field) const { … }
namespace {
ReflectionSchema MigrationToReflectionSchema(
const Message* const* default_instance, const uint32_t* offsets,
MigrationSchema migration_schema) { … }
}
class AssignDescriptorsHelper { … };
namespace {
struct MetadataOwner { … };
void AddDescriptors(const DescriptorTable* table);
void AssignDescriptorsImpl(const DescriptorTable* table, bool eager) { … }
void AddDescriptorsImpl(const DescriptorTable* table) { … }
void AddDescriptors(const DescriptorTable* table) { … }
}
void RegisterAllTypesInternal(const Metadata* file_level_metadata, int size) { … }
namespace internal {
Metadata AssignDescriptors(const DescriptorTable* (*table)(),
internal::once_flag* once,
const Metadata& metadata) { … }
void AssignDescriptors(const DescriptorTable* table, bool eager) { … }
AddDescriptorsRunner::AddDescriptorsRunner(const DescriptorTable* table) { … }
void RegisterFileLevelMetadata(const DescriptorTable* table) { … }
void UnknownFieldSetSerializer(const uint8_t* base, uint32_t offset,
uint32_t , uint32_t ,
io::CodedOutputStream* output) { … }
bool IsDescendant(Message& root, const Message& message) { … }
}
}
}
#include <google/protobuf/port_undef.inc>