| 631 | } |
| 632 | |
| 633 | std::string Message::dumpToString(DumpFlags flags) const |
| 634 | { |
| 635 | #if LIBSYSTEMD_VERSION>=245 && !defined(SDBUS_basu) |
| 636 | char* buffer{}; |
| 637 | SCOPE_EXIT{ free(buffer); }; // NOLINT(cppcoreguidelines-no-malloc,hicpp-no-malloc,cppcoreguidelines-owning-memory) |
| 638 | size_t size{}; |
| 639 | |
| 640 | const std::unique_ptr<FILE, int(*)(FILE*)> stream{open_memstream(&buffer, &size), fclose}; |
| 641 | SDBUS_THROW_ERROR_IF(!stream, "Failed to open memory stream", errno); |
| 642 | |
| 643 | auto r = sd_bus_message_dump(static_cast<sd_bus_message*>(msg_), stream.get(), static_cast<uint64_t>(flags)); |
| 644 | SDBUS_THROW_ERROR_IF(r < 0, "Failed to dump the message", -r); |
| 645 | |
| 646 | (void)fflush(stream.get()); |
| 647 | |
| 648 | return {buffer, size}; |
| 649 | #else |
| 650 | (void)flags; |
| 651 | throw Error(Error::Name{SD_BUS_ERROR_NOT_SUPPORTED}, "Dumping sd-bus message not supported by underlying version of libsystemd"); |
| 652 | #endif |
| 653 | } |
| 654 | |
| 655 | const char* Message::getInterfaceName() const |
| 656 | { |