Skip to content

Commit 3df65f8

Browse files
committed
fix: Adapt model_config_utils to protobuf v33 API
Three breakages against the protobuf bundled with gRPC v1.81.1: - FieldDescriptor::name() now returns absl::string_view; wrap in std::string for concatenation. - JsonPrintOptions::always_print_primitive_fields was removed; use its designated replacement always_print_fields_with_no_presence. - MessageToJsonString's absl::Status return is nodiscard and fails the -Werror build when ignored; propagate it as an INTERNAL status.
1 parent f07e2f3 commit 3df65f8

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/model_config_utils.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ CollectInt64Fields(
19761976
const google::protobuf::Reflection* refl = message->GetReflection();
19771977
for (int i = 0; i < desc->field_count(); ++i) {
19781978
const google::protobuf::FieldDescriptor* field = desc->field(i);
1979-
const std::string fullname = prefix + "::" + field->name();
1979+
const std::string fullname = prefix + "::" + std::string(field->name());
19801980
switch (field->type()) {
19811981
case google::protobuf::FieldDescriptor::TYPE_MESSAGE: {
19821982
if (field->is_repeated()) {
@@ -2201,9 +2201,15 @@ ModelConfigToJson(
22012201
std::string config_json_str;
22022202
::google::protobuf::util::JsonPrintOptions options;
22032203
options.preserve_proto_field_names = true;
2204-
options.always_print_primitive_fields = true;
2205-
::google::protobuf::util::MessageToJsonString(
2204+
options.always_print_fields_with_no_presence = true;
2205+
const auto to_json_status = ::google::protobuf::util::MessageToJsonString(
22062206
config, &config_json_str, options);
2207+
if (!to_json_status.ok()) {
2208+
return Status(
2209+
Status::Code::INTERNAL,
2210+
"failed to convert model configuration to JSON: " +
2211+
std::string(to_json_status.message()));
2212+
}
22072213

22082214
// We need to verify that every field 64-bit field in the
22092215
// ModelConfig protobuf is being handled. We hardcode the known

0 commit comments

Comments
 (0)