|
|
|
@ -59,7 +59,7 @@ namespace internal { |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
inline WireFormatLite::FieldType real_type(FieldType type) { |
|
|
|
|
GOOGLE_DCHECK(type > 0 && type <= WireFormatLite::MAX_FIELD_TYPE); |
|
|
|
|
GOOGLE_ABSL_DCHECK(type > 0 && type <= WireFormatLite::MAX_FIELD_TYPE); |
|
|
|
|
return static_cast<WireFormatLite::FieldType>(type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -92,9 +92,9 @@ void Register(const ExtensionInfo& info) { |
|
|
|
|
static auto local_static_registry = OnShutdownDelete(new ExtensionRegistry); |
|
|
|
|
global_registry = local_static_registry; |
|
|
|
|
if (!local_static_registry->insert(info).second) { |
|
|
|
|
GOOGLE_LOG(FATAL) << "Multiple extension registrations for type \"" |
|
|
|
|
<< info.message->GetTypeName() << "\", field number " |
|
|
|
|
<< info.number << "."; |
|
|
|
|
GOOGLE_ABSL_LOG(FATAL) << "Multiple extension registrations for type \"" |
|
|
|
|
<< info.message->GetTypeName() << "\", field number " |
|
|
|
|
<< info.number << "."; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -130,9 +130,9 @@ void ExtensionSet::RegisterExtension(const MessageLite* extendee, int number, |
|
|
|
|
FieldType type, bool is_repeated, |
|
|
|
|
bool is_packed, |
|
|
|
|
LazyEagerVerifyFnType verify_func) { |
|
|
|
|
GOOGLE_CHECK_NE(type, WireFormatLite::TYPE_ENUM); |
|
|
|
|
GOOGLE_CHECK_NE(type, WireFormatLite::TYPE_MESSAGE); |
|
|
|
|
GOOGLE_CHECK_NE(type, WireFormatLite::TYPE_GROUP); |
|
|
|
|
GOOGLE_ABSL_CHECK_NE(type, WireFormatLite::TYPE_ENUM); |
|
|
|
|
GOOGLE_ABSL_CHECK_NE(type, WireFormatLite::TYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_CHECK_NE(type, WireFormatLite::TYPE_GROUP); |
|
|
|
|
ExtensionInfo info(extendee, number, type, is_repeated, is_packed, |
|
|
|
|
verify_func); |
|
|
|
|
Register(info); |
|
|
|
@ -155,7 +155,7 @@ void ExtensionSet::RegisterEnumExtension(const MessageLite* extendee, |
|
|
|
|
int number, FieldType type, |
|
|
|
|
bool is_repeated, bool is_packed, |
|
|
|
|
EnumValidityFunc* is_valid) { |
|
|
|
|
GOOGLE_CHECK_EQ(type, WireFormatLite::TYPE_ENUM); |
|
|
|
|
GOOGLE_ABSL_CHECK_EQ(type, WireFormatLite::TYPE_ENUM); |
|
|
|
|
ExtensionInfo info(extendee, number, type, is_repeated, is_packed, nullptr); |
|
|
|
|
info.enum_validity_check.func = CallNoArgValidityFunc; |
|
|
|
|
// See comment in CallNoArgValidityFunc() about why we use a c-style cast.
|
|
|
|
@ -168,8 +168,8 @@ void ExtensionSet::RegisterMessageExtension(const MessageLite* extendee, |
|
|
|
|
bool is_repeated, bool is_packed, |
|
|
|
|
const MessageLite* prototype, |
|
|
|
|
LazyEagerVerifyFnType verify_func) { |
|
|
|
|
GOOGLE_CHECK(type == WireFormatLite::TYPE_MESSAGE || |
|
|
|
|
type == WireFormatLite::TYPE_GROUP); |
|
|
|
|
GOOGLE_ABSL_CHECK(type == WireFormatLite::TYPE_MESSAGE || |
|
|
|
|
type == WireFormatLite::TYPE_GROUP); |
|
|
|
|
ExtensionInfo info(extendee, number, type, is_repeated, is_packed, |
|
|
|
|
verify_func); |
|
|
|
|
info.message_info = {prototype}; |
|
|
|
@ -219,7 +219,7 @@ void ExtensionSet::DeleteFlatMap(const ExtensionSet::KeyValue* flat, |
|
|
|
|
bool ExtensionSet::Has(int number) const { |
|
|
|
|
const Extension* ext = FindOrNull(number); |
|
|
|
|
if (ext == nullptr) return false; |
|
|
|
|
GOOGLE_DCHECK(!ext->is_repeated); |
|
|
|
|
GOOGLE_ABSL_DCHECK(!ext->is_repeated); |
|
|
|
|
return !ext->is_cleared; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -245,11 +245,13 @@ int ExtensionSet::ExtensionSize(int number) const { |
|
|
|
|
FieldType ExtensionSet::ExtensionType(int number) const { |
|
|
|
|
const Extension* ext = FindOrNull(number); |
|
|
|
|
if (ext == nullptr) { |
|
|
|
|
GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present (1). "; |
|
|
|
|
GOOGLE_ABSL_LOG(DFATAL) |
|
|
|
|
<< "Don't lookup extension types if they aren't present (1). "; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
if (ext->is_cleared) { |
|
|
|
|
GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present (2). "; |
|
|
|
|
GOOGLE_ABSL_LOG(DFATAL) |
|
|
|
|
<< "Don't lookup extension types if they aren't present (2). "; |
|
|
|
|
} |
|
|
|
|
return ext->type; |
|
|
|
|
} |
|
|
|
@ -269,9 +271,10 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD }; |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
#define GOOGLE_DCHECK_TYPE(EXTENSION, LABEL, CPPTYPE) \ |
|
|
|
|
GOOGLE_DCHECK_EQ((EXTENSION).is_repeated ? REPEATED_FIELD : OPTIONAL_FIELD, LABEL); \
|
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type((EXTENSION).type), WireFormatLite::CPPTYPE_##CPPTYPE) |
|
|
|
|
#define GOOGLE_ABSL_DCHECK_TYPE(EXTENSION, LABEL, CPPTYPE) \ |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ((EXTENSION).is_repeated ? REPEATED_FIELD : OPTIONAL_FIELD, \
|
|
|
|
|
LABEL); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type((EXTENSION).type), WireFormatLite::CPPTYPE_##CPPTYPE) |
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
// Primitives
|
|
|
|
@ -284,7 +287,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD }; |
|
|
|
|
if (extension == nullptr || extension->is_cleared) { \
|
|
|
|
|
return default_value; \
|
|
|
|
|
} else { \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
|
|
|
|
|
return extension->LOWERCASE##_value; \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
@ -295,7 +298,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD }; |
|
|
|
|
if (extension == nullptr || extension->is_cleared) { \
|
|
|
|
|
return default_value; \
|
|
|
|
|
} else { \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
|
|
|
|
|
return extension->LOWERCASE##_value; \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
@ -306,11 +309,11 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD }; |
|
|
|
|
Extension* extension; \
|
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { \
|
|
|
|
|
extension->type = type; \
|
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), \
|
|
|
|
|
WireFormatLite::CPPTYPE_##UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), \
|
|
|
|
|
WireFormatLite::CPPTYPE_##UPPERCASE); \
|
|
|
|
|
extension->is_repeated = false; \
|
|
|
|
|
} else { \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
|
|
|
|
|
} \
|
|
|
|
|
extension->is_cleared = false; \
|
|
|
|
|
extension->LOWERCASE##_value = value; \
|
|
|
|
@ -319,24 +322,27 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD }; |
|
|
|
|
LOWERCASE ExtensionSet::GetRepeated##CAMELCASE(int number, int index) \
|
|
|
|
|
const { \
|
|
|
|
|
const Extension* extension = FindOrNull(number); \
|
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) \
|
|
|
|
|
<< "Index out-of-bounds (field is empty)."; \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
return extension->repeated_##LOWERCASE##_value->Get(index); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
const LOWERCASE& ExtensionSet::GetRefRepeated##CAMELCASE(int number, \
|
|
|
|
|
int index) const { \
|
|
|
|
|
const Extension* extension = FindOrNull(number); \
|
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) \
|
|
|
|
|
<< "Index out-of-bounds (field is empty)."; \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
return extension->repeated_##LOWERCASE##_value->Get(index); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
void ExtensionSet::SetRepeated##CAMELCASE(int number, int index, \
|
|
|
|
|
LOWERCASE value) { \
|
|
|
|
|
Extension* extension = FindOrNull(number); \
|
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) \
|
|
|
|
|
<< "Index out-of-bounds (field is empty)."; \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
extension->repeated_##LOWERCASE##_value->Set(index, value); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
@ -346,15 +352,15 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD }; |
|
|
|
|
Extension* extension; \
|
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { \
|
|
|
|
|
extension->type = type; \
|
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), \
|
|
|
|
|
WireFormatLite::CPPTYPE_##UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), \
|
|
|
|
|
WireFormatLite::CPPTYPE_##UPPERCASE); \
|
|
|
|
|
extension->is_repeated = true; \
|
|
|
|
|
extension->is_packed = packed; \
|
|
|
|
|
extension->repeated_##LOWERCASE##_value = \
|
|
|
|
|
Arena::CreateMessage<RepeatedField<LOWERCASE>>(arena_); \
|
|
|
|
|
} else { \
|
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_DCHECK_EQ(extension->is_packed, packed); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
|
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(extension->is_packed, packed); \
|
|
|
|
|
} \
|
|
|
|
|
extension->repeated_##LOWERCASE##_value->Add(value); \
|
|
|
|
|
} |
|
|
|
@ -443,10 +449,10 @@ void* ExtensionSet::MutableRawRepeatedField(int number, FieldType field_type, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Compatible version using old call signature. Does not create extensions when
|
|
|
|
|
// the don't already exist; instead, just GOOGLE_CHECK-fails.
|
|
|
|
|
// the don't already exist; instead, just GOOGLE_ABSL_CHECK-fails.
|
|
|
|
|
void* ExtensionSet::MutableRawRepeatedField(int number) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Extension not found."; |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Extension not found."; |
|
|
|
|
// We assume that all the RepeatedField<>* pointers have the same
|
|
|
|
|
// size and alignment within the anonymous union in Extension.
|
|
|
|
|
return extension->repeated_int32_t_value; |
|
|
|
@ -461,7 +467,7 @@ int ExtensionSet::GetEnum(int number, int default_value) const { |
|
|
|
|
// Not present. Return the default value.
|
|
|
|
|
return default_value; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, ENUM); |
|
|
|
|
return extension->enum_value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -473,7 +479,7 @@ const int& ExtensionSet::GetRefEnum(int number, |
|
|
|
|
// Not present. Return the default value.
|
|
|
|
|
return default_value; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, ENUM); |
|
|
|
|
return extension->enum_value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -483,10 +489,10 @@ void ExtensionSet::SetEnum(int number, FieldType type, int value, |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_ENUM); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_ENUM); |
|
|
|
|
extension->is_repeated = false; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, ENUM); |
|
|
|
|
} |
|
|
|
|
extension->is_cleared = false; |
|
|
|
|
extension->enum_value = value; |
|
|
|
@ -494,22 +500,22 @@ void ExtensionSet::SetEnum(int number, FieldType type, int value, |
|
|
|
|
|
|
|
|
|
int ExtensionSet::GetRepeatedEnum(int number, int index) const { |
|
|
|
|
const Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
return extension->repeated_enum_value->Get(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const int& ExtensionSet::GetRefRepeatedEnum(int number, int index) const { |
|
|
|
|
const Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
return extension->repeated_enum_value->Get(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ExtensionSet::SetRepeatedEnum(int number, int index, int value) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
extension->repeated_enum_value->Set(index, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -518,14 +524,14 @@ void ExtensionSet::AddEnum(int number, FieldType type, bool packed, int value, |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_ENUM); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_ENUM); |
|
|
|
|
extension->is_repeated = true; |
|
|
|
|
extension->is_packed = packed; |
|
|
|
|
extension->repeated_enum_value = |
|
|
|
|
Arena::CreateMessage<RepeatedField<int>>(arena_); |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
GOOGLE_DCHECK_EQ(extension->is_packed, packed); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, ENUM); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(extension->is_packed, packed); |
|
|
|
|
} |
|
|
|
|
extension->repeated_enum_value->Add(value); |
|
|
|
|
} |
|
|
|
@ -540,7 +546,7 @@ const std::string& ExtensionSet::GetString( |
|
|
|
|
// Not present. Return the default value.
|
|
|
|
|
return default_value; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, STRING); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, STRING); |
|
|
|
|
return *extension->string_value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -550,11 +556,11 @@ std::string* ExtensionSet::MutableString(int number, FieldType type, |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_STRING); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_STRING); |
|
|
|
|
extension->is_repeated = false; |
|
|
|
|
extension->string_value = Arena::Create<std::string>(arena_); |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, STRING); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, STRING); |
|
|
|
|
} |
|
|
|
|
extension->is_cleared = false; |
|
|
|
|
return extension->string_value; |
|
|
|
@ -563,15 +569,15 @@ std::string* ExtensionSet::MutableString(int number, FieldType type, |
|
|
|
|
const std::string& ExtensionSet::GetRepeatedString(int number, |
|
|
|
|
int index) const { |
|
|
|
|
const Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING); |
|
|
|
|
return extension->repeated_string_value->Get(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string* ExtensionSet::MutableRepeatedString(int number, int index) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING); |
|
|
|
|
return extension->repeated_string_value->Mutable(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -580,13 +586,13 @@ std::string* ExtensionSet::AddString(int number, FieldType type, |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_STRING); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_STRING); |
|
|
|
|
extension->is_repeated = true; |
|
|
|
|
extension->is_packed = false; |
|
|
|
|
extension->repeated_string_value = |
|
|
|
|
Arena::CreateMessage<RepeatedPtrField<std::string>>(arena_); |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING); |
|
|
|
|
} |
|
|
|
|
return extension->repeated_string_value->Add(); |
|
|
|
|
} |
|
|
|
@ -601,7 +607,7 @@ const MessageLite& ExtensionSet::GetMessage( |
|
|
|
|
// Not present. Return the default value.
|
|
|
|
|
return default_value; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
return extension->lazymessage_value->GetMessage(default_value, arena_); |
|
|
|
|
} else { |
|
|
|
@ -621,14 +627,14 @@ MessageLite* ExtensionSet::MutableMessage(int number, FieldType type, |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
extension->is_repeated = false; |
|
|
|
|
extension->is_lazy = false; |
|
|
|
|
extension->message_value = prototype.New(arena_); |
|
|
|
|
extension->is_cleared = false; |
|
|
|
|
return extension->message_value; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
extension->is_cleared = false; |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
return extension->lazymessage_value->MutableMessage(prototype, arena_); |
|
|
|
@ -650,13 +656,13 @@ void ExtensionSet::SetAllocatedMessage(int number, FieldType type, |
|
|
|
|
ClearExtension(number); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
GOOGLE_DCHECK(message->GetOwningArena() == nullptr || |
|
|
|
|
message->GetOwningArena() == arena_); |
|
|
|
|
GOOGLE_ABSL_DCHECK(message->GetOwningArena() == nullptr || |
|
|
|
|
message->GetOwningArena() == arena_); |
|
|
|
|
Arena* message_arena = message->GetOwningArena(); |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
extension->is_repeated = false; |
|
|
|
|
extension->is_lazy = false; |
|
|
|
|
if (message_arena == arena_) { |
|
|
|
@ -669,7 +675,7 @@ void ExtensionSet::SetAllocatedMessage(int number, FieldType type, |
|
|
|
|
extension->message_value->CheckTypeAndMergeFrom(*message); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
extension->lazymessage_value->SetAllocatedMessage(message, arena_); |
|
|
|
|
} else { |
|
|
|
@ -700,12 +706,12 @@ void ExtensionSet::UnsafeArenaSetAllocatedMessage( |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
extension->is_repeated = false; |
|
|
|
|
extension->is_lazy = false; |
|
|
|
|
extension->message_value = message; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
extension->lazymessage_value->UnsafeArenaSetAllocatedMessage(message, |
|
|
|
|
arena_); |
|
|
|
@ -726,7 +732,7 @@ MessageLite* ExtensionSet::ReleaseMessage(int number, |
|
|
|
|
// Not present. Return nullptr.
|
|
|
|
|
return nullptr; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
MessageLite* ret = nullptr; |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
ret = extension->lazymessage_value->ReleaseMessage(prototype, arena_); |
|
|
|
@ -755,7 +761,7 @@ MessageLite* ExtensionSet::UnsafeArenaReleaseMessage( |
|
|
|
|
// Not present. Return nullptr.
|
|
|
|
|
return nullptr; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE); |
|
|
|
|
MessageLite* ret = nullptr; |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
ret = extension->lazymessage_value->UnsafeArenaReleaseMessage(prototype, |
|
|
|
@ -778,15 +784,15 @@ MessageLite* ExtensionSet::UnsafeArenaReleaseMessage( |
|
|
|
|
const MessageLite& ExtensionSet::GetRepeatedMessage(int number, |
|
|
|
|
int index) const { |
|
|
|
|
const Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE); |
|
|
|
|
return extension->repeated_message_value->Get(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MessageLite* ExtensionSet::MutableRepeatedMessage(int number, int index) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE); |
|
|
|
|
return extension->repeated_message_value->Mutable(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -796,12 +802,12 @@ MessageLite* ExtensionSet::AddMessage(int number, FieldType type, |
|
|
|
|
Extension* extension; |
|
|
|
|
if (MaybeNewExtension(number, descriptor, &extension)) { |
|
|
|
|
extension->type = type; |
|
|
|
|
GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
extension->is_repeated = true; |
|
|
|
|
extension->repeated_message_value = |
|
|
|
|
Arena::CreateMessage<RepeatedPtrField<MessageLite>>(arena_); |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE); |
|
|
|
|
GOOGLE_ABSL_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// RepeatedPtrField<MessageLite> does not know how to Add() since it cannot
|
|
|
|
@ -821,12 +827,12 @@ MessageLite* ExtensionSet::AddMessage(int number, FieldType type, |
|
|
|
|
// const Descriptor* message_type,
|
|
|
|
|
// MessageFactory* factory)
|
|
|
|
|
|
|
|
|
|
#undef GOOGLE_DCHECK_TYPE |
|
|
|
|
#undef GOOGLE_ABSL_DCHECK_TYPE |
|
|
|
|
|
|
|
|
|
void ExtensionSet::RemoveLast(int number) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK(extension->is_repeated); |
|
|
|
|
|
|
|
|
|
switch (cpp_type(extension->type)) { |
|
|
|
|
case WireFormatLite::CPPTYPE_INT32: |
|
|
|
@ -864,24 +870,24 @@ void ExtensionSet::RemoveLast(int number) { |
|
|
|
|
|
|
|
|
|
MessageLite* ExtensionSet::ReleaseLast(int number) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_DCHECK(cpp_type(extension->type) == WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_ABSL_DCHECK(cpp_type(extension->type) == WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
return extension->repeated_message_value->ReleaseLast(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MessageLite* ExtensionSet::UnsafeArenaReleaseLast(int number) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_DCHECK(cpp_type(extension->type) == WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_ABSL_DCHECK(cpp_type(extension->type) == WireFormatLite::CPPTYPE_MESSAGE); |
|
|
|
|
return extension->repeated_message_value->UnsafeArenaReleaseLast(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ExtensionSet::SwapElements(int number, int index1, int index2) { |
|
|
|
|
Extension* extension = FindOrNull(number); |
|
|
|
|
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_ABSL_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; |
|
|
|
|
GOOGLE_ABSL_DCHECK(extension->is_repeated); |
|
|
|
|
|
|
|
|
|
switch (cpp_type(extension->type)) { |
|
|
|
|
case WireFormatLite::CPPTYPE_INT32: |
|
|
|
@ -988,9 +994,9 @@ void ExtensionSet::InternalExtensionMergeFrom(const MessageLite* extendee, |
|
|
|
|
extension->is_packed = other_extension.is_packed; |
|
|
|
|
extension->is_repeated = true; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_EQ(extension->type, other_extension.type); |
|
|
|
|
GOOGLE_DCHECK_EQ(extension->is_packed, other_extension.is_packed); |
|
|
|
|
GOOGLE_DCHECK(extension->is_repeated); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(extension->type, other_extension.type); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(extension->is_packed, other_extension.is_packed); |
|
|
|
|
GOOGLE_ABSL_DCHECK(extension->is_repeated); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (cpp_type(other_extension.type)) { |
|
|
|
@ -1084,9 +1090,9 @@ void ExtensionSet::InternalExtensionMergeFrom(const MessageLite* extendee, |
|
|
|
|
*other_extension.message_value); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_DCHECK_EQ(extension->type, other_extension.type); |
|
|
|
|
GOOGLE_DCHECK_EQ(extension->is_packed, other_extension.is_packed); |
|
|
|
|
GOOGLE_DCHECK(!extension->is_repeated); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(extension->type, other_extension.type); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(extension->is_packed, other_extension.is_packed); |
|
|
|
|
GOOGLE_ABSL_DCHECK(!extension->is_repeated); |
|
|
|
|
if (other_extension.is_lazy) { |
|
|
|
|
if (extension->is_lazy) { |
|
|
|
|
extension->lazymessage_value->MergeFrom( |
|
|
|
@ -1194,7 +1200,7 @@ void ExtensionSet::UnsafeShallowSwapExtension(ExtensionSet* other, int number) { |
|
|
|
|
|
|
|
|
|
if (this_ext == other_ext) return; |
|
|
|
|
|
|
|
|
|
GOOGLE_DCHECK_EQ(GetArena(), other->GetArena()); |
|
|
|
|
GOOGLE_ABSL_DCHECK_EQ(GetArena(), other->GetArena()); |
|
|
|
|
|
|
|
|
|
if (this_ext != nullptr && other_ext != nullptr) { |
|
|
|
|
std::swap(*this_ext, *other_ext); |
|
|
|
@ -1390,7 +1396,7 @@ size_t ExtensionSet::Extension::ByteSize(int number) const { |
|
|
|
|
case WireFormatLite::TYPE_BYTES: |
|
|
|
|
case WireFormatLite::TYPE_GROUP: |
|
|
|
|
case WireFormatLite::TYPE_MESSAGE: |
|
|
|
|
GOOGLE_LOG(FATAL) << "Non-primitive types can't be packed."; |
|
|
|
|
GOOGLE_ABSL_LOG(FATAL) << "Non-primitive types can't be packed."; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1491,7 +1497,7 @@ size_t ExtensionSet::Extension::ByteSize(int number) const { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int ExtensionSet::Extension::GetSize() const { |
|
|
|
|
GOOGLE_DCHECK(is_repeated); |
|
|
|
|
GOOGLE_ABSL_DCHECK(is_repeated); |
|
|
|
|
switch (cpp_type(type)) { |
|
|
|
|
#define HANDLE_TYPE(UPPERCASE, LOWERCASE) \ |
|
|
|
|
case WireFormatLite::CPPTYPE_##UPPERCASE: \
|
|
|
|
@ -1510,7 +1516,7 @@ int ExtensionSet::Extension::GetSize() const { |
|
|
|
|
#undef HANDLE_TYPE |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GOOGLE_LOG(FATAL) << "Can't get here."; |
|
|
|
|
GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1659,7 +1665,7 @@ void ExtensionSet::GrowCapacity(size_t minimum_new_capacity) { |
|
|
|
|
hint = new_map.large->insert(hint, {it->first, it->second}); |
|
|
|
|
} |
|
|
|
|
flat_size_ = static_cast<uint16_t>(-1); |
|
|
|
|
GOOGLE_DCHECK(is_large()); |
|
|
|
|
GOOGLE_ABSL_DCHECK(is_large()); |
|
|
|
|
} else { |
|
|
|
|
new_map.flat = Arena::CreateArray<KeyValue>(arena_, new_flat_capacity); |
|
|
|
|
std::copy(begin, end, new_map.flat); |
|
|
|
@ -1749,7 +1755,7 @@ uint8_t* ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray( |
|
|
|
|
case WireFormatLite::TYPE_BYTES: |
|
|
|
|
case WireFormatLite::TYPE_GROUP: |
|
|
|
|
case WireFormatLite::TYPE_MESSAGE: |
|
|
|
|
GOOGLE_LOG(FATAL) << "Non-primitive types can't be packed."; |
|
|
|
|
GOOGLE_ABSL_LOG(FATAL) << "Non-primitive types can't be packed."; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -1877,7 +1883,7 @@ ExtensionSet::Extension::InternalSerializeMessageSetItemWithCachedSizesToArray( |
|
|
|
|
uint8_t* target, io::EpsCopyOutputStream* stream) const { |
|
|
|
|
if (type != WireFormatLite::TYPE_MESSAGE || is_repeated) { |
|
|
|
|
// Not a valid MessageSet extension, but serialize it the normal way.
|
|
|
|
|
GOOGLE_LOG(WARNING) << "Invalid message set extension."; |
|
|
|
|
GOOGLE_ABSL_LOG(WARNING) << "Invalid message set extension."; |
|
|
|
|
return InternalSerializeFieldWithCachedSizesToArray(extendee, extension_set, |
|
|
|
|
number, target, stream); |
|
|
|
|
} |
|
|
|
|