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
|
@ -26,15 +26,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/BufferStream.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <LibIPC/Message.h>
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<typename T>
|
||||
bool decode(BufferStream&, T&)
|
||||
inline bool decode(Decoder&, T&)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -64,6 +68,21 @@ public:
|
|||
return IPC::decode(*this, value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool decode(Vector<T>& vector)
|
||||
{
|
||||
u64 size;
|
||||
if (!decode(size) || size > NumericLimits<i32>::max())
|
||||
return false;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
T value;
|
||||
if (!decode(value))
|
||||
return false;
|
||||
vector.append(move(value));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
BufferStream& m_stream;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue