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

LibIPC+IPCCompiler: Add IPC::Decoder, let classes decode themselves

This shaves ~5 seconds off of a full build, not too bad. Also it just
seems nicer to push this logic out to classes. It could be better but
it's a start. :^)
This commit is contained in:
Andreas Kling 2020-02-15 12:04:35 +01:00
parent dc417ada6d
commit a4d857e3c5
12 changed files with 272 additions and 61 deletions

View file

@ -25,6 +25,7 @@
*/
#include <AK/Assertions.h>
#include <AK/BufferStream.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibGfx/Color.h>
@ -344,7 +345,17 @@ Optional<Color> Color::from_string(const StringView& string)
}
}
inline const LogStream& operator<<(const LogStream& stream, Color value)
const LogStream& operator<<(const LogStream& stream, Color value)
{
return stream << value.to_string();
}
bool IPC::decode(BufferStream& stream, Color& color)
{
u32 rgba;
stream >> rgba;
if (stream.handle_read_failure())
return false;
color = Color::from_rgba(rgba);
return true;
}

View file

@ -278,3 +278,7 @@ const LogStream& operator<<(const LogStream&, Color);
}
using Gfx::Color;
namespace IPC {
bool decode(BufferStream&, Gfx::Color&);
}

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/BufferStream.h>
#include <AK/String.h>
#include <LibGfx/Point.h>
@ -40,3 +41,19 @@ const LogStream& operator<<(const LogStream& stream, const Point& value)
}
}
namespace IPC {
bool decode(BufferStream& stream, Gfx::Point& point)
{
int x;
int y;
stream >> x;
stream >> y;
if (stream.handle_read_failure())
return false;
point = { x, y };
return true;
}
}

View file

@ -159,3 +159,7 @@ private:
const LogStream& operator<<(const LogStream&, const Point&);
}
namespace IPC {
bool decode(BufferStream&, Gfx::Point&);
}

View file

@ -142,3 +142,19 @@ const LogStream& operator<<(const LogStream& stream, const Rect& value)
}
}
namespace IPC {
bool decode(BufferStream& stream, Gfx::Rect& rect)
{
Gfx::Point point;
Gfx::Size size;
if (!decode(stream, point))
return false;
if (!decode(stream, size))
return false;
rect = { point, size };
return true;
}
}

View file

@ -334,3 +334,7 @@ inline void Point::constrain(const Rect& rect)
const LogStream& operator<<(const LogStream&, const Rect&);
}
namespace IPC {
bool decode(BufferStream&, Gfx::Rect&);
}

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/BufferStream.h>
#include <AK/String.h>
#include <LibGfx/Size.h>
@ -40,3 +41,19 @@ const LogStream& operator<<(const LogStream& stream, const Size& value)
}
}
namespace IPC {
bool decode(BufferStream& stream, Gfx::Size& size)
{
int width;
int height;
stream >> width;
stream >> height;
if (stream.handle_read_failure())
return false;
size = { width, height };
return true;
}
}

View file

@ -111,3 +111,7 @@ private:
const LogStream& operator<<(const LogStream&, const Size&);
}
namespace IPC {
bool decode(BufferStream&, Gfx::Size&);
}