From 3274e1b8eb37f5d5bcd361dc52b8fde9be9b3bfa Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Fri, 13 Nov 2020 04:06:42 +0000 Subject: [PATCH] lib: convert Channel::CheckExchangeExists to use boost::string_ref Prepare for an easier transition to std::string_view. --- src/Channel.cpp | 4 ++-- src/SimpleAmqpClient/Bytes.h | 8 ++++++++ src/SimpleAmqpClient/Channel.h | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Channel.cpp b/src/Channel.cpp index 3964cd47..5c4620f6 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -474,12 +474,12 @@ int Channel::GetSocketFD() const { return amqp_get_sockfd(m_impl->m_connection); } -bool Channel::CheckExchangeExists(const std::string &exchange_name) { +bool Channel::CheckExchangeExists(boost::string_ref exchange_name) { const boost::array DECLARE_OK = { {AMQP_EXCHANGE_DECLARE_OK_METHOD}}; amqp_exchange_declare_t declare = {}; - declare.exchange = StringToBytes(exchange_name); + declare.exchange = StringRefToBytes(exchange_name); declare.passive = true; declare.nowait = false; diff --git a/src/SimpleAmqpClient/Bytes.h b/src/SimpleAmqpClient/Bytes.h index 44e71980..8f351773 100644 --- a/src/SimpleAmqpClient/Bytes.h +++ b/src/SimpleAmqpClient/Bytes.h @@ -2,6 +2,7 @@ #define SIMPLEAMQPCLIENT_BYTES_H #include +#include #include @@ -14,5 +15,12 @@ amqp_bytes_t StringToBytes(const std::string& str) { return ret; } +amqp_bytes_t StringRefToBytes(boost::string_ref str) { + amqp_bytes_t ret; + ret.bytes = reinterpret_cast(const_cast(str.data())); + ret.len = str.length(); + return ret; +} + } // namespace AmqpClient #endif // SIMPLEAMQPCLIENT_BYTES_H diff --git a/src/SimpleAmqpClient/Channel.h b/src/SimpleAmqpClient/Channel.h index 657ca7fb..deded1f0 100644 --- a/src/SimpleAmqpClient/Channel.h +++ b/src/SimpleAmqpClient/Channel.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -350,7 +351,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable { * @param exchange_name the name of the exchange to check for. * @returns true if the exchange exists on the broker, false otherwise. */ - bool CheckExchangeExists(const std::string &exchange_name); + bool CheckExchangeExists(boost::string_ref exchange_name); /** * Declares an exchange