SpiceAgent: Implement FileTransferData messages

This commit is contained in:
Caoimhe 2023-05-19 23:32:04 +01:00 committed by Andreas Kling
parent af91c75080
commit d87f823a68
Notes: sideshowbarker 2024-07-17 11:30:54 +09:00
2 changed files with 43 additions and 0 deletions

View file

@ -267,4 +267,25 @@ ErrorOr<String> FileTransferStatusMessage::debug_description()
return builder.to_string();
}
ErrorOr<FileTransferDataMessage> FileTransferDataMessage::read_from_stream(AK::Stream& stream)
{
auto id = TRY(stream.read_value<u32>());
auto size = TRY(stream.read_value<u64>());
auto contents = TRY(ByteBuffer::create_uninitialized(size));
TRY(stream.read_until_filled(contents));
return FileTransferDataMessage(id, contents);
}
ErrorOr<String> 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();
}
}

View file

@ -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<FileTransferDataMessage> read_from_stream(AK::Stream& stream);
ErrorOr<String> 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 {