actor-framework
Public Types | Public Member Functions | Protected Attributes | List of all members
caf::deserializer Class Referenceabstract

Technology-independent deserialization interface. More...

#include <deserializer.hpp>

Inheritance diagram for caf::deserializer:
Inheritance graph
[legend]
Collaboration diagram for caf::deserializer:
Collaboration graph
[legend]

Public Types

using super = load_inspector_base< deserializer >
 
- Public Types inherited from caf::load_inspector_base< deserializer >
using super = load_inspector
 

Public Member Functions

 deserializer (actor_system &sys) noexcept
 
actor_systemcontext () const noexcept
 
bool has_human_readable_format () const noexcept
 
virtual bool fetch_next_object_type (type_id_t &type)=0
 Reads run-time-type information for the next object if available.
 
virtual bool fetch_next_object_name (std::string_view &type_name)
 Reads run-time-type information for the next object if available. More...
 
bool next_object_name_matches (std::string_view type_name)
 Convenience function for querying fetch_next_object_name comparing the result to type_name in one shot. More...
 
bool assert_next_object_name (std::string_view type_name)
 Like next_object_name_matches, but sets an error on the deserializer on a mismatch. More...
 
virtual bool begin_object (type_id_t type, std::string_view pretty_class_name)=0
 Begins processing of an object, may perform a type check depending on the data format. More...
 
virtual bool end_object ()=0
 Ends processing of an object.
 
virtual bool begin_field (std::string_view name)=0
 
virtual bool begin_field (std::string_view, bool &is_present)=0
 
virtual bool begin_field (std::string_view name, span< const type_id_t > types, size_t &index)=0
 
virtual bool begin_field (std::string_view name, bool &is_present, span< const type_id_t > types, size_t &index)=0
 
virtual bool end_field ()=0
 
virtual bool begin_tuple (size_t size)=0
 Begins processing of a fixed-size sequence.
 
virtual bool end_tuple ()=0
 Ends processing of a sequence.
 
virtual bool begin_key_value_pair ()
 Begins processing of a tuple with two elements, whereas the first element represents the key in an associative array. More...
 
virtual bool end_key_value_pair ()
 Ends processing of a key-value pair after both values were written. More...
 
virtual bool begin_sequence (size_t &size)=0
 Begins processing of a sequence.
 
virtual bool end_sequence ()=0
 Ends processing of a sequence.
 
virtual bool begin_associative_array (size_t &size)
 Begins processing of an associative array (map). More...
 
virtual bool end_associative_array ()
 Ends processing of an associative array (map). More...
 
virtual bool value (std::byte &x)=0
 Reads x from the input. More...
 
virtual bool value (bool &x)=0
 Reads x from the input. More...
 
virtual bool value (int8_t &)=0
 Reads x from the input. More...
 
virtual bool value (uint8_t &)=0
 Reads x from the input. More...
 
virtual bool value (int16_t &)=0
 Reads x from the input. More...
 
virtual bool value (uint16_t &)=0
 Reads x from the input. More...
 
virtual bool value (int32_t &)=0
 Reads x from the input. More...
 
virtual bool value (uint32_t &)=0
 Reads x from the input. More...
 
virtual bool value (int64_t &)=0
 Reads x from the input. More...
 
virtual bool value (uint64_t &)=0
 Reads x from the input. More...
 
template<class T >
std::enable_if_t< std::is_integral_v< T >, bool > value (T &x) noexcept
 Reads x from the input. More...
 
virtual bool value (float &)=0
 Reads x from the input. More...
 
virtual bool value (double &)=0
 Reads x from the input. More...
 
virtual bool value (long double &)=0
 Reads x from the input. More...
 
virtual bool value (std::string &)=0
 Reads x from the input. More...
 
virtual bool value (std::u16string &)=0
 Reads x from the input. More...
 
virtual bool value (std::u32string &)=0
 Reads x from the input. More...
 
virtual bool value (span< std::byte > x)=0
 Reads a byte sequence from the input. More...
 
virtual bool list (std::vector< bool > &xs)
 Adds each boolean in xs to the output. More...
 
- Public Member Functions inherited from caf::load_inspector_base< deserializer >
constexpr auto object (T &) noexcept
 
constexpr auto virtual_object (std::string_view type_name) noexcept
 
bool begin_object_t ()
 
bool list (T &xs)
 
bool map (T &xs)
 
bool tuple (T &xs, std::index_sequence< Is... >)
 
bool tuple (T &xs)
 
bool tuple (T(&xs)[N])
 
bool apply (T &x)
 
bool apply (Get &&get, Set &&set)
 Deserializes a primitive value with getter / setter access.
 
- Public Member Functions inherited from caf::load_inspector
void set_error (error stop_reason)
 
template<class... Ts>
void emplace_error (Ts &&... xs)
 
const errorget_error () const noexcept
 
error && move_error () noexcept
 
template<class... Ts>
void field_invariant_check_failed (std::string msg)
 
template<class... Ts>
void field_value_synchronization_failed (std::string msg)
 
template<class... Ts>
void invalid_field_type (std::string msg)
 

Protected Attributes

actor_systemcontext_ = nullptr
 Provides access to the ::proxy_registry and to the ::actor_system.
 
bool has_human_readable_format_ = false
 Configures whether client code should assume human-readable output.
 
- Protected Attributes inherited from caf::load_inspector
error err_
 

Additional Inherited Members

- Static Public Member Functions inherited from caf::load_inspector
template<class T >
static auto field (std::string_view name, T &x)
 
template<class Get , class Set >
static auto field (std::string_view name, Get get, Set set)
 
template<class IsPresent , class Get , class Reset , class Set >
static auto field (std::string_view name, IsPresent &&, Get &&get, Reset reset, Set set)
 
- Static Public Attributes inherited from caf::load_inspector
static constexpr bool is_loading = true
 Enables dispatching on the inspector type.
 

Detailed Description

Technology-independent deserialization interface.

Member Function Documentation

◆ assert_next_object_name()

bool caf::deserializer::assert_next_object_name ( std::string_view  type_name)

Like next_object_name_matches, but sets an error on the deserializer on a mismatch.

◆ begin_associative_array()

bool caf::deserializer::begin_associative_array ( size_t &  size)
virtual

Begins processing of an associative array (map).

Note
the default implementation calls begin_sequence(size).

Reimplemented in caf::json_reader, and caf::config_value_reader.

◆ begin_key_value_pair()

bool caf::deserializer::begin_key_value_pair ( )
virtual

Begins processing of a tuple with two elements, whereas the first element represents the key in an associative array.

Note
the default implementation calls begin_tuple(2).

Reimplemented in caf::json_reader, and caf::config_value_reader.

◆ begin_object()

virtual bool caf::deserializer::begin_object ( type_id_t  type,
std::string_view  pretty_class_name 
)
pure virtual

Begins processing of an object, may perform a type check depending on the data format.

Parameters
type16-bit ID for known types, invalid_type_id otherwise.
pretty_class_nameEither the output of type_name_or_anonymous or the optionally defined pretty name.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ end_associative_array()

bool caf::deserializer::end_associative_array ( )
virtual

Ends processing of an associative array (map).

Note
the default implementation calls end_sequence().

Reimplemented in caf::json_reader, and caf::config_value_reader.

◆ end_key_value_pair()

bool caf::deserializer::end_key_value_pair ( )
virtual

Ends processing of a key-value pair after both values were written.

Note
the default implementation calls end_tuple().

Reimplemented in caf::json_reader, and caf::config_value_reader.

◆ fetch_next_object_name()

bool caf::deserializer::fetch_next_object_name ( std::string_view &  type_name)
virtual

Reads run-time-type information for the next object if available.

The default implementation calls fetch_next_object_type and queries the CAF type name. However, implementations of the interface may retrieve the type name differently and the type name may not correspond to any type known to CAF. For example. the json_reader returns the content of the @type field of the current object if available.

Warning
the characters in type_name may point to an internal buffer that becomes invalid as soon as calling any other member function on the deserializer. Convert the type_name to a string before storing it.

Reimplemented in caf::json_reader.

◆ list()

bool caf::deserializer::list ( std::vector< bool > &  xs)
virtual

Adds each boolean in xs to the output.

Derived classes can override this member function to pack the booleans, for example to avoid using one byte for each value in a binary output format.

◆ next_object_name_matches()

bool caf::deserializer::next_object_name_matches ( std::string_view  type_name)

Convenience function for querying fetch_next_object_name comparing the result to type_name in one shot.

◆ value() [1/18]

virtual bool caf::deserializer::value ( std::byte &  x)
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [2/18]

virtual bool caf::deserializer::value ( bool &  x)
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [3/18]

virtual bool caf::deserializer::value ( int8_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [4/18]

virtual bool caf::deserializer::value ( uint8_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [5/18]

virtual bool caf::deserializer::value ( int16_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [6/18]

virtual bool caf::deserializer::value ( uint16_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [7/18]

virtual bool caf::deserializer::value ( int32_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [8/18]

virtual bool caf::deserializer::value ( uint32_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [9/18]

virtual bool caf::deserializer::value ( int64_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [10/18]

virtual bool caf::deserializer::value ( uint64_t &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [11/18]

template<class T >
std::enable_if_t<std::is_integral_v<T>, bool> caf::deserializer::value ( T &  x)
inlinenoexcept

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

◆ value() [12/18]

virtual bool caf::deserializer::value ( float &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [13/18]

virtual bool caf::deserializer::value ( double &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [14/18]

virtual bool caf::deserializer::value ( long double &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [15/18]

virtual bool caf::deserializer::value ( std::string &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [16/18]

virtual bool caf::deserializer::value ( std::u16string &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [17/18]

virtual bool caf::deserializer::value ( std::u32string &  )
pure virtual

Reads x from the input.

Parameters
xA reference to a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.

◆ value() [18/18]

virtual bool caf::deserializer::value ( span< std::byte >  x)
pure virtual

Reads a byte sequence from the input.

Parameters
xThe byte sequence.
Returns
A non-zero error code on failure, sec::success otherwise.

Implemented in caf::json_reader, and caf::config_value_reader.


The documentation for this class was generated from the following files: