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.
| 118 | //and ends with ',' and return true. |
| 119 | //otherwise will append error into error message and return false. |
| 120 | inline 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 | |
| 139 | template<typename T> |
| 140 | inline bool convert_string_to_double_float_type( |
no test coverage detected