diff --git a/src/core/ext/filters/client_channel/backend_metric.cc b/src/core/ext/filters/client_channel/backend_metric.cc index b36614f5b80..f0c7711b9ea 100644 --- a/src/core/ext/filters/client_channel/backend_metric.cc +++ b/src/core/ext/filters/client_channel/backend_metric.cc @@ -28,17 +28,19 @@ namespace { template std::map 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 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(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( - 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( - 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; diff --git a/src/core/ext/filters/client_channel/xds/xds_api.cc b/src/core/ext/filters/client_channel/xds/xds_api.cc index a51256594fb..a4b2d10a0f7 100644 --- a/src/core/ext/filters/client_channel/xds/xds_api.cc +++ b/src/core/ext/filters/client_channel/xds/xds_api.cc @@ -120,13 +120,10 @@ void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value, void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb, const Json::Object& metadata) { for (const auto& p : metadata) { - google_protobuf_Struct_FieldsEntry* field = - google_protobuf_Struct_add_fields(metadata_pb, arena); - google_protobuf_Struct_FieldsEntry_set_key( - field, upb_strview_makez(p.first.c_str())); - google_protobuf_Value* value = - google_protobuf_Struct_FieldsEntry_mutable_value(field, arena); + google_protobuf_Value* value = google_protobuf_Value_new(arena); PopulateMetadataValue(arena, value, p.second); + google_protobuf_Struct_fields_set( + metadata_pb, upb_strview_makez(p.first.c_str()), value, arena); } } diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc index ec17b962972..359764e6506 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -545,17 +545,12 @@ static grpc_byte_buffer* get_serialized_start_server( grpc_gcp_HandshakerReq_mutable_server_start(req, arena.ptr()); grpc_gcp_StartServerHandshakeReq_add_application_protocols( start_server, upb_strview_makez(ALTS_APPLICATION_PROTOCOL), arena.ptr()); - grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry* param = - grpc_gcp_StartServerHandshakeReq_add_handshake_parameters(start_server, - arena.ptr()); - grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_set_key( - param, grpc_gcp_ALTS); grpc_gcp_ServerHandshakeParameters* value = grpc_gcp_ServerHandshakeParameters_new(arena.ptr()); grpc_gcp_ServerHandshakeParameters_add_record_protocols( value, upb_strview_makez(ALTS_RECORD_PROTOCOL), arena.ptr()); - grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_set_value(param, - value); + grpc_gcp_StartServerHandshakeReq_handshake_parameters_set( + start_server, grpc_gcp_ALTS, value, arena.ptr()); grpc_gcp_StartServerHandshakeReq_set_in_bytes( start_server, upb_strview_make(reinterpret_cast( GRPC_SLICE_START_PTR(*bytes_received)), diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc index 0e1ab006728..06a61d11704 100644 --- a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc +++ b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc @@ -228,17 +228,11 @@ static grpc_call_error check_server_start_success(grpc_call* /*call*/, nullptr); GPR_ASSERT(upb_strview_eql(application_protocols[0], upb_strview_makez(ALTS_APPLICATION_PROTOCOL))); - size_t handshake_parameters_count; - const grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry* const* - handshake_parameters = - grpc_gcp_StartServerHandshakeReq_handshake_parameters( - server_start, &handshake_parameters_count); - GPR_ASSERT(handshake_parameters_count == 1); - GPR_ASSERT(grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_key( - handshake_parameters[0]) == grpc_gcp_ALTS); - const grpc_gcp_ServerHandshakeParameters* value = - grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_value( - handshake_parameters[0]); + GPR_ASSERT(grpc_gcp_StartServerHandshakeReq_handshake_parameters_size( + server_start) == 1); + grpc_gcp_ServerHandshakeParameters* value; + GPR_ASSERT(grpc_gcp_StartServerHandshakeReq_handshake_parameters_get( + server_start, grpc_gcp_ALTS, &value)); upb_strview const* record_protocols = grpc_gcp_ServerHandshakeParameters_record_protocols(value, nullptr); GPR_ASSERT(upb_strview_eql(record_protocols[0],