mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:17:35 +00:00
LibIPC+LibGfx: Templatize IPC encoding as well as decoding
Now most classes dictate how they are serialized and deserialized when transmitted across LibIPC sockets. This also makes the IPC compiler a bit simpler. :^)
This commit is contained in:
parent
cba4880301
commit
3775983dfe
10 changed files with 83 additions and 45 deletions
|
@ -31,6 +31,13 @@
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<typename T>
|
||||
bool encode(BufferStream&, T&)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
class Encoder {
|
||||
public:
|
||||
explicit Encoder(MessageBuffer& buffer)
|
||||
|
@ -53,6 +60,28 @@ public:
|
|||
Encoder& operator<<(const String&);
|
||||
Encoder& operator<<(const Dictionary&);
|
||||
|
||||
template<typename T>
|
||||
Encoder& operator<<(const Vector<T>& vector)
|
||||
{
|
||||
*this << (u64)vector.size();
|
||||
for (auto& value : vector)
|
||||
*this << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Encoder& operator<<(const T& value)
|
||||
{
|
||||
encode(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void encode(const T& value)
|
||||
{
|
||||
IPC::encode(*this, value);
|
||||
}
|
||||
|
||||
private:
|
||||
MessageBuffer& m_buffer;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue