Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions orc-rt/include/orc-rt/SPSWrapperFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@
namespace orc_rt {
namespace detail {

template <typename... SPSArgTs> struct WFSPSSerializer {
template <typename... SPSArgTs> struct WFSPSHelper {
template <typename... ArgTs>
std::optional<WrapperFunctionBuffer> operator()(const ArgTs &...Args) {
std::optional<WrapperFunctionBuffer> serialize(const ArgTs &...Args) {
auto R =
WrapperFunctionBuffer::allocate(SPSArgList<SPSArgTs...>::size(Args...));
SPSOutputBuffer OB(R.data(), R.size());
if (!SPSArgList<SPSArgTs...>::serialize(OB, Args...))
return std::nullopt;
return std::move(R);
}
};

template <typename... SPSArgTs> struct WFSPSDeserializer {
template <typename... ArgTs>
bool operator()(WrapperFunctionBuffer &ArgBytes, ArgTs &...Args) {
template <typename ArgTuple>
std::optional<ArgTuple> deserialize(WrapperFunctionBuffer ArgBytes) {
assert(!ArgBytes.getOutOfBandError() &&
"Should not attempt to deserialize out-of-band error");
SPSInputBuffer IB(ArgBytes.data(), ArgBytes.size());
return SPSArgList<SPSArgTs...>::deserialize(IB, Args...);
ArgTuple Args;
if (!SPSSerializationTraits<SPSTuple<SPSArgTs...>, ArgTuple>::deserialize(
IB, Args))
return std::nullopt;
return Args;
}
};

Expand All @@ -48,19 +50,8 @@ template <typename SPSSig> struct WrapperFunctionSPSSerializer;

template <typename SPSRetT, typename... SPSArgTs>
struct WrapperFunctionSPSSerializer<SPSRetT(SPSArgTs...)> {
static detail::WFSPSSerializer<SPSArgTs...> argumentSerializer() noexcept {
return {};
}
static detail::WFSPSDeserializer<SPSArgTs...>
argumentDeserializer() noexcept {
return {};
}
static detail::WFSPSSerializer<SPSRetT> resultSerializer() noexcept {
return {};
}
static detail::WFSPSDeserializer<SPSRetT> resultDeserializer() noexcept {
return {};
}
static detail::WFSPSHelper<SPSArgTs...> arguments() noexcept { return {}; }
static detail::WFSPSHelper<SPSRetT> result() noexcept { return {}; }
};

/// Provides call and handle utilities to simplify writing and invocation of
Expand Down
17 changes: 8 additions & 9 deletions orc-rt/include/orc-rt/WrapperFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class StructuredYield<std::tuple<RetT>, Serializer>
public:
using StructuredYieldBase<Serializer>::StructuredYieldBase;
void operator()(RetT &&R) {
if (auto ResultBytes = this->S.resultSerializer()(std::forward<RetT>(R)))
if (auto ResultBytes = this->S.result().serialize(std::forward<RetT>(R)))
this->Return(this->Session, this->CallCtx, ResultBytes->release());
else
this->Return(this->Session, this->CallCtx,
Expand All @@ -166,9 +166,9 @@ template <typename T, typename Serializer>
struct ResultDeserializer<std::tuple<Expected<T>>, Serializer> {
static Expected<T> deserialize(WrapperFunctionBuffer ResultBytes,
Serializer &S) {
T Val;
if (S.resultDeserializer()(ResultBytes, Val))
return std::move(Val);
if (auto Val = S.result().template deserialize<std::tuple<T>>(
std::move(ResultBytes)))
return std::move(std::get<0>(*Val));
else
return make_error<StringError>("Could not deserialize result");
}
Expand Down Expand Up @@ -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<ArgTs>(Args)...)) {
if (auto ArgBytes = S.arguments().serialize(std::forward<ArgTs>(Args)...)) {
C(
[RH = std::move(RH),
S = std::move(S)](orc_rt_SessionRef Session,
Expand Down Expand Up @@ -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<ArgTuple>(std::move(ArgBytes)))
std::apply(bind_front(std::forward<Handler>(H),
detail::StructuredYield<RetTupleType, Serializer>(
Session, CallCtx, Return, std::move(S))),
std::move(Args));
std::move(*Args));
else
Return(Session, CallCtx,
WrapperFunctionBuffer::createOutOfBandError(
Expand Down
Loading