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

LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>

This allows us to use TRY() in decoding helpers, leading to a nice
reduction in line count.
This commit is contained in:
Andreas Kling 2021-11-28 11:56:31 +01:00
parent 8d76eb773f
commit cb9cac4e40
21 changed files with 207 additions and 296 deletions

View file

@ -383,22 +383,18 @@ bool encode(Encoder& encoder, const WindowServer::ScreenLayout::Screen& screen)
return true;
}
bool decode(Decoder& decoder, WindowServer::ScreenLayout::Screen& screen)
ErrorOr<void> decode(Decoder& decoder, WindowServer::ScreenLayout::Screen& screen)
{
String device;
if (!decoder.decode(device))
return false;
TRY(decoder.decode(device));
Gfx::IntPoint location;
if (!decoder.decode(location))
return false;
TRY(decoder.decode(location));
Gfx::IntSize resolution;
if (!decoder.decode(resolution))
return false;
TRY(decoder.decode(resolution));
int scale_factor = 0;
if (!decoder.decode(scale_factor))
return false;
TRY(decoder.decode(scale_factor));
screen = { device, location, resolution, scale_factor };
return true;
return {};
}
bool encode(Encoder& encoder, const WindowServer::ScreenLayout& screen_layout)
@ -407,16 +403,14 @@ bool encode(Encoder& encoder, const WindowServer::ScreenLayout& screen_layout)
return true;
}
bool decode(Decoder& decoder, WindowServer::ScreenLayout& screen_layout)
ErrorOr<void> decode(Decoder& decoder, WindowServer::ScreenLayout& screen_layout)
{
Vector<WindowServer::ScreenLayout::Screen> screens;
if (!decoder.decode(screens))
return false;
TRY(decoder.decode(screens));
unsigned main_screen_index = 0;
if (!decoder.decode(main_screen_index))
return false;
TRY(decoder.decode(main_screen_index));
screen_layout = { move(screens), main_screen_index };
return true;
return {};
}
}