feat: add support for string_view as D-Bus type
This commit is contained in:
1 parent
d856969051
commit
f15c260750
5 files changed
+39
-3
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user