From d4538df01426c4d6dda3229b643d2478b50381eb Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 14 Aug 2026 11:51:11 +0200 Subject: [PATCH] Add compatibility with newer protobuf --- 3rdparty/stout/include/stout/protobuf.hpp | 34 +++++++++++------------ src/common/protobuf_utils.cpp | 6 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/stout/include/stout/protobuf.hpp index 9a82a304d47..e19f589575c 100644 --- a/3rdparty/stout/include/stout/protobuf.hpp +++ b/3rdparty/stout/include/stout/protobuf.hpp @@ -220,7 +220,7 @@ Try deserialize(const std::string& value) value.data(), static_cast(value.size())); if (!t.ParseFromZeroCopyStream(&stream)) { - return Error("Failed to deserialize " + t.GetDescriptor()->full_name()); + return Error("Failed to deserialize " + std::string(t.GetDescriptor()->full_name())); } return t; } @@ -233,7 +233,7 @@ Try serialize(const T& t) std::string value; if (!t.SerializeToString(&value)) { - return Error("Failed to serialize " + t.GetDescriptor()->full_name()); + return Error("Failed to serialize " + std::string(t.GetDescriptor()->full_name())); } return value; } @@ -483,7 +483,7 @@ struct Parser : boost::static_visitor> break; default: return Error("Not expecting a JSON object for field '" + - field->name() + "'"); + std::string(field->name()) + "'"); } return Nothing(); } @@ -502,7 +502,7 @@ struct Parser : boost::static_visitor> Try decode = base64::decode(string.value); if (decode.isError()) { return Error("Failed to base64 decode bytes field" - " '" + field->name() + "': " + decode.error()); + " '" + std::string(field->name()) + "': " + decode.error()); } if (field->is_repeated()) { @@ -552,7 +552,7 @@ struct Parser : boost::static_visitor> if (number.isError()) { return Error( "Failed to parse '" + string.value + "' as a JSON number " - "for field '" + field->name() + "': " + number.error()); + "for field '" + std::string(field->name()) + "': " + number.error()); } return operator()(number.get()); @@ -572,7 +572,7 @@ struct Parser : boost::static_visitor> if (number.isError()) { return Error( "Failed to parse '" + string.value + "' as a JSON number " - "for field '" + field->name() + "': " + number.error()); + "for field '" + std::string(field->name()) + "': " + number.error()); } return operator()(number.get()); @@ -582,14 +582,14 @@ struct Parser : boost::static_visitor> if (boolean.isError()) { return Error( "Failed to parse '" + string.value + "' as a JSON boolean " - "for field '" + field->name() + "': " + boolean.error()); + "for field '" + std::string(field->name()) + "': " + boolean.error()); } return operator()(boolean.get()); } default: return Error("Not expecting a JSON string for field '" + - field->name() + "'"); + std::string(field->name()) + "'"); } return Nothing(); } @@ -647,7 +647,7 @@ struct Parser : boost::static_visitor> break; default: return Error("Not expecting a JSON number for field '" + - field->name() + "'"); + std::string(field->name()) + "'"); } return Nothing(); } @@ -656,7 +656,7 @@ struct Parser : boost::static_visitor> { if (!field->is_repeated()) { return Error("Not expecting a JSON array for field '" + - field->name() + "'"); + std::string(field->name()) + "'"); } foreach (const JSON::Value& value, array.values) { @@ -683,7 +683,7 @@ struct Parser : boost::static_visitor> break; default: return Error("Not expecting a JSON boolean for field '" + - field->name() + "'"); + std::string(field->name()) + "'"); } return Nothing(); } @@ -864,7 +864,7 @@ inline void json(ObjectWriter* writer, const Protobuf& protobuf) foreach (const FieldDescriptor* field, fields) { if (field->is_repeated() && !field->is_map()) { writer->field( - field->name(), + std::string(field->name()), [&field, &reflection, &message](JSON::ArrayWriter* writer) { int fieldSize = reflection->FieldSize(message, field); for (int i = 0; i < fieldSize; ++i) { @@ -966,11 +966,11 @@ inline void json(ObjectWriter* writer, const Protobuf& protobuf) }; if (!field->is_repeated()) { // Singular field. - writeField(field->name(), reflection, message, field); + writeField(std::string(field->name()), reflection, message, field); } else { // Map field. CHECK(field->is_map()); writer->field( - field->name(), + std::string(field->name()), [&field, &reflection, &message, &writeField]( JSON::ObjectWriter* writer) { foreach ( @@ -1176,7 +1176,7 @@ inline Object protobuf(const google::protobuf::Message& message) map.values[name] = value_for_field(entry, value_field); } - object.values[field->name()] = map; + object.values[std::string(field->name())] = map; } else if (field->is_repeated()) { JSON::Array array; int fieldSize = reflection->FieldSize(message, field); @@ -1243,9 +1243,9 @@ inline Object protobuf(const google::protobuf::Message& message) stringify(field->type())); } } - object.values[field->name()] = array; + object.values[std::string(field->name())] = array; } else { - object.values[field->name()] = value_for_field(message, field); + object.values[std::string(field->name())] = value_for_field(message, field); } } diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp index 723d85a8656..1e4848cd1cb 100644 --- a/src/common/protobuf_utils.cpp +++ b/src/common/protobuf_utils.cpp @@ -123,11 +123,11 @@ Option UnionValidator::validate( reflection->HasField(message, fieldDescriptor)) { const auto* descr = typeDescriptor_->FindValueByNumber(messageTypeNumber); return Error( - "Protobuf union `" + message.GetDescriptor()->full_name() + + "Protobuf union `" + string(message.GetDescriptor()->full_name()) + "` with `Type == " + - (descr == nullptr ? string("") : descr->name()) + + (descr == nullptr ? string("") : string(descr->name())) + "` should not have the field `" + - fieldDescriptor->name() + "` set."); + string(fieldDescriptor->name()) + "` set."); } } return None();