diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h index d08176f676289..3ea6406b69a37 100644 --- a/orc-rt/include/orc-rt/SPSWrapperFunction.h +++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h @@ -20,9 +20,9 @@ namespace orc_rt { namespace detail { -template struct WFSPSSerializer { +template struct WFSPSHelper { template - std::optional operator()(const ArgTs &...Args) { + std::optional serialize(const ArgTs &...Args) { auto R = WrapperFunctionBuffer::allocate(SPSArgList::size(Args...)); SPSOutputBuffer OB(R.data(), R.size()); @@ -30,15 +30,17 @@ template struct WFSPSSerializer { return std::nullopt; return std::move(R); } -}; -template struct WFSPSDeserializer { - template - bool operator()(WrapperFunctionBuffer &ArgBytes, ArgTs &...Args) { + template + std::optional deserialize(WrapperFunctionBuffer ArgBytes) { assert(!ArgBytes.getOutOfBandError() && "Should not attempt to deserialize out-of-band error"); SPSInputBuffer IB(ArgBytes.data(), ArgBytes.size()); - return SPSArgList::deserialize(IB, Args...); + ArgTuple Args; + if (!SPSSerializationTraits, ArgTuple>::deserialize( + IB, Args)) + return std::nullopt; + return Args; } }; @@ -48,19 +50,8 @@ template struct WrapperFunctionSPSSerializer; template struct WrapperFunctionSPSSerializer { - static detail::WFSPSSerializer argumentSerializer() noexcept { - return {}; - } - static detail::WFSPSDeserializer - argumentDeserializer() noexcept { - return {}; - } - static detail::WFSPSSerializer resultSerializer() noexcept { - return {}; - } - static detail::WFSPSDeserializer resultDeserializer() noexcept { - return {}; - } + static detail::WFSPSHelper arguments() noexcept { return {}; } + static detail::WFSPSHelper result() noexcept { return {}; } }; /// Provides call and handle utilities to simplify writing and invocation of diff --git a/orc-rt/include/orc-rt/WrapperFunction.h b/orc-rt/include/orc-rt/WrapperFunction.h index 41960d24de04e..233c3b21e041d 100644 --- a/orc-rt/include/orc-rt/WrapperFunction.h +++ b/orc-rt/include/orc-rt/WrapperFunction.h @@ -139,7 +139,7 @@ class StructuredYield, Serializer> public: using StructuredYieldBase::StructuredYieldBase; void operator()(RetT &&R) { - if (auto ResultBytes = this->S.resultSerializer()(std::forward(R))) + if (auto ResultBytes = this->S.result().serialize(std::forward(R))) this->Return(this->Session, this->CallCtx, ResultBytes->release()); else this->Return(this->Session, this->CallCtx, @@ -166,9 +166,9 @@ template struct ResultDeserializer>, Serializer> { static Expected deserialize(WrapperFunctionBuffer ResultBytes, Serializer &S) { - T Val; - if (S.resultDeserializer()(ResultBytes, Val)) - return std::move(Val); + if (auto Val = S.result().template deserialize>( + std::move(ResultBytes))) + return std::move(std::get<0>(*Val)); else return make_error("Could not deserialize result"); } @@ -205,7 +205,7 @@ struct WrapperFunction { "Result-handler should have exactly one argument"); typedef typename ResultHandlerTraits::args_tuple_type ResultTupleType; - if (auto ArgBytes = S.argumentSerializer()(std::forward(Args)...)) { + if (auto ArgBytes = S.arguments().serialize(std::forward(Args)...)) { C( [RH = std::move(RH), S = std::move(S)](orc_rt_SessionRef Session, @@ -241,13 +241,12 @@ struct WrapperFunction { if (ArgBytes.getOutOfBandError()) return Return(Session, CallCtx, ArgBytes.release()); - ArgTuple Args; - if (std::apply(bind_front(S.argumentDeserializer(), std::move(ArgBytes)), - Args)) + if (auto Args = + S.arguments().template deserialize(std::move(ArgBytes))) std::apply(bind_front(std::forward(H), detail::StructuredYield( Session, CallCtx, Return, std::move(S))), - std::move(Args)); + std::move(*Args)); else Return(Session, CallCtx, WrapperFunctionBuffer::createOutOfBandError(