mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
SpiceAgent: Implement FileTransferData
messages
This commit is contained in:
parent
af91c75080
commit
d87f823a68
Notes:
sideshowbarker
2024-07-17 11:30:54 +09:00
Author: https://github.com/caoimhebyrne Commit: https://github.com/SerenityOS/serenity/commit/d87f823a68 Pull-request: https://github.com/SerenityOS/serenity/pull/18834 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/drunderscore Reviewed-by: https://github.com/supercomputer7
2 changed files with 43 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue