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

Technology-independent serialization interface. More...

#include <serializer.hpp>

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

Public Types

using super = save_inspector_base< serializer >
 
- Public Types inherited from caf::save_inspector_base< serializer >
using super = save_inspector
 

Public Member Functions

 serializer (actor_system &sys) noexcept
 
actor_systemcontext () const noexcept
 
bool has_human_readable_format () const noexcept
 
virtual bool begin_object (type_id_t type, std::string_view name)=0
 Begins processing of an object. More...
 
virtual bool end_object ()=0
 Ends processing of an object.
 
virtual bool begin_field (std::string_view)=0
 
virtual bool begin_field (std::string_view name, 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 tuple.
 
virtual bool end_tuple ()=0
 Ends processing of a tuple.
 
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. Saves the size to the underlying storage.
 
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
 Adds x to the output. More...
 
virtual bool value (bool x)=0
 Adds x to the output. More...
 
virtual bool value (int8_t x)=0
 Adds x to the output. More...
 
virtual bool value (uint8_t x)=0
 Adds x to the output. More...
 
virtual bool value (int16_t x)=0
 Adds x to the output. More...
 
virtual bool value (uint16_t x)=0
 Adds x to the output. More...
 
virtual bool value (int32_t x)=0
 Adds x to the output. More...
 
virtual bool value (uint32_t x)=0
 Adds x to the output. More...
 
virtual bool value (int64_t x)=0
 Adds x to the output. More...
 
virtual bool value (uint64_t x)=0
 Adds x to the output. More...
 
template<class T >
std::enable_if_t< std::is_integral_v< T >, bool > value (T x)
 Adds x to the output. More...
 
virtual bool value (float x)=0
 Adds x to the output. More...
 
virtual bool value (double x)=0
 Adds x to the output. More...
 
virtual bool value (long double x)=0
 Adds x to the output. More...
 
virtual bool value (std::string_view x)=0
 Adds x to the output. More...
 
virtual bool value (const std::u16string &x)=0
 Adds x to the output. More...
 
virtual bool value (const std::u32string &x)=0
 Adds x to the output. More...
 
virtual bool value (span< const std::byte > x)=0
 Adds x as raw byte block to the output. More...
 
virtual bool list (const std::vector< bool > &xs)
 Adds each boolean in xs to the output. More...
 
- Public Member Functions inherited from caf::save_inspector_base< serializer >
constexpr auto object (T &) noexcept
 
constexpr auto virtual_object (std::string_view type_name) noexcept
 
bool begin_object_t ()
 
bool list (const T &xs)
 
bool map (const T &xs)
 
bool tuple (const T &xs, std::index_sequence< Is... >)
 
bool tuple (const T &xs)
 
bool tuple (T(&xs)[N])
 
bool apply (const T &x)
 
bool apply (Get &&get, Set &&)
 
- Public Member Functions inherited from caf::save_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::save_inspector
error err_
 

Additional Inherited Members

- Static Public Member Functions inherited from caf::save_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 &&)
 
template<class IsPresent , class Get , class... Ts>
static auto field (std::string_view name, IsPresent is_present, Get get, Ts &&...)
 
- Static Public Attributes inherited from caf::save_inspector
static constexpr bool is_loading = false
 Enables dispatching on the inspector type.
 

Detailed Description

Technology-independent serialization interface.

Member Function Documentation

◆ begin_associative_array()

bool caf::serializer::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_writer, caf::json_builder, and caf::config_value_writer.

◆ begin_key_value_pair()

bool caf::serializer::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_writer, caf::json_builder, and caf::config_value_writer.

◆ begin_object()

virtual bool caf::serializer::begin_object ( type_id_t  type,
std::string_view  name 
)
pure virtual

Begins processing of an object.

May save the type information to the underlying storage to allow a deserializer to retrieve and check the type information for data formats that provide deserialization.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ end_associative_array()

bool caf::serializer::end_associative_array ( )
virtual

Ends processing of an associative array (map).

Note
the default implementation calls end_sequence().

Reimplemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ end_key_value_pair()

bool caf::serializer::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_writer, caf::json_builder, and caf::config_value_writer.

◆ list()

bool caf::serializer::list ( const 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.

◆ value() [1/18]

virtual bool caf::serializer::value ( std::byte  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [2/18]

virtual bool caf::serializer::value ( bool  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [3/18]

virtual bool caf::serializer::value ( int8_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [4/18]

virtual bool caf::serializer::value ( uint8_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [5/18]

virtual bool caf::serializer::value ( int16_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [6/18]

virtual bool caf::serializer::value ( uint16_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [7/18]

virtual bool caf::serializer::value ( int32_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [8/18]

virtual bool caf::serializer::value ( uint32_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [9/18]

virtual bool caf::serializer::value ( int64_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [10/18]

virtual bool caf::serializer::value ( uint64_t  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [11/18]

template<class T >
std::enable_if_t<std::is_integral_v<T>, bool> caf::serializer::value ( x)
inline

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

◆ value() [12/18]

virtual bool caf::serializer::value ( float  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [13/18]

virtual bool caf::serializer::value ( double  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [14/18]

virtual bool caf::serializer::value ( long double  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [15/18]

virtual bool caf::serializer::value ( std::string_view  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [16/18]

virtual bool caf::serializer::value ( const std::u16string &  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [17/18]

virtual bool caf::serializer::value ( const std::u32string &  x)
pure virtual

Adds x to the output.

Parameters
xA value for a builtin type.
Returns
true on success, false otherwise.

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.

◆ value() [18/18]

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

Adds x as raw byte block to the output.

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

Implemented in caf::json_writer, caf::json_builder, and caf::config_value_writer.


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