LibIPC: Replace u32/u64 value coders with u/ul/ull value coders

We can and should do more cleanups of this kind, but this is a quick fix
to unbreak the 32-bit HackStudio build.
This commit is contained in:
Andreas Kling 2021-11-29 02:18:58 +01:00
parent 16746efcf8
commit ddce053f6c
4 changed files with 42 additions and 9 deletions

View file

@ -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();

View file

@ -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&);

View file

@ -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;
}

View file

@ -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;
};