diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-08-26 03:05:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 23:38:57 +0200 |
commit | 2909c3a931439d0cbed3e4599d9eed47a6fdb446 (patch) | |
tree | 7225ae3240891771213dec6da5366e0512781dfa /Userland | |
parent | 6c5fb2ca63b300b748f7b8e66efa532a450b0a58 (diff) | |
download | serenity-2909c3a931439d0cbed3e4599d9eed47a6fdb446.zip |
LibIPC: Add support for transferring doubles over IPC messages
I'm still wondering why nobody did this yet :^) Also changes the use of
unions for the more cleaner / less undefined AK::bit_cast.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.h | 1 |
4 files changed, 18 insertions, 6 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp index 677bf69e02..4a2093b78c 100644 --- a/Userland/Libraries/LibIPC/Decoder.cpp +++ b/Userland/Libraries/LibIPC/Decoder.cpp @@ -78,6 +78,12 @@ bool Decoder::decode(float& value) return !m_stream.handle_any_error(); } +bool Decoder::decode(double& value) +{ + m_stream >> value; + return !m_stream.handle_any_error(); +} + bool Decoder::decode(String& value) { i32 length = 0; diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h index 84f066ae22..f868e7c514 100644 --- a/Userland/Libraries/LibIPC/Decoder.h +++ b/Userland/Libraries/LibIPC/Decoder.h @@ -41,6 +41,7 @@ public: bool decode(i32&); bool decode(i64&); bool decode(float&); + bool decode(double&); bool decode(String&); bool decode(ByteBuffer&); bool decode(URL&); diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp index de01f2d998..31538e6c43 100644 --- a/Userland/Libraries/LibIPC/Encoder.cpp +++ b/Userland/Libraries/LibIPC/Encoder.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/BitCast.h> #include <AK/ByteBuffer.h> #include <AK/String.h> #include <AK/URL.h> @@ -98,12 +100,14 @@ Encoder& Encoder::operator<<(i64 value) Encoder& Encoder::operator<<(float value) { - union bits { - float as_float; - u32 as_u32; - } u; - u.as_float = value; - return *this << u.as_u32; + u32 as_u32 = bit_cast<u32>(value); + return *this << as_u32; +} + +Encoder& Encoder::operator<<(double value) +{ + u64 as_u64 = bit_cast<u64>(value); + return *this << as_u64; } Encoder& Encoder::operator<<(char const* value) diff --git a/Userland/Libraries/LibIPC/Encoder.h b/Userland/Libraries/LibIPC/Encoder.h index 438d6acfb4..aea7637b34 100644 --- a/Userland/Libraries/LibIPC/Encoder.h +++ b/Userland/Libraries/LibIPC/Encoder.h @@ -37,6 +37,7 @@ public: Encoder& operator<<(i32); Encoder& operator<<(i64); Encoder& operator<<(float); + Encoder& operator<<(double); Encoder& operator<<(char const*); Encoder& operator<<(StringView const&); Encoder& operator<<(String const&); |