From 24a0354ce84c6c839930788bc772736f7c56ae18 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 29 Mar 2020 19:03:13 +0200 Subject: [PATCH] LibIPC+LibGfx: Pass the IPC::Decoder to decoding helpers Instead of passing the BufferStream, pass the Decoder. I'd like to stop using BufferStream eventually anyway, so it's good to get it out of any API's where it's in currently. --- Libraries/LibGfx/Color.cpp | 6 +++--- Libraries/LibGfx/Color.h | 3 ++- Libraries/LibGfx/Point.cpp | 9 +++++---- Libraries/LibGfx/Point.h | 3 ++- Libraries/LibGfx/Rect.cpp | 7 ++++--- Libraries/LibGfx/Rect.h | 3 ++- Libraries/LibGfx/Size.cpp | 9 +++++---- Libraries/LibGfx/Size.h | 3 ++- Libraries/LibIPC/Decoder.h | 2 +- 9 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Libraries/LibGfx/Color.cpp b/Libraries/LibGfx/Color.cpp index 851bc1d24b..01bb3988d4 100644 --- a/Libraries/LibGfx/Color.cpp +++ b/Libraries/LibGfx/Color.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -386,11 +387,10 @@ const LogStream& operator<<(const LogStream& stream, Color value) return stream << value.to_string(); } -bool IPC::decode(BufferStream& stream, Color& color) +bool IPC::decode(IPC::Decoder& decoder, Color& color) { u32 rgba = 0; - stream >> rgba; - if (stream.handle_read_failure()) + if (!decoder.decode(rgba)) return false; color = Color::from_rgba(rgba); return true; diff --git a/Libraries/LibGfx/Color.h b/Libraries/LibGfx/Color.h index 456e3f0724..490b3d7249 100644 --- a/Libraries/LibGfx/Color.h +++ b/Libraries/LibGfx/Color.h @@ -28,6 +28,7 @@ #include #include +#include namespace Gfx { @@ -280,5 +281,5 @@ const LogStream& operator<<(const LogStream&, Color); using Gfx::Color; namespace IPC { -bool decode(BufferStream&, Gfx::Color&); +bool decode(Decoder&, Gfx::Color&); } diff --git a/Libraries/LibGfx/Point.cpp b/Libraries/LibGfx/Point.cpp index 2371e75cb7..32bd115a48 100644 --- a/Libraries/LibGfx/Point.cpp +++ b/Libraries/LibGfx/Point.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace Gfx { @@ -44,13 +45,13 @@ const LogStream& operator<<(const LogStream& stream, const Point& value) namespace IPC { -bool decode(BufferStream& stream, Gfx::Point& point) +bool decode(Decoder& decoder, Gfx::Point& point) { int x = 0; int y = 0; - stream >> x; - stream >> y; - if (stream.handle_read_failure()) + if (!decoder.decode(x)) + return false; + if (!decoder.decode(y)) return false; point = { x, y }; return true; diff --git a/Libraries/LibGfx/Point.h b/Libraries/LibGfx/Point.h index 4007642d2a..67a123cb4c 100644 --- a/Libraries/LibGfx/Point.h +++ b/Libraries/LibGfx/Point.h @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace Gfx { @@ -162,5 +163,5 @@ const LogStream& operator<<(const LogStream&, const Point&); } namespace IPC { -bool decode(BufferStream&, Gfx::Point&); +bool decode(Decoder&, Gfx::Point&); } diff --git a/Libraries/LibGfx/Rect.cpp b/Libraries/LibGfx/Rect.cpp index 5c39b15789..e3ec19b37b 100644 --- a/Libraries/LibGfx/Rect.cpp +++ b/Libraries/LibGfx/Rect.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace Gfx { @@ -145,13 +146,13 @@ const LogStream& operator<<(const LogStream& stream, const Rect& value) namespace IPC { -bool decode(BufferStream& stream, Gfx::Rect& rect) +bool decode(Decoder& decoder, Gfx::Rect& rect) { Gfx::Point point; Gfx::Size size; - if (!decode(stream, point)) + if (!decoder.decode(point)) return false; - if (!decode(stream, size)) + if (!decoder.decode(size)) return false; rect = { point, size }; return true; diff --git a/Libraries/LibGfx/Rect.h b/Libraries/LibGfx/Rect.h index d9109067f4..5a025cb282 100644 --- a/Libraries/LibGfx/Rect.h +++ b/Libraries/LibGfx/Rect.h @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace Gfx { @@ -337,5 +338,5 @@ const LogStream& operator<<(const LogStream&, const Rect&); } namespace IPC { -bool decode(BufferStream&, Gfx::Rect&); +bool decode(Decoder&, Gfx::Rect&); } diff --git a/Libraries/LibGfx/Size.cpp b/Libraries/LibGfx/Size.cpp index 6274e2be8f..ce49aa678d 100644 --- a/Libraries/LibGfx/Size.cpp +++ b/Libraries/LibGfx/Size.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace Gfx { @@ -44,13 +45,13 @@ const LogStream& operator<<(const LogStream& stream, const Size& value) namespace IPC { -bool decode(BufferStream& stream, Gfx::Size& size) +bool decode(Decoder& decoder, Gfx::Size& size) { int width = 0; int height = 0; - stream >> width; - stream >> height; - if (stream.handle_read_failure()) + if (!decoder.decode(width)) + return false; + if (!decoder.decode(height)) return false; size = { width, height }; return true; diff --git a/Libraries/LibGfx/Size.h b/Libraries/LibGfx/Size.h index 4156d751d6..4ca7f0addb 100644 --- a/Libraries/LibGfx/Size.h +++ b/Libraries/LibGfx/Size.h @@ -28,6 +28,7 @@ #include #include +#include namespace Gfx { @@ -113,5 +114,5 @@ const LogStream& operator<<(const LogStream&, const Size&); } namespace IPC { -bool decode(BufferStream&, Gfx::Size&); +bool decode(Decoder&, Gfx::Size&); } diff --git a/Libraries/LibIPC/Decoder.h b/Libraries/LibIPC/Decoder.h index 8c254fc0ce..4cba8ebb5a 100644 --- a/Libraries/LibIPC/Decoder.h +++ b/Libraries/LibIPC/Decoder.h @@ -59,7 +59,7 @@ public: template bool decode(T& value) { - return IPC::decode(m_stream, value); + return IPC::decode(*this, value); } private: