|
|
|
@ -28,17 +28,19 @@ namespace { |
|
|
|
|
template <typename EntryType> |
|
|
|
|
std::map<StringView, double, StringLess> ParseMap( |
|
|
|
|
udpa_data_orca_v1_OrcaLoadReport* msg, |
|
|
|
|
EntryType** (*entry_func)(udpa_data_orca_v1_OrcaLoadReport*, size_t*), |
|
|
|
|
const EntryType* (*entry_func)(const udpa_data_orca_v1_OrcaLoadReport*, |
|
|
|
|
size_t*), |
|
|
|
|
upb_strview (*key_func)(const EntryType*), |
|
|
|
|
double (*value_func)(const EntryType*), Arena* arena) { |
|
|
|
|
std::map<StringView, double, StringLess> result; |
|
|
|
|
size_t size; |
|
|
|
|
const auto* const* entries = entry_func(msg, &size); |
|
|
|
|
for (size_t i = 0; i < size; ++i) { |
|
|
|
|
upb_strview key_view = key_func(entries[i]); |
|
|
|
|
size_t i = UPB_MAP_BEGIN; |
|
|
|
|
while (true) { |
|
|
|
|
const auto* entry = entry_func(msg, &i); |
|
|
|
|
if (entry == nullptr) break; |
|
|
|
|
upb_strview key_view = key_func(entry); |
|
|
|
|
char* key = static_cast<char*>(arena->Alloc(key_view.size + 1)); |
|
|
|
|
memcpy(key, key_view.data, key_view.size); |
|
|
|
|
result[StringView(key, key_view.size)] = value_func(entries[i]); |
|
|
|
|
result[StringView(key, key_view.size)] = value_func(entry); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -64,12 +66,12 @@ const LoadBalancingPolicy::BackendMetricData* ParseBackendMetricData( |
|
|
|
|
udpa_data_orca_v1_OrcaLoadReport_rps(msg); |
|
|
|
|
backend_metric_data->request_cost = |
|
|
|
|
ParseMap<udpa_data_orca_v1_OrcaLoadReport_RequestCostEntry>( |
|
|
|
|
msg, udpa_data_orca_v1_OrcaLoadReport_mutable_request_cost, |
|
|
|
|
msg, udpa_data_orca_v1_OrcaLoadReport_request_cost_next, |
|
|
|
|
udpa_data_orca_v1_OrcaLoadReport_RequestCostEntry_key, |
|
|
|
|
udpa_data_orca_v1_OrcaLoadReport_RequestCostEntry_value, arena); |
|
|
|
|
backend_metric_data->utilization = |
|
|
|
|
ParseMap<udpa_data_orca_v1_OrcaLoadReport_UtilizationEntry>( |
|
|
|
|
msg, udpa_data_orca_v1_OrcaLoadReport_mutable_utilization, |
|
|
|
|
msg, udpa_data_orca_v1_OrcaLoadReport_utilization_next, |
|
|
|
|
udpa_data_orca_v1_OrcaLoadReport_UtilizationEntry_key, |
|
|
|
|
udpa_data_orca_v1_OrcaLoadReport_UtilizationEntry_value, arena); |
|
|
|
|
return backend_metric_data; |
|
|
|
|