mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-10 19:46:03 +00:00
LibIPC: Add encoder and decoder for AK::OrderedHashMap
Seems like a useful thing to have.
This commit is contained in:
parent
a8a50a994b
commit
f2b4c044db
Notes:
sideshowbarker
2024-07-17 14:33:22 +09:00
Author: https://github.com/vkoskiv
Commit: f2b4c044db
Pull-request: https://github.com/SerenityOS/serenity/pull/13421
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/linusg
2 changed files with 29 additions and 0 deletions
|
@ -67,6 +67,24 @@ public:
|
|||
return {};
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
ErrorOr<void> decode(OrderedHashMap<K, V>& hashmap)
|
||||
{
|
||||
u32 size;
|
||||
TRY(decode(size));
|
||||
if (size > NumericLimits<i32>::max())
|
||||
return Error::from_string_literal("IPC: Invalid HashMap size"sv);
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
K key;
|
||||
TRY(decode(key));
|
||||
V value;
|
||||
TRY(decode(value));
|
||||
TRY(hashmap.try_set(move(key), move(value)));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
template<Enum T>
|
||||
ErrorOr<void> decode(T& enum_value)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue