mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +00:00
LibIPC: Add a simple IPC::Dictionary type (String key -> String value)
This commit is contained in:
parent
dce3faff08
commit
78943f031e
9 changed files with 101 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/BufferStream.h>
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Dictionary.h>
|
||||
|
||||
namespace IPC {
|
||||
|
||||
|
@ -112,4 +113,27 @@ bool Decoder::decode(String& value)
|
|||
return !m_stream.handle_read_failure();
|
||||
}
|
||||
|
||||
bool Decoder::decode(Dictionary& dictionary)
|
||||
{
|
||||
u64 size = 0;
|
||||
m_stream >> size;
|
||||
if (m_stream.handle_read_failure())
|
||||
return false;
|
||||
if (size >= NumericLimits<i32>::max()) {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
String key;
|
||||
if (!decode(key))
|
||||
return false;
|
||||
String value;
|
||||
if (!decode(value))
|
||||
return false;
|
||||
dictionary.add(move(key), move(value));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue