[upb] cast pointers to (upb_Message*) when calling upb functions

upb currently defines upb_Message to be void but that may soon change,
at which point the gRPC build would break without these casts.

This time for sure! With C++-style casts that also actually build!
pull/35332/head
Eric Salo 11 months ago
parent 07706bc979
commit e7768a37c9
  1. 12
      src/core/ext/xds/xds_api.cc
  2. 3
      src/core/ext/xds/xds_cluster.cc
  3. 5
      src/core/ext/xds/xds_cluster_specifier_plugin.cc
  4. 10
      src/core/ext/xds/xds_common_types.cc
  5. 3
      src/core/ext/xds/xds_endpoint.cc
  6. 8
      src/core/ext/xds/xds_listener.cc
  7. 3
      src/core/ext/xds/xds_route_config.cc

@ -185,7 +185,8 @@ void MaybeLogDiscoveryRequest(
const upb_MessageDef* msg_type = const upb_MessageDef* msg_type =
envoy_service_discovery_v3_DiscoveryRequest_getmsgdef(context.def_pool); envoy_service_discovery_v3_DiscoveryRequest_getmsgdef(context.def_pool);
char buf[10240]; char buf[10240];
upb_TextEncode(request, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(request), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s", gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s",
context.client, buf); context.client, buf);
} }
@ -274,7 +275,8 @@ void MaybeLogDiscoveryResponse(
envoy_service_discovery_v3_DiscoveryResponse_getmsgdef( envoy_service_discovery_v3_DiscoveryResponse_getmsgdef(
context.def_pool); context.def_pool);
char buf[10240]; char buf[10240];
upb_TextEncode(response, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(response), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", context.client, gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", context.client,
buf); buf);
} }
@ -362,7 +364,8 @@ void MaybeLogLrsRequest(
envoy_service_load_stats_v3_LoadStatsRequest_getmsgdef( envoy_service_load_stats_v3_LoadStatsRequest_getmsgdef(
context.def_pool); context.def_pool);
char buf[10240]; char buf[10240];
upb_TextEncode(request, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(request), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s", gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s",
context.client, buf); context.client, buf);
} }
@ -523,7 +526,8 @@ void MaybeLogLrsResponse(
envoy_service_load_stats_v3_LoadStatsResponse_getmsgdef( envoy_service_load_stats_v3_LoadStatsResponse_getmsgdef(
context.def_pool); context.def_pool);
char buf[10240]; char buf[10240];
upb_TextEncode(response, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(response), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] received LRS response: %s", gpr_log(GPR_DEBUG, "[xds_client %p] received LRS response: %s",
context.client, buf); context.client, buf);
} }

@ -658,7 +658,8 @@ void MaybeLogCluster(const XdsResourceType::DecodeContext& context,
const upb_MessageDef* msg_type = const upb_MessageDef* msg_type =
envoy_config_cluster_v3_Cluster_getmsgdef(context.symtab); envoy_config_cluster_v3_Cluster_getmsgdef(context.symtab);
char buf[10240]; char buf[10240];
upb_TextEncode(cluster, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(cluster), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", context.client, buf); gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", context.client, buf);
} }
} }

@ -70,8 +70,9 @@ Json XdsRouteLookupClusterSpecifierPlugin::GenerateLoadBalancingPolicyConfig(
errors->AddError("could not parse plugin config"); errors->AddError("could not parse plugin config");
return {}; return {};
} }
const auto* plugin_config = const auto* plugin_config = reinterpret_cast<const upb_Message*>(
grpc_lookup_v1_RouteLookupClusterSpecifier_route_lookup_config(specifier); grpc_lookup_v1_RouteLookupClusterSpecifier_route_lookup_config(
specifier));
if (plugin_config == nullptr) { if (plugin_config == nullptr) {
ValidationErrors::ScopedField field(errors, ".route_lookup_config"); ValidationErrors::ScopedField field(errors, ".route_lookup_config");
errors->AddError("field not present"); errors->AddError("field not present");

@ -425,16 +425,18 @@ absl::StatusOr<Json> ParseProtobufStructToJson(
const google_protobuf_Struct* resource) { const google_protobuf_Struct* resource) {
upb::Status status; upb::Status status;
const auto* msg_def = google_protobuf_Struct_getmsgdef(context.symtab); const auto* msg_def = google_protobuf_Struct_getmsgdef(context.symtab);
size_t json_size = upb_JsonEncode(resource, msg_def, context.symtab, 0, size_t json_size =
nullptr, 0, status.ptr()); upb_JsonEncode(reinterpret_cast<const upb_Message*>(resource), msg_def,
context.symtab, 0, nullptr, 0, status.ptr());
if (json_size == static_cast<size_t>(-1)) { if (json_size == static_cast<size_t>(-1)) {
return absl::InvalidArgumentError( return absl::InvalidArgumentError(
absl::StrCat("error encoding google::Protobuf::Struct as JSON: ", absl::StrCat("error encoding google::Protobuf::Struct as JSON: ",
upb_Status_ErrorMessage(status.ptr()))); upb_Status_ErrorMessage(status.ptr())));
} }
void* buf = upb_Arena_Malloc(context.arena, json_size + 1); void* buf = upb_Arena_Malloc(context.arena, json_size + 1);
upb_JsonEncode(resource, msg_def, context.symtab, 0, upb_JsonEncode(reinterpret_cast<const upb_Message*>(resource), msg_def,
reinterpret_cast<char*>(buf), json_size + 1, status.ptr()); context.symtab, 0, reinterpret_cast<char*>(buf), json_size + 1,
status.ptr());
auto json = JsonParse(reinterpret_cast<char*>(buf)); auto json = JsonParse(reinterpret_cast<char*>(buf));
if (!json.ok()) { if (!json.ok()) {
// This should never happen. // This should never happen.

@ -162,7 +162,8 @@ void MaybeLogClusterLoadAssignment(
envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef( envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(
context.symtab); context.symtab);
char buf[10240]; char buf[10240];
upb_TextEncode(cla, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(cla), msg_type, nullptr,
0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s", gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s",
context.client, buf); context.client, buf);
} }

@ -291,8 +291,9 @@ void MaybeLogHttpConnectionManager(
envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef( envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef(
context.symtab); context.symtab);
char buf[10240]; char buf[10240];
upb_TextEncode(http_connection_manager_config, msg_type, nullptr, 0, buf, upb_TextEncode(
sizeof(buf)); reinterpret_cast<const upb_Message*>(http_connection_manager_config),
msg_type, nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] HttpConnectionManager: %s", gpr_log(GPR_DEBUG, "[xds_client %p] HttpConnectionManager: %s",
context.client, buf); context.client, buf);
} }
@ -1095,7 +1096,8 @@ void MaybeLogListener(const XdsResourceType::DecodeContext& context,
const upb_MessageDef* msg_type = const upb_MessageDef* msg_type =
envoy_config_listener_v3_Listener_getmsgdef(context.symtab); envoy_config_listener_v3_Listener_getmsgdef(context.symtab);
char buf[10240]; char buf[10240];
upb_TextEncode(listener, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(listener), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] Listener: %s", context.client, buf); gpr_log(GPR_DEBUG, "[xds_client %p] Listener: %s", context.client, buf);
} }
} }

@ -1137,7 +1137,8 @@ void MaybeLogRouteConfiguration(
const upb_MessageDef* msg_type = const upb_MessageDef* msg_type =
envoy_config_route_v3_RouteConfiguration_getmsgdef(context.symtab); envoy_config_route_v3_RouteConfiguration_getmsgdef(context.symtab);
char buf[10240]; char buf[10240];
upb_TextEncode(route_config, msg_type, nullptr, 0, buf, sizeof(buf)); upb_TextEncode(reinterpret_cast<const upb_Message*>(route_config), msg_type,
nullptr, 0, buf, sizeof(buf));
gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", context.client, gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", context.client,
buf); buf);
} }

Loading…
Cancel
Save