Commit a42e2ddb authored by Dominik Charousset's avatar Dominik Charousset

Allow users to send non-serializable messages

parent a3424580
......@@ -213,6 +213,7 @@ public:
template <class T>
typename std::enable_if<
detail::is_iterable<T>::value
&& ! detail::has_serialize<T>::value
>::type
apply(T& xs) {
apply_sequence(dref(), xs);
......@@ -278,8 +279,7 @@ public:
template <class T>
typename std::enable_if<
! detail::is_iterable<T>::value
&& ! std::is_empty<T>::value
! std::is_empty<T>::value
&& detail::has_serialize<T>::value
>::type
apply(T& x) {
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_DETAIL_TRY_SERIALIZE_HPP
#define CAF_DETAIL_TRY_SERIALIZE_HPP
namespace caf {
namespace detail {
template <class T, class U>
auto try_serialize(T& in_or_out, U* x) -> decltype(in_or_out & *x) {
in_or_out & *x;
}
template <class T>
void try_serialize(T&, const void*) {
// nop
}
} // namespace detail
} // namespace caf
#endif // CAF_DETAIL_TRY_SERIALIZE_HPP
......@@ -25,12 +25,13 @@
#include "caf/serializer.hpp"
#include "caf/deserializer.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/detail/type_nr.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/message_data.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/detail/try_serialize.hpp"
namespace caf {
namespace detail {
......@@ -59,7 +60,7 @@ struct tup_ptr_access {
template <class T, class U>
static void serialize(size_t pos, T& tup, U& in_or_out) {
if (pos == Pos)
in_or_out & std::get<Pos>(tup);
try_serialize(in_or_out, &std::get<Pos>(tup));
else
tup_ptr_access<Pos + 1, Max>::serialize(pos, tup, in_or_out);
}
......
......@@ -393,11 +393,6 @@ make_message(V&& x, Ts&&... xs) {
typename strip_and_convert<Ts>::type
>::type...
>;
static_assert(tl_forall<stored_types, is_serializable>::value,
"at least one type is not serializable via free "
"'serialize(InOrOut&, T&, const unsigned int)' or"
"`T::sereialize(InOrOut&, const unsigned int)` "
"member function");
using storage = typename tl_apply<stored_types, tuple_vals>::type;
auto ptr = make_counted<storage>(std::forward<V>(x), std::forward<Ts>(xs)...);
return message{detail::message_data::cow_ptr{std::move(ptr)}};
......
......@@ -22,9 +22,11 @@
#include <typeinfo>
#include "caf/deep_to_string.hpp"
#include "caf/detail/type_nr.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/detail/try_serialize.hpp"
namespace caf {
......@@ -75,11 +77,11 @@ struct type_erased_value_impl : public type_erased_value {
}
void save(serializer& sink) const override {
sink & const_cast<T&>(x);
detail::try_serialize(sink, const_cast<T*>(&x));
}
void load(deserializer& source) override {
source & x;
detail::try_serialize(source, &x);
}
std::string stringify() const override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment