summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibIPC/Decoder.cpp10
-rw-r--r--Userland/Libraries/LibIPC/Decoder.h5
-rw-r--r--Userland/Libraries/LibIPC/Encoder.cpp28
-rw-r--r--Userland/Libraries/LibIPC/Encoder.h8
4 files changed, 42 insertions, 9 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp
index 977695656b..edc0ea38f3 100644
--- a/Userland/Libraries/LibIPC/Decoder.cpp
+++ b/Userland/Libraries/LibIPC/Decoder.cpp
@@ -37,13 +37,19 @@ ErrorOr<void> Decoder::decode(u16& value)
return m_stream.try_handle_any_error();
}
-ErrorOr<void> Decoder::decode(u32& value)
+ErrorOr<void> Decoder::decode(unsigned& value)
{
m_stream >> value;
return m_stream.try_handle_any_error();
}
-ErrorOr<void> Decoder::decode(u64& value)
+ErrorOr<void> Decoder::decode(unsigned long& value)
+{
+ m_stream >> value;
+ return m_stream.try_handle_any_error();
+}
+
+ErrorOr<void> Decoder::decode(unsigned long long& value)
{
m_stream >> value;
return m_stream.try_handle_any_error();
diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h
index fee5c02a7c..c36e4a2a52 100644
--- a/Userland/Libraries/LibIPC/Decoder.h
+++ b/Userland/Libraries/LibIPC/Decoder.h
@@ -34,8 +34,9 @@ public:
ErrorOr<void> decode(bool&);
ErrorOr<void> decode(u8&);
ErrorOr<void> decode(u16&);
- ErrorOr<void> decode(u32&);
- ErrorOr<void> decode(u64&);
+ ErrorOr<void> decode(unsigned&);
+ ErrorOr<void> decode(unsigned long&);
+ ErrorOr<void> decode(unsigned long long&);
ErrorOr<void> decode(i8&);
ErrorOr<void> decode(i16&);
ErrorOr<void> decode(i32&);
diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp
index 0fcb0d9516..0958898de3 100644
--- a/Userland/Libraries/LibIPC/Encoder.cpp
+++ b/Userland/Libraries/LibIPC/Encoder.cpp
@@ -36,17 +36,16 @@ Encoder& Encoder::operator<<(u16 value)
return *this;
}
-Encoder& Encoder::operator<<(u32 value)
+void Encoder::encode_u32(u32 value)
{
m_buffer.data.ensure_capacity(m_buffer.data.size() + 4);
m_buffer.data.unchecked_append((u8)value);
m_buffer.data.unchecked_append((u8)(value >> 8));
m_buffer.data.unchecked_append((u8)(value >> 16));
m_buffer.data.unchecked_append((u8)(value >> 24));
- return *this;
}
-Encoder& Encoder::operator<<(u64 value)
+void Encoder::encode_u64(u64 value)
{
m_buffer.data.ensure_capacity(m_buffer.data.size() + 8);
m_buffer.data.unchecked_append((u8)value);
@@ -57,6 +56,29 @@ Encoder& Encoder::operator<<(u64 value)
m_buffer.data.unchecked_append((u8)(value >> 40));
m_buffer.data.unchecked_append((u8)(value >> 48));
m_buffer.data.unchecked_append((u8)(value >> 56));
+}
+
+Encoder& Encoder::operator<<(unsigned value)
+{
+ encode_u32(value);
+ return *this;
+}
+
+Encoder& Encoder::operator<<(unsigned long value)
+{
+ if constexpr (sizeof(value) == 4)
+ encode_u32(value);
+ else
+ encode_u64(value);
+ return *this;
+}
+
+Encoder& Encoder::operator<<(unsigned long long value)
+{
+ if constexpr (sizeof(value) == 4)
+ encode_u32(value);
+ else
+ encode_u64(value);
return *this;
}
diff --git a/Userland/Libraries/LibIPC/Encoder.h b/Userland/Libraries/LibIPC/Encoder.h
index 5a10b55192..8d442d7ba4 100644
--- a/Userland/Libraries/LibIPC/Encoder.h
+++ b/Userland/Libraries/LibIPC/Encoder.h
@@ -30,8 +30,9 @@ public:
Encoder& operator<<(bool);
Encoder& operator<<(u8);
Encoder& operator<<(u16);
- Encoder& operator<<(u32);
- Encoder& operator<<(u64);
+ Encoder& operator<<(unsigned);
+ Encoder& operator<<(unsigned long);
+ Encoder& operator<<(unsigned long long);
Encoder& operator<<(i8);
Encoder& operator<<(i16);
Encoder& operator<<(i32);
@@ -95,6 +96,9 @@ public:
}
private:
+ void encode_u32(u32);
+ void encode_u64(u64);
+
MessageBuffer& m_buffer;
};