in cpp/acs_agent_client_reactor.cc [176:203]
absl::StatusOr<T> AcsAgentClientReactor::GetIntValueFromInitialMetadata(
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata,
const std::string& key) {
if (metadata.count(key) == 0) {
return absl::NotFoundError(absl::StrCat(
"The key: ", key, " was not found in initial metadata from server."));
}
auto [range_begin, range_end] = metadata.equal_range(key);
// Theoretically, there should be <=1 value for the quota keys in the initial
// metadata of server. If there are multiple values, we will return the first
// valid value.
for (auto it = range_begin; it != range_end; ++it) {
T value = 0;
std::string value_str(it->second.data(), it->second.size());
if (!absl::SimpleAtoi(value_str, &value)) {
ABSL_LOG(WARNING) << "key: " << key
<< " found in initial metadata from server but its "
"value having the wrong format: "
<< value_str;
} else {
return value;
}
}
return absl::NotFoundError(
absl::StrCat("key: ", key,
" was found in initial metadata from server but its value "
"was not a valid integer."));
}