mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibIPC: Use a simpler encoding for arithmetic values
This is less code, but mostly serves to reduce the amount of methods to be added to IPC::MessageBuffer in an upcoming patch.
This commit is contained in:
parent
3adf01b816
commit
bf15b66117
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/bf15b66117 Pull-request: https://github.com/SerenityOS/serenity/pull/22545 Issue: https://github.com/SerenityOS/serenity/issues/22358
1 changed files with 1 additions and 30 deletions
|
@ -40,11 +40,6 @@ public:
|
|||
return m_buffer.data.try_ensure_capacity(m_buffer.data.size() + capacity);
|
||||
}
|
||||
|
||||
void append(u8 value)
|
||||
{
|
||||
m_buffer.data.unchecked_append(value);
|
||||
}
|
||||
|
||||
ErrorOr<void> append(u8 const* values, size_t count)
|
||||
{
|
||||
TRY(extend_capacity(count));
|
||||
|
@ -67,31 +62,7 @@ private:
|
|||
template<Arithmetic T>
|
||||
ErrorOr<void> encode(Encoder& encoder, T const& value)
|
||||
{
|
||||
TRY(encoder.extend_capacity(sizeof(T)));
|
||||
|
||||
if constexpr (sizeof(T) == 1) {
|
||||
encoder.append(static_cast<u8>(value));
|
||||
} else if constexpr (sizeof(T) == 2) {
|
||||
encoder.append(static_cast<u8>(value));
|
||||
encoder.append(static_cast<u8>(value >> 8));
|
||||
} else if constexpr (sizeof(T) == 4) {
|
||||
encoder.append(static_cast<u8>(value));
|
||||
encoder.append(static_cast<u8>(value >> 8));
|
||||
encoder.append(static_cast<u8>(value >> 16));
|
||||
encoder.append(static_cast<u8>(value >> 24));
|
||||
} else if constexpr (sizeof(T) == 8) {
|
||||
encoder.append(static_cast<u8>(value));
|
||||
encoder.append(static_cast<u8>(value >> 8));
|
||||
encoder.append(static_cast<u8>(value >> 16));
|
||||
encoder.append(static_cast<u8>(value >> 24));
|
||||
encoder.append(static_cast<u8>(value >> 32));
|
||||
encoder.append(static_cast<u8>(value >> 40));
|
||||
encoder.append(static_cast<u8>(value >> 48));
|
||||
encoder.append(static_cast<u8>(value >> 56));
|
||||
} else {
|
||||
static_assert(DependentFalse<T>);
|
||||
}
|
||||
|
||||
TRY(encoder.append(reinterpret_cast<u8 const*>(&value), sizeof(value)));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue