Commit 075992dc authored by Dominik Charousset's avatar Dominik Charousset

Use lightweight error code whenever possible

parent 55153b94
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
virtual error save(serializer& sink) const = 0; virtual error save(serializer& sink) const = 0;
/// Serialize this group to `sink`. /// Serialize this group to `sink`.
virtual error save(binary_serializer& sink) const = 0; virtual error_code<sec> save(binary_serializer& sink) const = 0;
/// Subscribes `who` to this group and returns `true` on success /// Subscribes `who` to this group and returns `true` on success
/// or `false` if `who` is already subscribed. /// or `false` if `who` is already subscribed.
......
...@@ -183,10 +183,10 @@ inline bool operator!=(const abstract_actor* x, const strong_actor_ptr& y) { ...@@ -183,10 +183,10 @@ inline bool operator!=(const abstract_actor* x, const strong_actor_ptr& y) {
/// @relates actor_control_block /// @relates actor_control_block
using weak_actor_ptr = weak_intrusive_ptr<actor_control_block>; using weak_actor_ptr = weak_intrusive_ptr<actor_control_block>;
error load_actor(strong_actor_ptr& storage, execution_unit*, error_code<sec> load_actor(strong_actor_ptr& storage, execution_unit*,
actor_id aid, const node_id& nid); actor_id aid, const node_id& nid);
error save_actor(strong_actor_ptr& storage, execution_unit*, error_code<sec> save_actor(strong_actor_ptr& storage, execution_unit*,
actor_id aid, const node_id& nid); actor_id aid, const node_id& nid);
template <class Inspector> template <class Inspector>
...@@ -225,7 +225,7 @@ template <class Inspector> ...@@ -225,7 +225,7 @@ template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, weak_actor_ptr& x) { typename Inspector::result_type inspect(Inspector& f, weak_actor_ptr& x) {
// inspect as strong pointer, then write back to weak pointer on save // inspect as strong pointer, then write back to weak pointer on save
auto tmp = x.lock(); auto tmp = x.lock();
auto load = [&]() -> error { x.reset(tmp.get()); return none; }; auto load = [&] { x.reset(tmp.get()); };
return f(tmp, meta::load_callback(load)); return f(tmp, meta::load_callback(load));
} }
......
...@@ -37,9 +37,7 @@ class binary_deserializer : public write_inspector<binary_deserializer> { ...@@ -37,9 +37,7 @@ class binary_deserializer : public write_inspector<binary_deserializer> {
public: public:
// -- member types ----------------------------------------------------------- // -- member types -----------------------------------------------------------
using result_type = error; using result_type = error_code<sec>;
using apply_result = error_code<sec>;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
...@@ -91,58 +89,58 @@ public: ...@@ -91,58 +89,58 @@ public:
// -- overridden member functions -------------------------------------------- // -- overridden member functions --------------------------------------------
apply_result begin_object(uint16_t& typenr, std::string& name); result_type begin_object(uint16_t& typenr, std::string& name);
apply_result end_object() noexcept; result_type end_object() noexcept;
apply_result begin_sequence(size_t& list_size) noexcept; result_type begin_sequence(size_t& list_size) noexcept;
apply_result end_sequence() noexcept; result_type end_sequence() noexcept;
apply_result apply(bool&) noexcept; result_type apply(bool&) noexcept;
apply_result apply(byte&) noexcept; result_type apply(byte&) noexcept;
apply_result apply(int8_t&) noexcept; result_type apply(int8_t&) noexcept;
apply_result apply(uint8_t&) noexcept; result_type apply(uint8_t&) noexcept;
apply_result apply(int16_t&) noexcept; result_type apply(int16_t&) noexcept;
apply_result apply(uint16_t&) noexcept; result_type apply(uint16_t&) noexcept;
apply_result apply(int32_t&) noexcept; result_type apply(int32_t&) noexcept;
apply_result apply(uint32_t&) noexcept; result_type apply(uint32_t&) noexcept;
apply_result apply(int64_t&) noexcept; result_type apply(int64_t&) noexcept;
apply_result apply(uint64_t&) noexcept; result_type apply(uint64_t&) noexcept;
apply_result apply(float&) noexcept; result_type apply(float&) noexcept;
apply_result apply(double&) noexcept; result_type apply(double&) noexcept;
apply_result apply(long double&); result_type apply(long double&);
apply_result apply(timespan& x) noexcept; result_type apply(timespan& x) noexcept;
apply_result apply(timestamp& x) noexcept; result_type apply(timestamp& x) noexcept;
apply_result apply(span<byte>) noexcept; result_type apply(span<byte>) noexcept;
apply_result apply(std::string&); result_type apply(std::string&);
apply_result apply(std::u16string&); result_type apply(std::u16string&);
apply_result apply(std::u32string&); result_type apply(std::u32string&);
template <class Enum, class = std::enable_if_t<std::is_enum<Enum>::value>> template <class Enum, class = std::enable_if_t<std::is_enum<Enum>::value>>
auto apply(Enum& x) noexcept { auto apply(Enum& x) noexcept {
return apply(reinterpret_cast<std::underlying_type_t<Enum>&>(x)); return apply(reinterpret_cast<std::underlying_type_t<Enum>&>(x));
} }
apply_result apply(std::vector<bool>& xs); result_type apply(std::vector<bool>& xs);
private: private:
explicit binary_deserializer(actor_system& sys) noexcept; explicit binary_deserializer(actor_system& sys) noexcept;
......
...@@ -40,7 +40,7 @@ class binary_serializer : public read_inspector<binary_serializer> { ...@@ -40,7 +40,7 @@ class binary_serializer : public read_inspector<binary_serializer> {
public: public:
// -- member types ----------------------------------------------------------- // -- member types -----------------------------------------------------------
using result_type = error; using result_type = error_code<sec>;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
......
...@@ -36,24 +36,31 @@ namespace caf { ...@@ -36,24 +36,31 @@ namespace caf {
/// requires a heap allocation. With the callback implementation of CAF, /// requires a heap allocation. With the callback implementation of CAF,
/// the object remains on the stack and does not cause more overhead /// the object remains on the stack and does not cause more overhead
/// than necessary. /// than necessary.
template <class... Ts> template <class Signature>
class callback { class callback;
template <class Result, class... Ts>
class callback<Result(Ts...)> {
public: public:
virtual error operator()(Ts...) = 0; virtual Result operator()(Ts...) = 0;
}; };
/// Utility class for wrapping a function object of type `Base`. /// Utility class for wrapping a function object of type `Base`.
template <class F, class... Ts> template <class F, class Signature>
class callback_impl : public callback<Ts...> { class callback_impl;
template <class F, class Result, class... Ts>
class callback_impl<F, Result(Ts...)> : public callback<Result(Ts...)> {
public: public:
callback_impl(F&& f) : f_(std::move(f)) { callback_impl(F&& f) : f_(std::move(f)) {
// nop // nop
} }
callback_impl(callback_impl&&) = default; callback_impl(callback_impl&&) = default;
callback_impl& operator=(callback_impl&&) = default; callback_impl& operator=(callback_impl&&) = default;
error operator()(Ts... xs) override { Result operator()(Ts... xs) override {
return f_(std::forward<Ts>(xs)...); return f_(std::forward<Ts>(xs)...);
} }
...@@ -61,24 +68,14 @@ private: ...@@ -61,24 +68,14 @@ private:
F f_; F f_;
}; };
/// Utility class for selecting a `callback_impl`.
template <class F,
class Args = typename detail::get_callable_trait<F>::arg_types>
struct select_callback;
template <class F, class... Ts>
struct select_callback<F, detail::type_list<Ts...>> {
using type = callback_impl<F, Ts...>;
};
/// Creates a callback from a lambda expression. /// Creates a callback from a lambda expression.
/// @relates callback /// @relates callback
template <class F> template <class F>
typename select_callback<F>::type make_callback(F fun) { auto make_callback(F fun) {
return {std::move(fun)}; using signature = typename detail::get_callable_trait<F>::fun_sig;
return callback_impl<F, signature>{std::move(fun)};
} }
} // namespace caf } // namespace caf
CAF_POP_WARNINGS CAF_POP_WARNINGS
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
error load(size_t pos, deserializer& source) override; error load(size_t pos, deserializer& source) override;
error load(size_t pos, binary_deserializer& source) override; error_code<sec> load(size_t pos, binary_deserializer& source) override;
// -- overridden observers of type_erased_tuple ------------------------------ // -- overridden observers of type_erased_tuple ------------------------------
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
error save(size_t pos, serializer& sink) const override; error save(size_t pos, serializer& sink) const override;
error save(size_t pos, binary_serializer& sink) const override; error_code<sec> save(size_t pos, binary_serializer& sink) const override;
// -- modifiers -------------------------------------------------------------- // -- modifiers --------------------------------------------------------------
......
...@@ -138,7 +138,7 @@ public: ...@@ -138,7 +138,7 @@ public:
return dispatch(pos, source); return dispatch(pos, source);
} }
error load(size_t pos, binary_deserializer& source) override { error_code<sec> load(size_t pos, binary_deserializer& source) override {
return dispatch(pos, source); return dispatch(pos, source);
} }
...@@ -154,7 +154,7 @@ public: ...@@ -154,7 +154,7 @@ public:
return mptr()->dispatch(pos, sink); return mptr()->dispatch(pos, sink);
} }
error save(size_t pos, binary_serializer& sink) const override { error_code<sec> save(size_t pos, binary_serializer& sink) const override {
return mptr()->dispatch(pos, sink); return mptr()->dispatch(pos, sink);
} }
......
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
return ptrs_[pos]->load(source); return ptrs_[pos]->load(source);
} }
error load(size_t pos, binary_deserializer& source) override { error_code<sec> load(size_t pos, binary_deserializer& source) override {
return ptrs_[pos]->load(source); return ptrs_[pos]->load(source);
} }
...@@ -104,7 +104,7 @@ public: ...@@ -104,7 +104,7 @@ public:
return ptrs_[pos]->save(sink); return ptrs_[pos]->save(sink);
} }
error save(size_t pos, binary_serializer& sink) const override { error_code<sec> save(size_t pos, binary_serializer& sink) const override {
return ptrs_[pos]->save(sink); return ptrs_[pos]->save(sink);
} }
......
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
return source(*addr_of(x_)); return source(*addr_of(x_));
} }
error load(binary_deserializer& source) override { error_code<sec> load(binary_deserializer& source) override {
return source(*addr_of(x_)); return source(*addr_of(x_));
} }
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
return sink(*addr_of(const_cast<T&>(x_))); return sink(*addr_of(const_cast<T&>(x_)));
} }
error save(binary_serializer& sink) const override { error_code<sec> save(binary_serializer& sink) const override {
return sink(*addr_of(const_cast<T&>(x_))); return sink(*addr_of(const_cast<T&>(x_)));
} }
......
...@@ -92,11 +92,10 @@ private: ...@@ -92,11 +92,10 @@ private:
/// @relates uri_impl /// @relates uri_impl
template <class Inspector> template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, uri_impl& x) { typename Inspector::result_type inspect(Inspector& f, uri_impl& x) {
auto load = [&]() -> error { auto load = [&] {
x.str.clear(); x.str.clear();
if (x.valid()) if (x.valid())
x.assemble_str(); x.assemble_str();
return none;
}; };
return f(x.scheme, x.authority, x.path, x.query, x.fragment, return f(x.scheme, x.authority, x.path, x.query, x.fragment,
meta::load_callback(load)); meta::load_callback(load));
......
...@@ -195,17 +195,40 @@ public: ...@@ -195,17 +195,40 @@ public:
// -- friend functions ------------------------------------------------------- // -- friend functions -------------------------------------------------------
template <class Inspector> template <class Inspector>
friend typename Inspector::result_type inspect(Inspector& f, error& x) { friend auto inspect(Inspector& f, error& x) {
auto fun = [&](meta::type_name_t x0, uint8_t& x1, atom_value& x2, using result_type = typename Inspector::result_type;
meta::omittable_if_empty_t x3, if constexpr (Inspector::reads_state) {
message& x4) -> error { return f(x0, x1, x2, x3, x4); }; if (!x) {
return x.apply(fun); uint8_t code = 0;
return f(code);
}
return f(x.code(), x.category(), x.context());
} else {
uint8_t code = 0;
auto cb = meta::load_callback([&] {
if (code == 0) {
x.clear();
if constexpr (std::is_same<result_type, void>::value)
return;
else
return result_type{};
}
x.init();
x.code_ref() = code;
return f(x.category_ref(), x.context());
});
return f(code, cb);
}
} }
private: private:
// -- inspection support ----------------------------------------------------- // -- inspection support -----------------------------------------------------
error apply(const inspect_fun& f); uint8_t& code_ref() noexcept;
atom_value& category_ref() noexcept;
void init();
// -- nested classes --------------------------------------------------------- // -- nested classes ---------------------------------------------------------
......
...@@ -82,11 +82,11 @@ public: ...@@ -82,11 +82,11 @@ public:
friend error inspect(serializer&, group&); friend error inspect(serializer&, group&);
friend error inspect(binary_serializer&, group&); friend error_code<sec> inspect(binary_serializer&, group&);
friend error inspect(deserializer&, group&); friend error inspect(deserializer&, group&);
friend error inspect(binary_deserializer&, group&); friend error_code<sec> inspect(binary_deserializer&, group&);
abstract_group* get() const noexcept { abstract_group* get() const noexcept {
return ptr_.get(); return ptr_.get();
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
virtual error load(deserializer& source, group& storage) = 0; virtual error load(deserializer& source, group& storage) = 0;
/// Loads a group of this module from `source` and stores it in `storage`. /// Loads a group of this module from `source` and stores it in `storage`.
virtual error load(binary_deserializer& source, group& storage) = 0; virtual error_code<sec> load(binary_deserializer& source, group& storage) = 0;
// -- observers -------------------------------------------------------------- // -- observers --------------------------------------------------------------
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
error load(size_t pos, deserializer& source) override; error load(size_t pos, deserializer& source) override;
error load(size_t pos, binary_deserializer& source) override; error_code<sec> load(size_t pos, binary_deserializer& source) override;
size_t size() const noexcept override; size_t size() const noexcept override;
...@@ -89,17 +89,17 @@ public: ...@@ -89,17 +89,17 @@ public:
error save(size_t pos, serializer& sink) const override; error save(size_t pos, serializer& sink) const override;
error save(size_t pos, binary_serializer& sink) const override; error_code<sec> save(size_t pos, binary_serializer& sink) const override;
bool shared() const noexcept override; bool shared() const noexcept override;
error load(deserializer& source) override; error load(deserializer& source) override;
error load(binary_deserializer& source) override; error_code<sec> load(binary_deserializer& source) override;
error save(serializer& sink) const override; error save(serializer& sink) const override;
error save(binary_serializer& sink) const override; error_code<sec> save(binary_serializer& sink) const override;
// -- factories -------------------------------------------------------------- // -- factories --------------------------------------------------------------
...@@ -165,7 +165,8 @@ public: ...@@ -165,7 +165,8 @@ public:
/// even if the serialized object had a different type. /// even if the serialized object had a different type.
static error save(serializer& sink, const type_erased_tuple& x); static error save(serializer& sink, const type_erased_tuple& x);
static error save(binary_serializer& sink, const type_erased_tuple& x); static error_code<sec>
save(binary_serializer& sink, const type_erased_tuple& x);
/// @endcond /// @endcond
...@@ -199,13 +200,13 @@ private: ...@@ -199,13 +200,13 @@ private:
error inspect(serializer& sink, message& msg); error inspect(serializer& sink, message& msg);
/// @relates message /// @relates message
error inspect(binary_serializer& sink, message& msg); error_code<sec> inspect(binary_serializer& sink, message& msg);
/// @relates message /// @relates message
error inspect(deserializer& source, message& msg); error inspect(deserializer& source, message& msg);
/// @relates message /// @relates message
error inspect(binary_deserializer& source, message& msg); error_code<sec> inspect(binary_deserializer& source, message& msg);
/// @relates message /// @relates message
std::string to_string(const message& msg); std::string to_string(const message& msg);
......
...@@ -57,9 +57,9 @@ public: ...@@ -57,9 +57,9 @@ public:
virtual error deserialize(deserializer& source) = 0; virtual error deserialize(deserializer& source) = 0;
virtual error serialize(binary_serializer& sink) const = 0; virtual error_code<sec> serialize(binary_serializer& sink) const = 0;
virtual error deserialize(binary_deserializer& source) = 0; virtual error_code<sec> deserialize(binary_deserializer& source) = 0;
}; };
// A technology-agnostic node identifier with process ID and hash value. // A technology-agnostic node identifier with process ID and hash value.
...@@ -119,9 +119,9 @@ public: ...@@ -119,9 +119,9 @@ public:
error deserialize(deserializer& source) override; error deserialize(deserializer& source) override;
error serialize(binary_serializer& sink) const override; error_code<sec> serialize(binary_serializer& sink) const override;
error deserialize(binary_deserializer& source) override; error_code<sec> deserialize(binary_deserializer& source) override;
private: private:
// -- member variables ----------------------------------------------------- // -- member variables -----------------------------------------------------
...@@ -167,9 +167,9 @@ public: ...@@ -167,9 +167,9 @@ public:
error deserialize(deserializer& source) override; error deserialize(deserializer& source) override;
error serialize(binary_serializer& sink) const override; error_code<sec> serialize(binary_serializer& sink) const override;
error deserialize(binary_deserializer& source) override; error_code<sec> deserialize(binary_deserializer& source) override;
private: private:
// -- member variables ----------------------------------------------------- // -- member variables -----------------------------------------------------
...@@ -232,11 +232,11 @@ public: ...@@ -232,11 +232,11 @@ public:
friend error inspect(serializer& sink, node_id& x); friend error inspect(serializer& sink, node_id& x);
friend error inspect(binary_serializer& sink, node_id& x); friend error_code<sec> inspect(binary_serializer& sink, node_id& x);
friend error inspect(deserializer& source, node_id& x); friend error inspect(deserializer& source, node_id& x);
friend error inspect(binary_deserializer& source, node_id& x); friend error_code<sec> inspect(binary_deserializer& source, node_id& x);
private: private:
intrusive_ptr<data> data_; intrusive_ptr<data> data_;
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
virtual error load(size_t pos, deserializer& source) = 0; virtual error load(size_t pos, deserializer& source) = 0;
/// Load the content for the element at position `pos` from `source`. /// Load the content for the element at position `pos` from `source`.
virtual error load(size_t pos, binary_deserializer& source) = 0; virtual error_code<sec> load(size_t pos, binary_deserializer& source) = 0;
// -- modifiers -------------------------------------------------------------- // -- modifiers --------------------------------------------------------------
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
virtual error load(deserializer& source); virtual error load(deserializer& source);
/// Load the content for the tuple from `source`. /// Load the content for the tuple from `source`.
virtual error load(binary_deserializer& source); virtual error_code<sec> load(binary_deserializer& source);
// -- pure virtual observers ------------------------------------------------- // -- pure virtual observers -------------------------------------------------
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
virtual error save(size_t pos, serializer& sink) const = 0; virtual error save(size_t pos, serializer& sink) const = 0;
/// Saves the element at position `pos` to `sink`. /// Saves the element at position `pos` to `sink`.
virtual error save(size_t pos, binary_serializer& sink) const = 0; virtual error_code<sec> save(size_t pos, binary_serializer& sink) const = 0;
// -- observers -------------------------------------------------------------- // -- observers --------------------------------------------------------------
...@@ -107,7 +107,7 @@ public: ...@@ -107,7 +107,7 @@ public:
virtual error save(serializer& sink) const; virtual error save(serializer& sink) const;
/// Saves the content of the tuple to `sink`. /// Saves the content of the tuple to `sink`.
virtual error save(binary_serializer& sink) const; virtual error_code<sec> save(binary_serializer& sink) const;
/// Checks whether the type of the stored value at position `pos` /// Checks whether the type of the stored value at position `pos`
/// matches type number `n` and run-time type information `p`. /// matches type number `n` and run-time type information `p`.
...@@ -231,22 +231,22 @@ private: ...@@ -231,22 +231,22 @@ private:
}; };
/// @relates type_erased_tuple /// @relates type_erased_tuple
inline error inspect(serializer& sink, const type_erased_tuple& x) { inline auto inspect(serializer& sink, const type_erased_tuple& x) {
return x.save(sink); return x.save(sink);
} }
/// @relates type_erased_tuple /// @relates type_erased_tuple
inline error inspect(binary_serializer& sink, const type_erased_tuple& x) { inline auto inspect(binary_serializer& sink, const type_erased_tuple& x) {
return x.save(sink); return x.save(sink);
} }
/// @relates type_erased_tuple /// @relates type_erased_tuple
inline error inspect(deserializer& source, type_erased_tuple& x) { inline auto inspect(deserializer& source, type_erased_tuple& x) {
return x.load(source); return x.load(source);
} }
/// @relates type_erased_tuple /// @relates type_erased_tuple
inline error inspect(binary_deserializer& source, type_erased_tuple& x) { inline auto inspect(binary_deserializer& source, type_erased_tuple& x) {
return x.load(source); return x.load(source);
} }
...@@ -267,7 +267,7 @@ public: ...@@ -267,7 +267,7 @@ public:
error load(size_t pos, deserializer& source) override; error load(size_t pos, deserializer& source) override;
error load(size_t pos, binary_deserializer& source) override; error_code<sec> load(size_t pos, binary_deserializer& source) override;
size_t size() const noexcept override; size_t size() const noexcept override;
...@@ -283,7 +283,7 @@ public: ...@@ -283,7 +283,7 @@ public:
error save(size_t pos, serializer& sink) const override; error save(size_t pos, serializer& sink) const override;
error save(size_t pos, binary_serializer& sink) const override; error_code<sec> save(size_t pos, binary_serializer& sink) const override;
}; };
} // namespace caf } // namespace caf
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
virtual error load(deserializer& source) = 0; virtual error load(deserializer& source) = 0;
/// Load the content for the stored value from `source`. /// Load the content for the stored value from `source`.
virtual error load(binary_deserializer& source) = 0; virtual error_code<sec> load(binary_deserializer& source) = 0;
// -- pure virtual observers ------------------------------------------------- // -- pure virtual observers -------------------------------------------------
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
virtual error save(serializer& sink) const = 0; virtual error save(serializer& sink) const = 0;
/// Saves the content of the stored value to `sink`. /// Saves the content of the stored value to `sink`.
virtual error save(binary_serializer& sink) const = 0; virtual error_code<sec> save(binary_serializer& sink) const = 0;
/// Converts the stored value to a string. /// Converts the stored value to a string.
virtual std::string stringify() const = 0; virtual std::string stringify() const = 0;
...@@ -99,27 +99,27 @@ public: ...@@ -99,27 +99,27 @@ public:
}; };
/// @relates type_erased_value_impl /// @relates type_erased_value_impl
inline error inspect(serializer& f, type_erased_value& x) { inline auto inspect(serializer& f, type_erased_value& x) {
return x.save(f); return x.save(f);
} }
/// @relates type_erased_value_impl /// @relates type_erased_value_impl
inline error inspect(binary_serializer& f, type_erased_value& x) { inline auto inspect(binary_serializer& f, type_erased_value& x) {
return x.save(f); return x.save(f);
} }
/// @relates type_erased_value_impl /// @relates type_erased_value_impl
inline error inspect(deserializer& f, type_erased_value& x) { inline auto inspect(deserializer& f, type_erased_value& x) {
return x.load(f); return x.load(f);
} }
/// @relates type_erased_value_impl /// @relates type_erased_value_impl
inline error inspect(binary_deserializer& f, type_erased_value& x) { inline auto inspect(binary_deserializer& f, type_erased_value& x) {
return x.load(f); return x.load(f);
} }
/// @relates type_erased_value_impl /// @relates type_erased_value_impl
inline std::string to_string(const type_erased_value& x) { inline auto to_string(const type_erased_value& x) {
return x.stringify(); return x.stringify();
} }
......
...@@ -123,11 +123,11 @@ public: ...@@ -123,11 +123,11 @@ public:
friend error inspect(caf::serializer& dst, uri& x); friend error inspect(caf::serializer& dst, uri& x);
friend error inspect(caf::binary_serializer& dst, uri& x); friend error_code<sec> inspect(caf::binary_serializer& dst, uri& x);
friend error inspect(caf::deserializer& src, uri& x); friend error inspect(caf::deserializer& src, uri& x);
friend error inspect(caf::binary_deserializer& src, uri& x); friend error_code<sec> inspect(caf::binary_deserializer& src, uri& x);
private: private:
impl_ptr impl_; impl_ptr impl_;
......
...@@ -80,7 +80,7 @@ bool operator==(const abstract_actor* x, const strong_actor_ptr& y) { ...@@ -80,7 +80,7 @@ bool operator==(const abstract_actor* x, const strong_actor_ptr& y) {
return actor_control_block::from(x) == y.get(); return actor_control_block::from(x) == y.get();
} }
error load_actor(strong_actor_ptr& storage, execution_unit* ctx, error_code<sec> load_actor(strong_actor_ptr& storage, execution_unit* ctx,
actor_id aid, const node_id& nid) { actor_id aid, const node_id& nid) {
if (ctx == nullptr) if (ctx == nullptr)
return sec::no_context; return sec::no_context;
...@@ -99,7 +99,7 @@ error load_actor(strong_actor_ptr& storage, execution_unit* ctx, ...@@ -99,7 +99,7 @@ error load_actor(strong_actor_ptr& storage, execution_unit* ctx,
return none; return none;
} }
error save_actor(strong_actor_ptr& storage, execution_unit* ctx, error_code<sec> save_actor(strong_actor_ptr& storage, execution_unit* ctx,
actor_id aid, const node_id& nid) { actor_id aid, const node_id& nid) {
if (ctx == nullptr) if (ctx == nullptr)
return sec::no_context; return sec::no_context;
......
...@@ -32,10 +32,10 @@ namespace caf { ...@@ -32,10 +32,10 @@ namespace caf {
namespace { namespace {
using apply_result = binary_deserializer::apply_result; using result_type = binary_deserializer::result_type;
template <class T> template <class T>
apply_result apply_int(binary_deserializer& source, T& x) { result_type apply_int(binary_deserializer& source, T& x) {
auto tmp = std::make_unsigned_t<T>{}; auto tmp = std::make_unsigned_t<T>{};
if (auto err = source.apply(as_writable_bytes(make_span(&tmp, 1)))) if (auto err = source.apply(as_writable_bytes(make_span(&tmp, 1))))
return err; return err;
...@@ -44,7 +44,7 @@ apply_result apply_int(binary_deserializer& source, T& x) { ...@@ -44,7 +44,7 @@ apply_result apply_int(binary_deserializer& source, T& x) {
} }
template <class T> template <class T>
apply_result apply_float(binary_deserializer& source, T& x) { result_type apply_float(binary_deserializer& source, T& x) {
auto tmp = typename detail::ieee_754_trait<T>::packed_type{}; auto tmp = typename detail::ieee_754_trait<T>::packed_type{};
if (auto err = apply_int(source, tmp)) if (auto err = apply_int(source, tmp))
return err; return err;
...@@ -68,7 +68,7 @@ binary_deserializer::binary_deserializer(actor_system& sys) noexcept ...@@ -68,7 +68,7 @@ binary_deserializer::binary_deserializer(actor_system& sys) noexcept
// nop // nop
} }
apply_result binary_deserializer::begin_object(uint16_t& nr, std::string& name) { result_type binary_deserializer::begin_object(uint16_t& nr, std::string& name) {
name.clear(); name.clear();
if (auto err = apply(nr)) if (auto err = apply(nr))
return err; return err;
...@@ -78,11 +78,11 @@ apply_result binary_deserializer::begin_object(uint16_t& nr, std::string& name) ...@@ -78,11 +78,11 @@ apply_result binary_deserializer::begin_object(uint16_t& nr, std::string& name)
return none; return none;
} }
apply_result binary_deserializer::end_object() noexcept { result_type binary_deserializer::end_object() noexcept {
return none; return none;
} }
apply_result binary_deserializer::begin_sequence(size_t& list_size) noexcept { result_type binary_deserializer::begin_sequence(size_t& list_size) noexcept {
// Use varbyte encoding to compress sequence size on the wire. // Use varbyte encoding to compress sequence size on the wire.
uint32_t x = 0; uint32_t x = 0;
int n = 0; int n = 0;
...@@ -97,7 +97,7 @@ apply_result binary_deserializer::begin_sequence(size_t& list_size) noexcept { ...@@ -97,7 +97,7 @@ apply_result binary_deserializer::begin_sequence(size_t& list_size) noexcept {
return none; return none;
} }
apply_result binary_deserializer::end_sequence() noexcept { result_type binary_deserializer::end_sequence() noexcept {
return none; return none;
} }
...@@ -111,7 +111,7 @@ void binary_deserializer::reset(span<const byte> bytes) noexcept { ...@@ -111,7 +111,7 @@ void binary_deserializer::reset(span<const byte> bytes) noexcept {
end_ = current_ + bytes.size(); end_ = current_ + bytes.size();
} }
apply_result binary_deserializer::apply(bool& x) noexcept { result_type binary_deserializer::apply(bool& x) noexcept {
int8_t tmp = 0; int8_t tmp = 0;
if (auto err = apply(tmp)) if (auto err = apply(tmp))
return err; return err;
...@@ -119,7 +119,7 @@ apply_result binary_deserializer::apply(bool& x) noexcept { ...@@ -119,7 +119,7 @@ apply_result binary_deserializer::apply(bool& x) noexcept {
return none; return none;
} }
apply_result binary_deserializer::apply(byte& x) noexcept { result_type binary_deserializer::apply(byte& x) noexcept {
if (range_check(1)) { if (range_check(1)) {
x = *current_++; x = *current_++;
return none; return none;
...@@ -127,7 +127,7 @@ apply_result binary_deserializer::apply(byte& x) noexcept { ...@@ -127,7 +127,7 @@ apply_result binary_deserializer::apply(byte& x) noexcept {
return sec::end_of_stream; return sec::end_of_stream;
} }
apply_result binary_deserializer::apply(int8_t& x) noexcept { result_type binary_deserializer::apply(int8_t& x) noexcept {
if (range_check(1)) { if (range_check(1)) {
x = static_cast<int8_t>(*current_++); x = static_cast<int8_t>(*current_++);
return none; return none;
...@@ -135,7 +135,7 @@ apply_result binary_deserializer::apply(int8_t& x) noexcept { ...@@ -135,7 +135,7 @@ apply_result binary_deserializer::apply(int8_t& x) noexcept {
return sec::end_of_stream; return sec::end_of_stream;
} }
apply_result binary_deserializer::apply(uint8_t& x) noexcept { result_type binary_deserializer::apply(uint8_t& x) noexcept {
if (range_check(1)) { if (range_check(1)) {
x = static_cast<uint8_t>(*current_++); x = static_cast<uint8_t>(*current_++);
return none; return none;
...@@ -143,39 +143,39 @@ apply_result binary_deserializer::apply(uint8_t& x) noexcept { ...@@ -143,39 +143,39 @@ apply_result binary_deserializer::apply(uint8_t& x) noexcept {
return sec::end_of_stream; return sec::end_of_stream;
} }
apply_result binary_deserializer::apply(int16_t& x) noexcept { result_type binary_deserializer::apply(int16_t& x) noexcept {
return apply_int(*this, x); return apply_int(*this, x);
} }
apply_result binary_deserializer::apply(uint16_t& x) noexcept { result_type binary_deserializer::apply(uint16_t& x) noexcept {
return apply_int(*this, x); return apply_int(*this, x);
} }
apply_result binary_deserializer::apply(int32_t& x) noexcept { result_type binary_deserializer::apply(int32_t& x) noexcept {
return apply_int(*this, x); return apply_int(*this, x);
} }
apply_result binary_deserializer::apply(uint32_t& x) noexcept { result_type binary_deserializer::apply(uint32_t& x) noexcept {
return apply_int(*this, x); return apply_int(*this, x);
} }
apply_result binary_deserializer::apply(int64_t& x) noexcept { result_type binary_deserializer::apply(int64_t& x) noexcept {
return apply_int(*this, x); return apply_int(*this, x);
} }
apply_result binary_deserializer::apply(uint64_t& x) noexcept { result_type binary_deserializer::apply(uint64_t& x) noexcept {
return apply_int(*this, x); return apply_int(*this, x);
} }
apply_result binary_deserializer::apply(float& x) noexcept { result_type binary_deserializer::apply(float& x) noexcept {
return apply_float(*this, x); return apply_float(*this, x);
} }
apply_result binary_deserializer::apply(double& x) noexcept { result_type binary_deserializer::apply(double& x) noexcept {
return apply_float(*this, x); return apply_float(*this, x);
} }
apply_result binary_deserializer::apply(long double& x) { result_type binary_deserializer::apply(long double& x) {
// TODO: Our IEEE-754 conversion currently does not work for long double. The // TODO: Our IEEE-754 conversion currently does not work for long double. The
// standard does not guarantee a fixed representation for this type, but // standard does not guarantee a fixed representation for this type, but
// on X86 we can usually rely on 80-bit precision. For now, we fall back // on X86 we can usually rely on 80-bit precision. For now, we fall back
...@@ -189,7 +189,7 @@ apply_result binary_deserializer::apply(long double& x) { ...@@ -189,7 +189,7 @@ apply_result binary_deserializer::apply(long double& x) {
return sec::invalid_argument; return sec::invalid_argument;
} }
apply_result binary_deserializer::apply(timespan& x) noexcept { result_type binary_deserializer::apply(timespan& x) noexcept {
int64_t tmp = 0; int64_t tmp = 0;
if (auto err = apply(tmp)) if (auto err = apply(tmp))
return err; return err;
...@@ -197,7 +197,7 @@ apply_result binary_deserializer::apply(timespan& x) noexcept { ...@@ -197,7 +197,7 @@ apply_result binary_deserializer::apply(timespan& x) noexcept {
return none; return none;
} }
apply_result binary_deserializer::apply(timestamp& x) noexcept { result_type binary_deserializer::apply(timestamp& x) noexcept {
int64_t tmp = 0; int64_t tmp = 0;
if (auto err = apply(tmp)) if (auto err = apply(tmp))
return err; return err;
...@@ -205,7 +205,7 @@ apply_result binary_deserializer::apply(timestamp& x) noexcept { ...@@ -205,7 +205,7 @@ apply_result binary_deserializer::apply(timestamp& x) noexcept {
return none; return none;
} }
apply_result binary_deserializer::apply(span<byte> x) noexcept { result_type binary_deserializer::apply(span<byte> x) noexcept {
if (!range_check(x.size())) if (!range_check(x.size()))
return sec::end_of_stream; return sec::end_of_stream;
memcpy(x.data(), current_, x.size()); memcpy(x.data(), current_, x.size());
...@@ -213,7 +213,7 @@ apply_result binary_deserializer::apply(span<byte> x) noexcept { ...@@ -213,7 +213,7 @@ apply_result binary_deserializer::apply(span<byte> x) noexcept {
return none; return none;
} }
apply_result binary_deserializer::apply(std::string& x) { result_type binary_deserializer::apply(std::string& x) {
x.clear(); x.clear();
size_t str_size = 0; size_t str_size = 0;
if (auto err = begin_sequence(str_size)) if (auto err = begin_sequence(str_size))
...@@ -225,7 +225,7 @@ apply_result binary_deserializer::apply(std::string& x) { ...@@ -225,7 +225,7 @@ apply_result binary_deserializer::apply(std::string& x) {
return end_sequence(); return end_sequence();
} }
apply_result binary_deserializer::apply(std::u16string& x) { result_type binary_deserializer::apply(std::u16string& x) {
x.clear(); x.clear();
size_t str_size = 0; size_t str_size = 0;
if (auto err = begin_sequence(str_size)) if (auto err = begin_sequence(str_size))
...@@ -240,7 +240,7 @@ apply_result binary_deserializer::apply(std::u16string& x) { ...@@ -240,7 +240,7 @@ apply_result binary_deserializer::apply(std::u16string& x) {
return end_sequence(); return end_sequence();
} }
apply_result binary_deserializer::apply(std::u32string& x) { result_type binary_deserializer::apply(std::u32string& x) {
x.clear(); x.clear();
size_t str_size = 0; size_t str_size = 0;
if (auto err = begin_sequence(str_size)) if (auto err = begin_sequence(str_size))
...@@ -256,7 +256,7 @@ apply_result binary_deserializer::apply(std::u32string& x) { ...@@ -256,7 +256,7 @@ apply_result binary_deserializer::apply(std::u32string& x) {
return end_sequence(); return end_sequence();
} }
apply_result binary_deserializer::apply(std::vector<bool>& x) { result_type binary_deserializer::apply(std::vector<bool>& x) {
x.clear(); x.clear();
size_t len = 0; size_t len = 0;
if (auto err = begin_sequence(len)) if (auto err = begin_sequence(len))
......
...@@ -60,7 +60,8 @@ error dynamic_message_data::load(size_t pos, deserializer& source) { ...@@ -60,7 +60,8 @@ error dynamic_message_data::load(size_t pos, deserializer& source) {
return elements_[pos]->load(source); return elements_[pos]->load(source);
} }
error dynamic_message_data::load(size_t pos, binary_deserializer& source) { error_code<sec>
dynamic_message_data::load(size_t pos, binary_deserializer& source) {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return elements_[pos]->load(source); return elements_[pos]->load(source);
} }
...@@ -98,7 +99,8 @@ error dynamic_message_data::save(size_t pos, serializer& sink) const { ...@@ -98,7 +99,8 @@ error dynamic_message_data::save(size_t pos, serializer& sink) const {
return elements_[pos]->save(sink); return elements_[pos]->save(sink);
} }
error dynamic_message_data::save(size_t pos, binary_serializer& sink) const { error_code<sec>
dynamic_message_data::save(size_t pos, binary_serializer& sink) const {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return elements_[pos]->save(sink); return elements_[pos]->save(sink);
} }
......
...@@ -153,16 +153,19 @@ void error::clear() noexcept { ...@@ -153,16 +153,19 @@ void error::clear() noexcept {
// -- inspection support ----------------------------------------------------- // -- inspection support -----------------------------------------------------
error error::apply(const inspect_fun& f) { uint8_t& error::code_ref() noexcept {
data tmp{0, atom(""), message{}}; CAF_ASSERT(data_ != nullptr);
data& ref = data_ != nullptr ? *data_ : tmp; return data_->code;
auto result = f(meta::type_name("error"), ref.code, ref.category, }
meta::omittable_if_empty(), ref.context);
if (ref.code == 0) atom_value& error::category_ref() noexcept {
clear(); CAF_ASSERT(data_ != nullptr);
else if (&tmp == &ref) return data_->category;
data_ = new data(std::move(tmp)); }
return result;
void error::init() {
if (data_ == nullptr)
data_ = new data;
} }
std::string to_string(const error& x) { std::string to_string(const error& x) {
......
...@@ -74,7 +74,7 @@ error inspect(serializer& sink, group& x) { ...@@ -74,7 +74,7 @@ error inspect(serializer& sink, group& x) {
return save_group(sink, x); return save_group(sink, x);
} }
error inspect(binary_serializer& sink, group& x) { error_code<sec> inspect(binary_serializer& sink, group& x) {
return save_group(sink, x); return save_group(sink, x);
} }
...@@ -104,7 +104,7 @@ error inspect(deserializer& source, group& x) { ...@@ -104,7 +104,7 @@ error inspect(deserializer& source, group& x) {
return load_group(source, x); return load_group(source, x);
} }
error inspect(binary_deserializer& source, group& x) { error_code<sec> inspect(binary_deserializer& source, group& x) {
return load_group(source, x); return load_group(source, x);
} }
......
...@@ -111,7 +111,7 @@ public: ...@@ -111,7 +111,7 @@ public:
error save(serializer& sink) const override; error save(serializer& sink) const override;
error save(binary_serializer& sink) const override; error_code<sec> save(binary_serializer& sink) const override;
void stop() override { void stop() override {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
...@@ -350,16 +350,15 @@ public: ...@@ -350,16 +350,15 @@ public:
return group{result}; return group{result};
} }
template <class Deserializer> template <class Deserializer>
error load_impl(Deserializer& source, group& storage) { typename Deserializer::result_type
load_impl(Deserializer& source, group& storage) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
// deserialize identifier and broker // deserialize identifier and broker
std::string identifier; std::string identifier;
strong_actor_ptr broker_ptr; strong_actor_ptr broker_ptr;
auto e = source(identifier, broker_ptr); if (auto err = source(identifier, broker_ptr))
if (e) return err;
return e;
CAF_LOG_DEBUG(CAF_ARG(identifier) << CAF_ARG(broker_ptr)); CAF_LOG_DEBUG(CAF_ARG(identifier) << CAF_ARG(broker_ptr));
if (!broker_ptr) { if (!broker_ptr) {
storage = invalid_group; storage = invalid_group;
...@@ -390,7 +389,7 @@ public: ...@@ -390,7 +389,7 @@ public:
return load_impl(source, storage); return load_impl(source, storage);
} }
error load(binary_deserializer& source, group& storage) override { error_code<sec> load(binary_deserializer& source, group& storage) override {
return load_impl(source, storage); return load_impl(source, storage);
} }
...@@ -407,7 +406,7 @@ public: ...@@ -407,7 +406,7 @@ public:
return save_impl(ptr, sink); return save_impl(ptr, sink);
} }
error save(const local_group* ptr, binary_serializer& sink) const { error_code<sec> save(const local_group* ptr, binary_serializer& sink) const {
return save_impl(ptr, sink); return save_impl(ptr, sink);
} }
...@@ -452,7 +451,7 @@ error local_group::save(serializer& sink) const { ...@@ -452,7 +451,7 @@ error local_group::save(serializer& sink) const {
return static_cast<local_group_module&>(parent_).save(this, sink); return static_cast<local_group_module&>(parent_).save(this, sink);
} }
error local_group::save(binary_serializer& sink) const { error_code<sec> local_group::save(binary_serializer& sink) const {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
return static_cast<local_group_module&>(parent_).save(this, sink); return static_cast<local_group_module&>(parent_).save(this, sink);
} }
......
...@@ -66,7 +66,7 @@ error message::load(size_t pos, deserializer& source) { ...@@ -66,7 +66,7 @@ error message::load(size_t pos, deserializer& source) {
return vals_.unshared().load(pos, source); return vals_.unshared().load(pos, source);
} }
error message::load(size_t pos, binary_deserializer& source) { error_code<sec> message::load(size_t pos, binary_deserializer& source) {
CAF_ASSERT(vals_ != nullptr); CAF_ASSERT(vals_ != nullptr);
return vals_.unshared().load(pos, source); return vals_.unshared().load(pos, source);
} }
...@@ -104,7 +104,7 @@ error message::save(size_t pos, serializer& sink) const { ...@@ -104,7 +104,7 @@ error message::save(size_t pos, serializer& sink) const {
return vals_->save(pos, sink); return vals_->save(pos, sink);
} }
error message::save(size_t pos, binary_serializer& sink) const { error_code<sec> message::save(size_t pos, binary_serializer& sink) const {
CAF_ASSERT(vals_ != nullptr); CAF_ASSERT(vals_ != nullptr);
return vals_->save(pos, sink); return vals_->save(pos, sink);
} }
...@@ -116,7 +116,8 @@ bool message::shared() const noexcept { ...@@ -116,7 +116,8 @@ bool message::shared() const noexcept {
namespace { namespace {
template <class Deserializer> template <class Deserializer>
error load_vals(Deserializer& source, message::data_ptr& vals) { typename Deserializer::result_type
load_vals(Deserializer& source, message::data_ptr& vals) {
if (source.context() == nullptr) if (source.context() == nullptr)
return sec::no_context; return sec::no_context;
uint16_t zero = 0; uint16_t zero = 0;
...@@ -146,7 +147,10 @@ error load_vals(Deserializer& source, message::data_ptr& vals) { ...@@ -146,7 +147,10 @@ error load_vals(Deserializer& source, message::data_ptr& vals) {
tmp.assign(i, n); tmp.assign(i, n);
auto ptr = types.make_value(tmp); auto ptr = types.make_value(tmp);
if (!ptr) if (!ptr)
return make_error(sec::unknown_type, make_message(std::move(tmp))); {
CAF_LOG_ERROR("unknown type:" << tmp);
return sec::unknown_type;
}
if (auto err = ptr->load(source)) if (auto err = ptr->load(source))
return err; return err;
dmd->append(std::move(ptr)); dmd->append(std::move(ptr));
...@@ -167,14 +171,15 @@ error message::load(deserializer& source) { ...@@ -167,14 +171,15 @@ error message::load(deserializer& source) {
return load_vals(source, vals_); return load_vals(source, vals_);
} }
error message::load(binary_deserializer& source) { error_code<sec> message::load(binary_deserializer& source) {
return load_vals(source, vals_); return load_vals(source, vals_);
} }
namespace { namespace {
template <class Serializer> template <class Serializer>
error save_tuple(Serializer& sink, const type_erased_tuple& x) { typename Serializer::result_type
save_tuple(Serializer& sink, const type_erased_tuple& x) {
if (sink.context() == nullptr) if (sink.context() == nullptr)
return sec::no_context; return sec::no_context;
// build type name // build type name
...@@ -196,9 +201,7 @@ error save_tuple(Serializer& sink, const type_erased_tuple& x) { ...@@ -196,9 +201,7 @@ error save_tuple(Serializer& sink, const type_erased_tuple& x) {
<< (rtti.second != nullptr ? rtti.second->name() << (rtti.second != nullptr ? rtti.second->name()
: "-not-available-") : "-not-available-")
<< std::endl; << std::endl;
return make_error(sec::unknown_type, make_message(rtti.second != nullptr return sec::unknown_type;
? rtti.second->name()
: "-not-available-"));
} }
tname += '+'; tname += '+';
tname += portable_name; tname += portable_name;
...@@ -217,7 +220,8 @@ error message::save(serializer& sink, const type_erased_tuple& x) { ...@@ -217,7 +220,8 @@ error message::save(serializer& sink, const type_erased_tuple& x) {
return save_tuple(sink, x); return save_tuple(sink, x);
} }
error message::save(binary_serializer& sink, const type_erased_tuple& x) { error_code<sec>
message::save(binary_serializer& sink, const type_erased_tuple& x) {
return save_tuple(sink, x); return save_tuple(sink, x);
} }
...@@ -225,7 +229,7 @@ error message::save(serializer& sink) const { ...@@ -225,7 +229,7 @@ error message::save(serializer& sink) const {
return save_tuple(sink, *this); return save_tuple(sink, *this);
} }
error message::save(binary_serializer& sink) const { error_code<sec> message::save(binary_serializer& sink) const {
return save_tuple(sink, *this); return save_tuple(sink, *this);
} }
...@@ -262,11 +266,11 @@ error inspect(deserializer& source, message& msg) { ...@@ -262,11 +266,11 @@ error inspect(deserializer& source, message& msg) {
return msg.load(source); return msg.load(source);
} }
error inspect(binary_serializer& sink, message& msg) { error_code<sec> inspect(binary_serializer& sink, message& msg) {
return msg.save(sink); return msg.save(sink);
} }
error inspect(binary_deserializer& source, message& msg) { error_code<sec> inspect(binary_deserializer& source, message& msg) {
return msg.load(source); return msg.load(source);
} }
......
...@@ -138,11 +138,13 @@ error node_id::default_data::deserialize(deserializer& source) { ...@@ -138,11 +138,13 @@ error node_id::default_data::deserialize(deserializer& source) {
return source(pid_, host_); return source(pid_, host_);
} }
error node_id::default_data::serialize(binary_serializer& sink) const { error_code<sec>
node_id::default_data::serialize(binary_serializer& sink) const {
return sink(pid_, host_); return sink(pid_, host_);
} }
error node_id::default_data::deserialize(binary_deserializer& source) { error_code<sec>
node_id::default_data::deserialize(binary_deserializer& source) {
return source(pid_, host_); return source(pid_, host_);
} }
...@@ -188,11 +190,11 @@ error node_id::uri_data::deserialize(deserializer& source) { ...@@ -188,11 +190,11 @@ error node_id::uri_data::deserialize(deserializer& source) {
return source(value_); return source(value_);
} }
error node_id::uri_data::serialize(binary_serializer& sink) const { error_code<sec> node_id::uri_data::serialize(binary_serializer& sink) const {
return sink(value_); return sink(value_);
} }
error node_id::uri_data::deserialize(binary_deserializer& source) { error_code<sec> node_id::uri_data::deserialize(binary_deserializer& source) {
return source(value_); return source(value_);
} }
...@@ -228,8 +230,7 @@ void node_id::swap(node_id& x) { ...@@ -228,8 +230,7 @@ void node_id::swap(node_id& x) {
namespace { namespace {
template <class Serializer> template <class Serializer>
error serialize_data(Serializer& sink, auto serialize_data(Serializer& sink, const intrusive_ptr<node_id::data>& ptr) {
const intrusive_ptr<node_id::data>& ptr) {
if (ptr && ptr->valid()) { if (ptr && ptr->valid()) {
if (auto err = sink(ptr->implementation_id())) if (auto err = sink(ptr->implementation_id()))
return err; return err;
...@@ -239,14 +240,14 @@ error serialize_data(Serializer& sink, ...@@ -239,14 +240,14 @@ error serialize_data(Serializer& sink,
} }
template <class Deserializer> template <class Deserializer>
error deserialize_data(Deserializer& source, auto deserialize_data(Deserializer& source, intrusive_ptr<node_id::data>& ptr) {
intrusive_ptr<node_id::data>& ptr) { using result_type = typename Deserializer::result_type;
auto impl = static_cast<atom_value>(0); auto impl = static_cast<atom_value>(0);
if (auto err = source(impl)) if (auto err = source(impl))
return err; return err;
if (impl == atom("")) { if (impl == atom("")) {
ptr.reset(); ptr.reset();
return none; return result_type{};
} }
if (impl == node_id::default_data::class_id) { if (impl == node_id::default_data::class_id) {
if (ptr == nullptr if (ptr == nullptr
...@@ -259,7 +260,7 @@ error deserialize_data(Deserializer& source, ...@@ -259,7 +260,7 @@ error deserialize_data(Deserializer& source,
ptr = make_counted<node_id::uri_data>(); ptr = make_counted<node_id::uri_data>();
return ptr->deserialize(source); return ptr->deserialize(source);
} }
return sec::unknown_type; return result_type{sec::unknown_type};
} }
} // namespace } // namespace
...@@ -272,11 +273,11 @@ error inspect(deserializer& source, node_id& x) { ...@@ -272,11 +273,11 @@ error inspect(deserializer& source, node_id& x) {
return deserialize_data(source, x.data_); return deserialize_data(source, x.data_);
} }
error inspect(binary_serializer& sink, node_id& x) { error_code<sec> inspect(binary_serializer& sink, node_id& x) {
return serialize_data(sink, x.data_); return serialize_data(sink, x.data_);
} }
error inspect(binary_deserializer& source, node_id& x) { error_code<sec> inspect(binary_deserializer& source, node_id& x) {
return deserialize_data(source, x.data_); return deserialize_data(source, x.data_);
} }
......
...@@ -37,7 +37,7 @@ error type_erased_tuple::load(deserializer& source) { ...@@ -37,7 +37,7 @@ error type_erased_tuple::load(deserializer& source) {
return none; return none;
} }
error type_erased_tuple::load(binary_deserializer& source) { error_code<sec> type_erased_tuple::load(binary_deserializer& source) {
for (size_t i = 0; i < size(); ++i) for (size_t i = 0; i < size(); ++i)
if (auto err = load(i, source)) if (auto err = load(i, source))
return err; return err;
...@@ -74,7 +74,7 @@ error type_erased_tuple::save(serializer& sink) const { ...@@ -74,7 +74,7 @@ error type_erased_tuple::save(serializer& sink) const {
return none; return none;
} }
error type_erased_tuple::save(binary_serializer& sink) const { error_code<sec> type_erased_tuple::save(binary_serializer& sink) const {
for (size_t i = 0; i < size(); ++i) for (size_t i = 0; i < size(); ++i)
save(i, sink); save(i, sink);
return none; return none;
...@@ -103,7 +103,7 @@ error empty_type_erased_tuple::load(size_t, deserializer&) { ...@@ -103,7 +103,7 @@ error empty_type_erased_tuple::load(size_t, deserializer&) {
CAF_RAISE_ERROR("empty_type_erased_tuple::get_mutable"); CAF_RAISE_ERROR("empty_type_erased_tuple::get_mutable");
} }
error empty_type_erased_tuple::load(size_t, binary_deserializer&) { error_code<sec> empty_type_erased_tuple::load(size_t, binary_deserializer&) {
CAF_RAISE_ERROR("empty_type_erased_tuple::get_mutable"); CAF_RAISE_ERROR("empty_type_erased_tuple::get_mutable");
} }
...@@ -135,7 +135,8 @@ error empty_type_erased_tuple::save(size_t, serializer&) const { ...@@ -135,7 +135,8 @@ error empty_type_erased_tuple::save(size_t, serializer&) const {
CAF_RAISE_ERROR("empty_type_erased_tuple::save"); CAF_RAISE_ERROR("empty_type_erased_tuple::save");
} }
error empty_type_erased_tuple::save(size_t, binary_serializer&) const { error_code<sec>
empty_type_erased_tuple::save(size_t, binary_serializer&) const {
CAF_RAISE_ERROR("empty_type_erased_tuple::save"); CAF_RAISE_ERROR("empty_type_erased_tuple::save");
} }
......
...@@ -112,11 +112,11 @@ error inspect(caf::deserializer& src, uri& x) { ...@@ -112,11 +112,11 @@ error inspect(caf::deserializer& src, uri& x) {
return err; return err;
} }
error inspect(caf::binary_serializer& dst, uri& x) { error_code<sec> inspect(caf::binary_serializer& dst, uri& x) {
return inspect(dst, const_cast<detail::uri_impl&>(*x.impl_)); return inspect(dst, const_cast<detail::uri_impl&>(*x.impl_));
} }
error inspect(caf::binary_deserializer& src, uri& x) { error_code<sec> inspect(caf::binary_deserializer& src, uri& x) {
auto impl = make_counted<detail::uri_impl>(); auto impl = make_counted<detail::uri_impl>();
auto err = inspect(src, *impl); auto err = inspect(src, *impl);
if (err == none) if (err == none)
......
...@@ -103,10 +103,11 @@ public: ...@@ -103,10 +103,11 @@ public:
/// Describes a function object responsible for writing /// Describes a function object responsible for writing
/// the payload for a BASP message. /// the payload for a BASP message.
using payload_writer = callback<binary_serializer&>; using payload_writer = callback<error_code<sec>(binary_serializer&)>;
/// Describes a callback function object for `remove_published_actor`. /// Describes a callback function object for `remove_published_actor`.
using removed_published_actor = callback<const strong_actor_ptr&, uint16_t>; using removed_published_actor
= callback<error_code<sec>(const strong_actor_ptr&, uint16_t)>;
instance(abstract_broker* parent, callee& lstnr); instance(abstract_broker* parent, callee& lstnr);
......
...@@ -101,10 +101,10 @@ uint16_t port(const ip_endpoint& ep); ...@@ -101,10 +101,10 @@ uint16_t port(const ip_endpoint& ep);
uint32_t family(const ip_endpoint& ep); uint32_t family(const ip_endpoint& ep);
error load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h, error_code<sec> load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h,
uint16_t& p, size_t& l); uint16_t& p, size_t& l);
error save_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h, error_code<sec> save_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h,
uint16_t& p, size_t& l); uint16_t& p, size_t& l);
template <class Inspector> template <class Inspector>
......
...@@ -176,7 +176,7 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender, ...@@ -176,7 +176,7 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
mid.integer_value(), mid.integer_value(),
sender ? sender->id() : invalid_actor_id, sender ? sender->id() : invalid_actor_id,
dest_actor}; dest_actor};
auto writer = make_callback([&](binary_serializer& sink) -> error { auto writer = make_callback([&](binary_serializer& sink) { //
return sink(forwarding_stack, msg); return sink(forwarding_stack, msg);
}); });
write(ctx, callee_.get_buffer(path->hdl), hdr, &writer); write(ctx, callee_.get_buffer(path->hdl), hdr, &writer);
...@@ -187,7 +187,7 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender, ...@@ -187,7 +187,7 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
mid.integer_value(), mid.integer_value(),
sender ? sender->id() : invalid_actor_id, sender ? sender->id() : invalid_actor_id,
dest_actor}; dest_actor};
auto writer = make_callback([&](binary_serializer& sink) -> error { auto writer = make_callback([&](binary_serializer& sink) {
return sink(source_node, dest_node, forwarding_stack, msg); return sink(source_node, dest_node, forwarding_stack, msg);
}); });
write(ctx, callee_.get_buffer(path->hdl), hdr, &writer); write(ctx, callee_.get_buffer(path->hdl), hdr, &writer);
...@@ -225,7 +225,7 @@ void instance::write_server_handshake(execution_unit* ctx, byte_buffer& out_buf, ...@@ -225,7 +225,7 @@ void instance::write_server_handshake(execution_unit* ctx, byte_buffer& out_buf,
pa = &i->second; pa = &i->second;
} }
CAF_LOG_DEBUG_IF(!pa && port, "no actor published"); CAF_LOG_DEBUG_IF(!pa && port, "no actor published");
auto writer = make_callback([&](binary_serializer& sink) -> error { auto writer = make_callback([&](binary_serializer& sink) {
auto app_ids = get_or(config(), "middleman.app-identifiers", auto app_ids = get_or(config(), "middleman.app-identifiers",
defaults::middleman::app_identifiers); defaults::middleman::app_identifiers);
auto aid = invalid_actor_id; auto aid = invalid_actor_id;
...@@ -246,8 +246,9 @@ void instance::write_server_handshake(execution_unit* ctx, byte_buffer& out_buf, ...@@ -246,8 +246,9 @@ void instance::write_server_handshake(execution_unit* ctx, byte_buffer& out_buf,
} }
void instance::write_client_handshake(execution_unit* ctx, byte_buffer& buf) { void instance::write_client_handshake(execution_unit* ctx, byte_buffer& buf) {
auto writer = make_callback( auto writer = make_callback([&](binary_serializer& sink) { //
[&](binary_serializer& sink) -> error { return sink(this_node_); }); return sink(this_node_);
});
header hdr{message_type::client_handshake, header hdr{message_type::client_handshake,
0, 0,
0, 0,
...@@ -260,7 +261,7 @@ void instance::write_client_handshake(execution_unit* ctx, byte_buffer& buf) { ...@@ -260,7 +261,7 @@ void instance::write_client_handshake(execution_unit* ctx, byte_buffer& buf) {
void instance::write_monitor_message(execution_unit* ctx, byte_buffer& buf, void instance::write_monitor_message(execution_unit* ctx, byte_buffer& buf,
const node_id& dest_node, actor_id aid) { const node_id& dest_node, actor_id aid) {
CAF_LOG_TRACE(CAF_ARG(dest_node) << CAF_ARG(aid)); CAF_LOG_TRACE(CAF_ARG(dest_node) << CAF_ARG(aid));
auto writer = make_callback([&](binary_serializer& sink) -> error { auto writer = make_callback([&](binary_serializer& sink) { //
return sink(this_node_, dest_node); return sink(this_node_, dest_node);
}); });
header hdr{message_type::monitor_message, 0, 0, 0, invalid_actor_id, aid}; header hdr{message_type::monitor_message, 0, 0, 0, invalid_actor_id, aid};
...@@ -271,7 +272,7 @@ void instance::write_down_message(execution_unit* ctx, byte_buffer& buf, ...@@ -271,7 +272,7 @@ void instance::write_down_message(execution_unit* ctx, byte_buffer& buf,
const node_id& dest_node, actor_id aid, const node_id& dest_node, actor_id aid,
const error& rsn) { const error& rsn) {
CAF_LOG_TRACE(CAF_ARG(dest_node) << CAF_ARG(aid) << CAF_ARG(rsn)); CAF_LOG_TRACE(CAF_ARG(dest_node) << CAF_ARG(aid) << CAF_ARG(rsn));
auto writer = make_callback([&](binary_serializer& sink) -> error { auto writer = make_callback([&](binary_serializer& sink) { //
return sink(this_node_, dest_node, rsn); return sink(this_node_, dest_node, rsn);
}); });
header hdr{message_type::down_message, 0, 0, 0, aid, invalid_actor_id}; header hdr{message_type::down_message, 0, 0, 0, aid, invalid_actor_id};
......
...@@ -295,10 +295,9 @@ behavior basp_broker::make_behavior() { ...@@ -295,10 +295,9 @@ behavior basp_broker::make_behavior() {
}, },
[=](unpublish_atom, const actor_addr& whom, uint16_t port) -> result<void> { [=](unpublish_atom, const actor_addr& whom, uint16_t port) -> result<void> {
CAF_LOG_TRACE(CAF_ARG(whom) << CAF_ARG(port)); CAF_LOG_TRACE(CAF_ARG(whom) << CAF_ARG(port));
auto cb = make_callback( auto cb = make_callback([&](const strong_actor_ptr&, uint16_t x) {
[&](const strong_actor_ptr&, uint16_t x) -> error {
close(hdl_by_port(x)); close(hdl_by_port(x));
return none; return error_code<sec>{};
}); });
if (instance.remove_published_actor(whom, port, &cb) == 0) if (instance.remove_published_actor(whom, port, &cb) == 0)
return sec::no_actor_published_at_port; return sec::no_actor_published_at_port;
......
...@@ -366,7 +366,7 @@ void middleman::init(actor_system_config& cfg) { ...@@ -366,7 +366,7 @@ void middleman::init(actor_system_config& cfg) {
return sec::no_such_group_module; return sec::no_such_group_module;
} }
error load(binary_deserializer&, group&) override { error_code<sec> load(binary_deserializer&, group&) override {
// never called, because we hand out group instances of the local module // never called, because we hand out group instances of the local module
return sec::no_such_group_module; return sec::no_such_group_module;
} }
......
...@@ -206,8 +206,8 @@ uint32_t family(const ip_endpoint& ep) { ...@@ -206,8 +206,8 @@ uint32_t family(const ip_endpoint& ep) {
return ep.caddress()->sa_family; return ep.caddress()->sa_family;
} }
error load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h, uint16_t& p, error_code<sec> load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h,
size_t& l) { uint16_t& p, size_t& l) {
ep.clear(); ep.clear();
if (l > 0) { if (l > 0) {
*ep.length() = l; *ep.length() = l;
...@@ -233,8 +233,8 @@ error load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h, uint16_t& p, ...@@ -233,8 +233,8 @@ error load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h, uint16_t& p,
return none; return none;
} }
error save_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h, uint16_t& p, error_code<sec> save_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h,
size_t& l) { uint16_t& p, size_t& l) {
if (*ep.length() > 0) { if (*ep.length() > 0) {
f = family(ep); f = family(ep);
h = host(ep); h = host(ep);
......
...@@ -229,10 +229,10 @@ public: ...@@ -229,10 +229,10 @@ public:
template <class T, class... Ts> template <class T, class... Ts>
void to_buf(byte_buffer& buf, basp::header& hdr, payload_writer* writer, void to_buf(byte_buffer& buf, basp::header& hdr, payload_writer* writer,
const T& x, const Ts&... xs) { const T& x, const Ts&... xs) {
auto pw = make_callback([&](binary_serializer& sink) -> error { auto pw = make_callback([&](binary_serializer& sink) {
if (writer) if (writer)
return error::eval([&] { return (*writer)(sink); }, if (auto err = (*writer)(sink))
[&] { return sink(const_cast<T&>(x)); }); return err;
return sink(const_cast<T&>(x)); return sink(const_cast<T&>(x));
}); });
to_buf(buf, hdr, &pw, xs...); to_buf(buf, hdr, &pw, xs...);
......
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