mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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:
parent
b1ea418d14
commit
05f41382bb
Notes:
sideshowbarker
2024-07-18 05:37:06 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/05f41382bb Pull-request: https://github.com/SerenityOS/serenity/pull/16081 Issue: https://github.com/SerenityOS/serenity/issues/9584 Reviewed-by: https://github.com/linusg ✅
25 changed files with 75 additions and 2 deletions
|
@ -74,7 +74,10 @@ private:
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Core::AnonymousBuffer const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Core::AnonymousBuffer&);
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,10 @@ private:
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Core::DateTime const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Core::DateTime&);
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,11 @@ struct ProxyData {
|
|||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Core::ProxyData const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Core::ProxyData&);
|
||||
|
||||
}
|
||||
|
|
|
@ -100,12 +100,14 @@ ErrorOr<void> AK::Formatter<DNS::RecordClass>::format(AK::FormatBuilder& builder
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder& encoder, DNS::Answer const& answer)
|
||||
{
|
||||
encoder << answer.name().as_string() << (u16)answer.type() << (u16)answer.class_code() << answer.ttl() << answer.record_data() << answer.mdns_cache_flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder& decoder, DNS::Answer& answer)
|
||||
{
|
||||
String name;
|
||||
|
|
|
@ -94,7 +94,10 @@ struct AK::Formatter<DNS::RecordClass> : StandardFormatter {
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, DNS::Answer const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, DNS::Answer&);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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&);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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&);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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&);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -34,7 +34,10 @@ private:
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Gfx::ShareableBitmap const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Gfx::ShareableBitmap&);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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&);
|
||||
|
||||
}
|
||||
|
|
|
@ -170,6 +170,7 @@ ErrorOr<void> Decoder::decode([[maybe_unused]] File& file)
|
|||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder& decoder, Core::AnonymousBuffer& buffer)
|
||||
{
|
||||
bool valid;
|
||||
|
@ -187,6 +188,7 @@ ErrorOr<void> decode(Decoder& decoder, Core::AnonymousBuffer& buffer)
|
|||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder& decoder, Core::DateTime& datetime)
|
||||
{
|
||||
i64 timestamp;
|
||||
|
@ -195,6 +197,7 @@ ErrorOr<void> decode(Decoder& decoder, Core::DateTime& datetime)
|
|||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder& decoder, Core::ProxyData& data)
|
||||
{
|
||||
UnderlyingType<decltype(data.type)> type;
|
||||
|
|
|
@ -196,6 +196,7 @@ Encoder& Encoder::operator<<(File const& file)
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool encode(Encoder& encoder, Core::AnonymousBuffer const& buffer)
|
||||
{
|
||||
encoder << buffer.is_valid();
|
||||
|
@ -206,12 +207,14 @@ bool encode(Encoder& encoder, Core::AnonymousBuffer const& buffer)
|
|||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool encode(Encoder& encoder, Core::DateTime const& datetime)
|
||||
{
|
||||
encoder << static_cast<i64>(datetime.timestamp());
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool encode(Encoder& encoder, Core::ProxyData const& proxy)
|
||||
{
|
||||
encoder << to_underlying(proxy.type);
|
||||
|
|
|
@ -38,6 +38,7 @@ SameSite same_site_from_string(StringView same_site_mode)
|
|||
|
||||
}
|
||||
|
||||
template<>
|
||||
bool IPC::encode(Encoder& encoder, Web::Cookie::Cookie const& cookie)
|
||||
{
|
||||
encoder << cookie.name;
|
||||
|
@ -56,6 +57,7 @@ bool IPC::encode(Encoder& encoder, Web::Cookie::Cookie const& cookie)
|
|||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> IPC::decode(Decoder& decoder, Web::Cookie::Cookie& cookie)
|
||||
{
|
||||
TRY(decoder.decode(cookie.name));
|
||||
|
|
|
@ -46,7 +46,10 @@ SameSite same_site_from_string(StringView same_site_mode);
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Web::Cookie::Cookie const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Web::Cookie::Cookie&);
|
||||
|
||||
}
|
||||
|
|
|
@ -347,6 +347,7 @@ Optional<Core::DateTime> parse_date_time(StringView date_string)
|
|||
|
||||
}
|
||||
|
||||
template<>
|
||||
bool IPC::encode(Encoder& encoder, Web::Cookie::ParsedCookie const& cookie)
|
||||
{
|
||||
encoder << cookie.name;
|
||||
|
@ -362,6 +363,7 @@ bool IPC::encode(Encoder& encoder, Web::Cookie::ParsedCookie const& cookie)
|
|||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> IPC::decode(Decoder& decoder, Web::Cookie::ParsedCookie& cookie)
|
||||
{
|
||||
TRY(decoder.decode(cookie.name));
|
||||
|
|
|
@ -32,7 +32,10 @@ Optional<ParsedCookie> parse_cookie(String const& cookie_string);
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Web::Cookie::ParsedCookie const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Web::Cookie::ParsedCookie&);
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ Response::Response(Error&& error)
|
|||
|
||||
}
|
||||
|
||||
template<>
|
||||
bool IPC::encode(Encoder& encoder, Web::WebDriver::Response const& response)
|
||||
{
|
||||
response.visit(
|
||||
|
@ -46,6 +47,7 @@ bool IPC::encode(Encoder& encoder, Web::WebDriver::Response const& response)
|
|||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> IPC::decode(Decoder& decoder, Web::WebDriver::Response& response)
|
||||
{
|
||||
ResponseType type {};
|
||||
|
|
|
@ -46,7 +46,10 @@ private:
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, Web::WebDriver::Response const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, Web::WebDriver::Response&);
|
||||
|
||||
}
|
||||
|
|
|
@ -73,9 +73,16 @@ public:
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, WindowServer::ScreenLayout::Screen const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, WindowServer::ScreenLayout::Screen&);
|
||||
|
||||
template<>
|
||||
bool encode(Encoder&, WindowServer::ScreenLayout const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder&, WindowServer::ScreenLayout&);
|
||||
|
||||
}
|
||||
|
|
|
@ -394,12 +394,14 @@ bool ScreenLayout::try_auto_add_display_connector(String const& device_path)
|
|||
|
||||
namespace IPC {
|
||||
|
||||
bool encode(Encoder& encoder, const WindowServer::ScreenLayout::Screen& screen)
|
||||
template<>
|
||||
bool encode(Encoder& encoder, WindowServer::ScreenLayout::Screen const& screen)
|
||||
{
|
||||
encoder << screen.mode << screen.device << screen.location << screen.resolution << screen.scale_factor;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder& decoder, WindowServer::ScreenLayout::Screen& screen)
|
||||
{
|
||||
WindowServer::ScreenLayout::Screen::Mode mode;
|
||||
|
@ -416,12 +418,14 @@ ErrorOr<void> decode(Decoder& decoder, WindowServer::ScreenLayout::Screen& scree
|
|||
return {};
|
||||
}
|
||||
|
||||
bool encode(Encoder& encoder, const WindowServer::ScreenLayout& screen_layout)
|
||||
template<>
|
||||
bool encode(Encoder& encoder, WindowServer::ScreenLayout const& screen_layout)
|
||||
{
|
||||
encoder << screen_layout.screens << screen_layout.main_screen_index;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> decode(Decoder& decoder, WindowServer::ScreenLayout& screen_layout)
|
||||
{
|
||||
Vector<WindowServer::ScreenLayout::Screen> screens;
|
||||
|
|
Loading…
Reference in a new issue