mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
LibIPC: Add a simple IPC::Dictionary type (String key -> String value)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user