feat: add support for string_view as D-Bus type

This commit is contained in:
Stanislav Angelovič committed 2024-04-24 20:20:29 +02:00
1 parent d856969051
commit f15c260750
5 files changed
+39 -3

No files matched your search

+12
View File
@@ -35,6 +35,7 @@
#include "ScopeGuard.h"
#include <cassert>
#include <cstring>
#include SDBUS_HEADER
namespace sdbus {
@@ -197,6 +198,17 @@ Message& Message::operator<<(const std::string& item)
return *this;
}
Message& Message::operator<<(std::string_view item)
{
char* destPtr{};
auto r = sd_bus_message_append_string_space((sd_bus_message*)msg_, item.length(), &destPtr);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a string_view value", -r);
std::memcpy(destPtr, item.data(), item.length());
return *this;
}
Message& Message::operator<<(const Variant &item)
{
item.serializeTo(*this);