summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibIPC/Decoder.cpp19
-rw-r--r--Libraries/LibIPC/Decoder.h21
-rw-r--r--Libraries/LibIPC/Encoder.cpp8
-rw-r--r--Libraries/LibIPC/Encoder.h11
4 files changed, 59 insertions, 0 deletions
diff --git a/Libraries/LibIPC/Decoder.cpp b/Libraries/LibIPC/Decoder.cpp
index 6854c8f016..c76f9a7330 100644
--- a/Libraries/LibIPC/Decoder.cpp
+++ b/Libraries/LibIPC/Decoder.cpp
@@ -112,6 +112,25 @@ bool Decoder::decode(String& value)
return !m_stream.handle_any_error();
}
+bool Decoder::decode(ByteBuffer& value)
+{
+ i32 length = 0;
+ m_stream >> length;
+ if (m_stream.handle_any_error())
+ return false;
+ if (length < 0) {
+ value = {};
+ return true;
+ }
+ if (length == 0) {
+ value = ByteBuffer::create_uninitialized(0);
+ return true;
+ }
+ value = ByteBuffer::create_uninitialized(length);
+ m_stream >> value.bytes();
+ return !m_stream.handle_any_error();
+}
+
bool Decoder::decode(URL& value)
{
String string;
diff --git a/Libraries/LibIPC/Decoder.h b/Libraries/LibIPC/Decoder.h
index 37c3d6a848..0b5d39041e 100644
--- a/Libraries/LibIPC/Decoder.h
+++ b/Libraries/LibIPC/Decoder.h
@@ -60,8 +60,29 @@ public:
bool decode(i64&);
bool decode(float&);
bool decode(String&);
+ bool decode(ByteBuffer&);
bool decode(URL&);
bool decode(Dictionary&);
+ template<typename K, typename V>
+ bool decode(HashMap<K, V>& hashmap)
+ {
+ u32 size;
+ if (!decode(size) || size > NumericLimits<i32>::max())
+ return false;
+
+ for (size_t i = 0; i < size; ++i) {
+ K key;
+ if (!decode(key))
+ return false;
+
+ V value;
+ if (!decode(value))
+ return false;
+
+ hashmap.set(move(key), move(value));
+ }
+ return true;
+ }
template<typename T>
bool decode(T& value)
diff --git a/Libraries/LibIPC/Encoder.cpp b/Libraries/LibIPC/Encoder.cpp
index af93c9918e..c0eb8d670e 100644
--- a/Libraries/LibIPC/Encoder.cpp
+++ b/Libraries/LibIPC/Encoder.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <AK/URL.h>
#include <LibIPC/Dictionary.h>
@@ -141,6 +142,13 @@ Encoder& Encoder::operator<<(const String& value)
return *this << value.view();
}
+Encoder& Encoder::operator<<(const ByteBuffer& value)
+{
+ *this << static_cast<i32>(value.size());
+ m_buffer.append(value.data(), value.size());
+ return *this;
+}
+
Encoder& Encoder::operator<<(const URL& value)
{
return *this << value.to_string();
diff --git a/Libraries/LibIPC/Encoder.h b/Libraries/LibIPC/Encoder.h
index b5869c5a82..2af6d0fbca 100644
--- a/Libraries/LibIPC/Encoder.h
+++ b/Libraries/LibIPC/Encoder.h
@@ -58,8 +58,19 @@ public:
Encoder& operator<<(const char*);
Encoder& operator<<(const StringView&);
Encoder& operator<<(const String&);
+ Encoder& operator<<(const ByteBuffer&);
Encoder& operator<<(const URL&);
Encoder& operator<<(const Dictionary&);
+ template<typename K, typename V>
+ Encoder& operator<<(const HashMap<K, V>& hashmap)
+ {
+ *this << (u32)hashmap.size();
+ for (auto it : hashmap) {
+ *this << it.key;
+ *this << it.value;
+ }
+ return *this;
+ }
template<typename T>
Encoder& operator<<(const Vector<T>& vector)