|
|
@ -58,6 +58,7 @@ |
|
|
|
#include "absl/strings/ascii.h" |
|
|
|
#include "absl/strings/ascii.h" |
|
|
|
#include "absl/strings/escaping.h" |
|
|
|
#include "absl/strings/escaping.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
|
|
|
#include "absl/strings/str_format.h" |
|
|
|
#include "google/protobuf/stubs/stringprintf.h" |
|
|
|
#include "google/protobuf/stubs/stringprintf.h" |
|
|
|
#include "absl/strings/str_join.h" |
|
|
|
#include "absl/strings/str_join.h" |
|
|
|
#include "absl/strings/str_split.h" |
|
|
|
#include "absl/strings/str_split.h" |
|
|
@ -7675,6 +7676,27 @@ bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet( |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
// Helpers for method below
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> std::string ValueOutOfRange( |
|
|
|
|
|
|
|
absl::string_view type_name, absl::string_view option_name) { |
|
|
|
|
|
|
|
return absl::StrFormat( |
|
|
|
|
|
|
|
"Value out of range, %d to %d, for %s option \"%s\".", \
|
|
|
|
|
|
|
|
std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), |
|
|
|
|
|
|
|
type_name, option_name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> std::string ValueMustBeInt( |
|
|
|
|
|
|
|
absl::string_view type_name, absl::string_view option_name) { |
|
|
|
|
|
|
|
return absl::StrFormat( |
|
|
|
|
|
|
|
"Value must be integer, from %d to %d, for %s option \"%s\".", \
|
|
|
|
|
|
|
|
std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), |
|
|
|
|
|
|
|
type_name, option_name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
const FieldDescriptor* option_field, UnknownFieldSet* unknown_fields) { |
|
|
|
const FieldDescriptor* option_field, UnknownFieldSet* unknown_fields) { |
|
|
|
// We switch on the CppType to validate.
|
|
|
|
// We switch on the CppType to validate.
|
|
|
@ -7683,8 +7705,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
if (uninterpreted_option_->has_positive_int_value()) { |
|
|
|
if (uninterpreted_option_->has_positive_int_value()) { |
|
|
|
if (uninterpreted_option_->positive_int_value() > |
|
|
|
if (uninterpreted_option_->positive_int_value() > |
|
|
|
static_cast<uint64_t>(std::numeric_limits<int32_t>::max())) { |
|
|
|
static_cast<uint64_t>(std::numeric_limits<int32_t>::max())) { |
|
|
|
return AddValueError("Value out of range for int32 option \"" + |
|
|
|
return AddValueError(ValueOutOfRange<int32_t>("int32", option_field->full_name())); |
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
SetInt32(option_field->number(), |
|
|
|
SetInt32(option_field->number(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
@ -7693,16 +7714,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
} else if (uninterpreted_option_->has_negative_int_value()) { |
|
|
|
} else if (uninterpreted_option_->has_negative_int_value()) { |
|
|
|
if (uninterpreted_option_->negative_int_value() < |
|
|
|
if (uninterpreted_option_->negative_int_value() < |
|
|
|
static_cast<int64_t>(std::numeric_limits<int32_t>::min())) { |
|
|
|
static_cast<int64_t>(std::numeric_limits<int32_t>::min())) { |
|
|
|
return AddValueError("Value out of range for int32 option \"" + |
|
|
|
return AddValueError(ValueOutOfRange<int32_t>("int32", option_field->full_name())); |
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
SetInt32(option_field->number(), |
|
|
|
SetInt32(option_field->number(), |
|
|
|
uninterpreted_option_->negative_int_value(), |
|
|
|
uninterpreted_option_->negative_int_value(), |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return AddValueError("Value must be integer for int32 option \"" + |
|
|
|
return AddValueError(ValueMustBeInt<int32_t>("int32", option_field->full_name())); |
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
@ -7710,8 +7729,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
if (uninterpreted_option_->has_positive_int_value()) { |
|
|
|
if (uninterpreted_option_->has_positive_int_value()) { |
|
|
|
if (uninterpreted_option_->positive_int_value() > |
|
|
|
if (uninterpreted_option_->positive_int_value() > |
|
|
|
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) { |
|
|
|
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) { |
|
|
|
return AddValueError("Value out of range for int64 option \"" + |
|
|
|
return AddValueError(ValueOutOfRange<int64_t>("int64", option_field->full_name())); |
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
SetInt64(option_field->number(), |
|
|
|
SetInt64(option_field->number(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
@ -7722,8 +7740,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
uninterpreted_option_->negative_int_value(), |
|
|
|
uninterpreted_option_->negative_int_value(), |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return AddValueError("Value must be integer for int64 option \"" + |
|
|
|
return AddValueError(ValueMustBeInt<int64_t>("int64", option_field->full_name())); |
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
@ -7731,18 +7748,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
if (uninterpreted_option_->has_positive_int_value()) { |
|
|
|
if (uninterpreted_option_->has_positive_int_value()) { |
|
|
|
if (uninterpreted_option_->positive_int_value() > |
|
|
|
if (uninterpreted_option_->positive_int_value() > |
|
|
|
std::numeric_limits<uint32_t>::max()) { |
|
|
|
std::numeric_limits<uint32_t>::max()) { |
|
|
|
return AddValueError("Value out of range for uint32 option \"" + |
|
|
|
return AddValueError(ValueOutOfRange<uint32_t>("uint32", option_field->full_name())); |
|
|
|
option_field->name() + "\"."); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
SetUInt32(option_field->number(), |
|
|
|
SetUInt32(option_field->number(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return AddValueError( |
|
|
|
return AddValueError(ValueMustBeInt<uint32_t>("uint32", option_field->full_name())); |
|
|
|
"Value must be non-negative integer for uint32 " |
|
|
|
|
|
|
|
"option \"" + |
|
|
|
|
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
@ -7752,10 +7765,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
|
uninterpreted_option_->positive_int_value(), |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
option_field->type(), unknown_fields); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return AddValueError( |
|
|
|
return AddValueError(ValueMustBeInt<uint64_t>("uint64", option_field->full_name())); |
|
|
|
"Value must be non-negative integer for uint64 " |
|
|
|
|
|
|
|
"option \"" + |
|
|
|
|
|
|
|
option_field->full_name() + "\"."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|