MCPcopy Create free account
hub / github.com/apache/brpc / value_invalid

Function value_invalid

src/json2pb/json_to_pb.cpp:120–137  ·  view source on GitHub ↗

It will be called when type mismatch occurs, fg: convert string to uint, and will also be called when invalid value appears, fg: invalid enum name, invalid enum number, invalid string content to convert to double or float. for optional field error will just append error into error message and ends with ',' and return true. otherwise will append error into error message and return false.

Source from the content-addressed store, hash-verified

118//and ends with ',' and return true.
119//otherwise will append error into error message and return false.
120inline bool value_invalid(const google::protobuf::FieldDescriptor* field, const char* type,
121 const BUTIL_RAPIDJSON_NAMESPACE::Value& value, std::string* err) {
122 bool optional = !field->is_required() && !field->is_repeated();
123 if (err) {
124 if (!err->empty()) {
125 err->append(", ");
126 }
127 err->append("Invalid value `");
128 string_append_value(value, err);
129 butil::string_appendf(err, "' for %sfield `%s' which SHOULD be %s",
130 optional ? "optional " : "",
131 butil::EnsureString(field->full_name()).c_str(), type);
132 }
133 if (!optional) {
134 return false;
135 }
136 return true;
137}
138
139template<typename T>
140inline bool convert_string_to_double_float_type(

Callers 6

convert_float_typeFunction · 0.85
convert_double_typeFunction · 0.85
convert_enum_typeFunction · 0.85
convert_int64_typeFunction · 0.85
convert_uint64_typeFunction · 0.85

Calls 6

string_append_valueFunction · 0.85
string_appendfFunction · 0.85
EnsureStringFunction · 0.85
emptyMethod · 0.45
appendMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected