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

Userland: Properly define IPC::encode and IPC::decode specializations

In order to avoid the base encode/decode methods from being used (and
failing a static assertion), we must be sure to declare/define the
custom type implementations as template specializations.

After this, LibIPC is no longer sensitive to include order.
This commit is contained in:
Timothy Flynn 2022-11-15 11:24:59 -05:00 committed by Tim Flynn
parent b1ea418d14
commit 05f41382bb
25 changed files with 75 additions and 2 deletions

View file

@ -366,12 +366,14 @@ Vector<Color> Color::tints(u32 steps, float max) const
}
template<>
bool IPC::encode(Encoder& encoder, Color const& color)
{
encoder << color.value();
return true;
}
template<>
ErrorOr<void> IPC::decode(Decoder& decoder, Color& color)
{
u32 rgba;

View file

@ -568,7 +568,10 @@ struct Formatter<Gfx::Color> : public Formatter<StringView> {
namespace IPC {
template<>
bool encode(Encoder&, Gfx::Color const&);
template<>
ErrorOr<void> decode(Decoder&, Gfx::Color&);
}

View file

@ -51,12 +51,14 @@ String FloatPoint::to_string() const
namespace IPC {
template<>
bool encode(Encoder& encoder, Gfx::IntPoint const& point)
{
encoder << point.x() << point.y();
return true;
}
template<>
ErrorOr<void> decode(Decoder& decoder, Gfx::IntPoint& point)
{
int x = 0;

View file

@ -290,7 +290,10 @@ struct Formatter<Gfx::Point<T>> : Formatter<FormatString> {
namespace IPC {
template<>
bool encode(Encoder&, Gfx::IntPoint const&);
template<>
ErrorOr<void> decode(Decoder&, Gfx::IntPoint&);
}

View file

@ -30,12 +30,14 @@ String FloatRect::to_string() const
namespace IPC {
template<>
bool encode(Encoder& encoder, Gfx::IntRect const& rect)
{
encoder << rect.location() << rect.size();
return true;
}
template<>
ErrorOr<void> decode(Decoder& decoder, Gfx::IntRect& rect)
{
Gfx::IntPoint point;

View file

@ -1031,7 +1031,10 @@ struct Formatter<Gfx::Rect<T>> : Formatter<FormatString> {
namespace IPC {
template<>
bool encode(Encoder&, Gfx::IntRect const&);
template<>
ErrorOr<void> decode(Decoder&, Gfx::IntRect&);
}

View file

@ -22,6 +22,7 @@ ShareableBitmap::ShareableBitmap(NonnullRefPtr<Bitmap> bitmap, Tag)
namespace IPC {
template<>
bool encode(Encoder& encoder, Gfx::ShareableBitmap const& shareable_bitmap)
{
encoder << shareable_bitmap.is_valid();
@ -39,6 +40,7 @@ bool encode(Encoder& encoder, Gfx::ShareableBitmap const& shareable_bitmap)
return true;
}
template<>
ErrorOr<void> decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
{
bool valid = false;

View file

@ -34,7 +34,10 @@ private:
namespace IPC {
template<>
bool encode(Encoder&, Gfx::ShareableBitmap const&);
template<>
ErrorOr<void> decode(Decoder&, Gfx::ShareableBitmap&);
}

View file

@ -27,12 +27,14 @@ String FloatSize::to_string() const
namespace IPC {
template<>
bool encode(Encoder& encoder, Gfx::IntSize const& size)
{
encoder << size.width() << size.height();
return true;
}
template<>
ErrorOr<void> decode(Decoder& decoder, Gfx::IntSize& size)
{
int width = 0;

View file

@ -188,7 +188,10 @@ struct Formatter<Gfx::Size<T>> : Formatter<FormatString> {
namespace IPC {
template<>
bool encode(Encoder&, Gfx::IntSize const&);
template<>
ErrorOr<void> decode(Decoder&, Gfx::IntSize&);
}