From 820ca5b33201c67d290d5c16fa2419121ee76de0 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Aug 2026 23:19:56 +0000 Subject: [PATCH] refactor: Convert boost::beast::string_view to std::string_view (#6306) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mvadari <8029314+mvadari@users.noreply.github.com> Co-authored-by: Mayukha Vadari Co-authored-by: Ayaz Salikhov Co-authored-by: xrplf-ai-reviewer[bot] <266832837+xrplf-ai-reviewer[bot]@users.noreply.github.com> Co-authored-by: Mayukha Vadari Co-authored-by: Timur Yalymov <36795566+tyalymov@users.noreply.github.com> Co-authored-by: Cursor Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com> --- include/xrpl/beast/rfc2616.h | 3 ++- include/xrpl/config/BasicConfig.h | 1 - include/xrpl/json/Output.h | 7 +++---- include/xrpl/server/detail/BaseWSPeer.h | 16 ++++++++-------- src/libxrpl/json/Writer.cpp | 5 +++-- src/xrpld/overlay/detail/ProtocolVersion.cpp | 5 +++-- src/xrpld/overlay/detail/ProtocolVersion.h | 7 +++---- src/xrpld/rpc/detail/ServerHandler.cpp | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/xrpl/beast/rfc2616.h b/include/xrpl/beast/rfc2616.h index 0e061845fb..87d63b0260 100644 --- a/include/xrpl/beast/rfc2616.h +++ b/include/xrpl/beast/rfc2616.h @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace beast::rfc2616 { @@ -186,7 +187,7 @@ splitCommas(FwdIt first, FwdIt last) template > Result -splitCommas(boost::beast::string_view const& s) +splitCommas(std::string_view s) { return splitCommas(s.begin(), s.end()); } diff --git a/include/xrpl/config/BasicConfig.h b/include/xrpl/config/BasicConfig.h index 607a0c3e5f..2278a0fa68 100644 --- a/include/xrpl/config/BasicConfig.h +++ b/include/xrpl/config/BasicConfig.h @@ -2,7 +2,6 @@ #include -#include #include #include diff --git a/include/xrpl/json/Output.h b/include/xrpl/json/Output.h index 53d453c277..f73bd38c77 100644 --- a/include/xrpl/json/Output.h +++ b/include/xrpl/json/Output.h @@ -1,20 +1,19 @@ #pragma once -#include - #include #include +#include namespace json { class Value; -using Output = std::function; +using Output = std::function; inline Output stringOutput(std::string& s) { - return [&](boost::beast::string_view const& b) { s.append(b.data(), b.size()); }; + return [&](std::string_view b) { s.append(b.data(), b.size()); }; } /** diff --git a/include/xrpl/server/detail/BaseWSPeer.h b/include/xrpl/server/detail/BaseWSPeer.h index b1670865bd..403d7f92ee 100644 --- a/include/xrpl/server/detail/BaseWSPeer.h +++ b/include/xrpl/server/detail/BaseWSPeer.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -62,8 +63,7 @@ private: bool pingActive_ = false; boost::beast::websocket::ping_data payload_; error_code ec_; - std::function - controlCallback_; + std::function controlCallback_; public: template @@ -151,7 +151,7 @@ protected: onPing(error_code const& ec); void - onPingPong(boost::beast::websocket::frame_type kind, boost::beast::string_view payload); + onPingPong(boost::beast::websocket::frame_type kind, std::string_view payload); void onTimer(error_code ec); @@ -189,9 +189,9 @@ BaseWSPeer::run() impl().ws_.set_option(port().pmdOptions); // Must manage the control callback memory outside of the `control_callback` // function - controlCallback_ = [this]( - boost::beast::websocket::frame_type kind, - boost::beast::string_view payload) { onPingPong(kind, payload); }; + controlCallback_ = [this](boost::beast::websocket::frame_type kind, std::string_view payload) { + onPingPong(kind, payload); + }; impl().ws_.control_callback(controlCallback_); startTimer(); closeOnTimer_ = true; @@ -430,11 +430,11 @@ template void BaseWSPeer::onPingPong( boost::beast::websocket::frame_type kind, - boost::beast::string_view payload) + std::string_view payload) { if (kind == boost::beast::websocket::frame_type::pong) { - boost::beast::string_view const p(payload_.begin()); + std::string_view const p(payload_.begin(), payload_.size()); if (payload == p) { closeOnTimer_ = false; diff --git a/src/libxrpl/json/Writer.cpp b/src/libxrpl/json/Writer.cpp index 4c922a0e33..c5ce4666ef 100644 --- a/src/libxrpl/json/Writer.cpp +++ b/src/libxrpl/json/Writer.cpp @@ -9,6 +9,7 @@ #include // IWYU pragma: keep #include #include +#include #include #include @@ -87,14 +88,14 @@ public: } void - output(boost::beast::string_view const& bytes) + output(std::string_view bytes) { markStarted(); output_(bytes); } void - stringOutput(boost::beast::string_view const& bytes) + stringOutput(std::string_view bytes) { markStarted(); std::size_t position = 0, writtenUntil = 0; diff --git a/src/xrpld/overlay/detail/ProtocolVersion.cpp b/src/xrpld/overlay/detail/ProtocolVersion.cpp index 1296041ad5..74dad61828 100644 --- a/src/xrpld/overlay/detail/ProtocolVersion.cpp +++ b/src/xrpld/overlay/detail/ProtocolVersion.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace xrpl { @@ -52,7 +53,7 @@ to_string(ProtocolVersion const& p) } std::vector -parseProtocolVersions(boost::beast::string_view const& value) +parseProtocolVersions(std::string_view value) { static boost::regex const kRE( "^" // start of line @@ -119,7 +120,7 @@ negotiateProtocolVersion(std::vector const& versions) } std::optional -negotiateProtocolVersion(boost::beast::string_view const& versions) +negotiateProtocolVersion(std::string_view versions) { auto const them = parseProtocolVersions(versions); diff --git a/src/xrpld/overlay/detail/ProtocolVersion.h b/src/xrpld/overlay/detail/ProtocolVersion.h index b56871318a..5c05f63e2a 100644 --- a/src/xrpld/overlay/detail/ProtocolVersion.h +++ b/src/xrpld/overlay/detail/ProtocolVersion.h @@ -1,10 +1,9 @@ #pragma once -#include - #include #include #include +#include #include #include @@ -43,7 +42,7 @@ to_string(ProtocolVersion const& p); * no duplicates and will be sorted in ascending protocol order. */ std::vector -parseProtocolVersions(boost::beast::string_view const& s); +parseProtocolVersions(std::string_view s); /** * Given a list of supported protocol versions, choose the one we prefer. @@ -55,7 +54,7 @@ negotiateProtocolVersion(std::vector const& versions); * Given a list of supported protocol versions, choose the one we prefer. */ std::optional -negotiateProtocolVersion(boost::beast::string_view const& versions); +negotiateProtocolVersion(std::string_view versions); /** * The list of all the protocol versions we support. diff --git a/src/xrpld/rpc/detail/ServerHandler.cpp b/src/xrpld/rpc/detail/ServerHandler.cpp index 827d8705fd..28e7eebd63 100644 --- a/src/xrpld/rpc/detail/ServerHandler.cpp +++ b/src/xrpld/rpc/detail/ServerHandler.cpp @@ -264,7 +264,7 @@ ServerHandler::onHandoff( static inline json::Output makeOutput(Session& session) { - return [&](boost::beast::string_view const& b) { session.write(b.data(), b.size()); }; + return [&](std::string_view b) { session.write(b.data(), b.size()); }; } static std::map @@ -564,11 +564,11 @@ ServerHandler::processSession( makeOutput(*session), coro, forwardedFor(session->request()), - [&] { + [&] -> std::string_view { auto const iter = session->request().find("X-User"); if (iter != session->request().end()) return iter->value(); - return boost::beast::string_view{}; + return {}; }()); if (beast::rfc2616::isKeepAlive(session->request()))