1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

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.
This commit is contained in:
kleines Filmröllchen 2021-08-26 03:05:01 +02:00 committed by Andreas Kling
parent 6c5fb2ca63
commit 2909c3a931
4 changed files with 18 additions and 6 deletions

View file

@ -78,6 +78,12 @@ bool Decoder::decode(float& value)
return !m_stream.handle_any_error(); 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) bool Decoder::decode(String& value)
{ {
i32 length = 0; i32 length = 0;

View file

@ -41,6 +41,7 @@ public:
bool decode(i32&); bool decode(i32&);
bool decode(i64&); bool decode(i64&);
bool decode(float&); bool decode(float&);
bool decode(double&);
bool decode(String&); bool decode(String&);
bool decode(ByteBuffer&); bool decode(ByteBuffer&);
bool decode(URL&); bool decode(URL&);

View file

@ -1,9 +1,11 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/BitCast.h>
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/URL.h> #include <AK/URL.h>
@ -98,12 +100,14 @@ Encoder& Encoder::operator<<(i64 value)
Encoder& Encoder::operator<<(float value) Encoder& Encoder::operator<<(float value)
{ {
union bits { u32 as_u32 = bit_cast<u32>(value);
float as_float; return *this << as_u32;
u32 as_u32; }
} u;
u.as_float = value; Encoder& Encoder::operator<<(double value)
return *this << u.as_u32; {
u64 as_u64 = bit_cast<u64>(value);
return *this << as_u64;
} }
Encoder& Encoder::operator<<(char const* value) Encoder& Encoder::operator<<(char const* value)

View file

@ -37,6 +37,7 @@ public:
Encoder& operator<<(i32); Encoder& operator<<(i32);
Encoder& operator<<(i64); Encoder& operator<<(i64);
Encoder& operator<<(float); Encoder& operator<<(float);
Encoder& operator<<(double);
Encoder& operator<<(char const*); Encoder& operator<<(char const*);
Encoder& operator<<(StringView const&); Encoder& operator<<(StringView const&);
Encoder& operator<<(String const&); Encoder& operator<<(String const&);