1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

LibIPC+Everywhere: Change IPC decoders to construct values in-place

Currently, the generated IPC decoders will default-construct the type to
be decoded, then pass that value by reference to the concrete decoder.
This, of course, requires that the type is default-constructible. This
was an issue for decoding Variants, which had to require the first type
in the Variant list is Empty, to ensure it is default constructible.

Further, this made it possible for values to become uninitialized in
user-defined decoders.

This patch makes the decoder interface such that the concrete decoders
themselves contruct the decoded type upon return from the decoder. To do
so, the default decoders in IPC::Decoder had to be moved to the IPC
namespace scope, as these decoders are now specializations instead of
overloaded methods (C++ requires specializations to be in a namespace
scope).
This commit is contained in:
Timothy Flynn 2022-12-22 20:40:33 -05:00 committed by Andreas Kling
parent 765c5b416f
commit 9b483625e6
31 changed files with 437 additions and 519 deletions

View file

@ -48,31 +48,23 @@ bool IPC::encode(Encoder& encoder, Web::WebDriver::Response const& response)
}
template<>
ErrorOr<void> IPC::decode(Decoder& decoder, Web::WebDriver::Response& response)
ErrorOr<Web::WebDriver::Response> IPC::decode(Decoder& decoder)
{
ResponseType type {};
TRY(decoder.decode(type));
auto type = TRY(decoder.decode<ResponseType>());
switch (type) {
case ResponseType::Success: {
JsonValue value;
TRY(decoder.decode(value));
response = move(value);
break;
}
case ResponseType::Success:
return TRY(decoder.decode<JsonValue>());
case ResponseType::Error: {
Web::WebDriver::Error error {};
TRY(decoder.decode(error.http_status));
TRY(decoder.decode(error.error));
TRY(decoder.decode(error.message));
TRY(decoder.decode(error.data));
auto http_status = TRY(decoder.decode<unsigned>());
auto error = TRY(decoder.decode<DeprecatedString>());
auto message = TRY(decoder.decode<DeprecatedString>());
auto data = TRY(decoder.decode<Optional<JsonValue>>());
response = move(error);
break;
return Web::WebDriver::Error { http_status, move(error), move(message), move(data) };
}
}
return {};
VERIFY_NOT_REACHED();
}