diff --git a/Userland/Services/SpiceAgent/Message.cpp b/Userland/Services/SpiceAgent/Message.cpp index 6bbb430e6e7..6c7da279488 100644 --- a/Userland/Services/SpiceAgent/Message.cpp +++ b/Userland/Services/SpiceAgent/Message.cpp @@ -267,4 +267,25 @@ ErrorOr FileTransferStatusMessage::debug_description() return builder.to_string(); } +ErrorOr FileTransferDataMessage::read_from_stream(AK::Stream& stream) +{ + auto id = TRY(stream.read_value()); + auto size = TRY(stream.read_value()); + + auto contents = TRY(ByteBuffer::create_uninitialized(size)); + TRY(stream.read_until_filled(contents)); + + return FileTransferDataMessage(id, contents); +} + +ErrorOr FileTransferDataMessage::debug_description() +{ + StringBuilder builder; + TRY(builder.try_append("FileTransferData { "sv)); + TRY(builder.try_appendff("id = {}, ", id())); + TRY(builder.try_appendff("contents.size() = {}", contents().size())); + TRY(builder.try_append(" }"sv)); + return builder.to_string(); +} + } diff --git a/Userland/Services/SpiceAgent/Message.h b/Userland/Services/SpiceAgent/Message.h index 3875b891958..4d2345f3e7a 100644 --- a/Userland/Services/SpiceAgent/Message.h +++ b/Userland/Services/SpiceAgent/Message.h @@ -242,6 +242,28 @@ private: FileTransferStatus m_status; }; +// Contains the file data sent from a file transfer request after it has been approved. +class FileTransferDataMessage : public Message { +public: + static ErrorOr read_from_stream(AK::Stream& stream); + + ErrorOr debug_description() override; + + u32 id() const { return m_id; } + ByteBuffer const& contents() { return m_contents; } + +private: + FileTransferDataMessage(u32 id, ByteBuffer const& contents) + : Message(Type::FileTransferData) + , m_id(id) + , m_contents(contents) + { + } + + u32 m_id { 0 }; + ByteBuffer m_contents; +}; + } namespace AK {