C++ Actor Framework 0.18
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
caf::json_reader Class Reference

Deserializes an inspectable object from a JSON-formatted string. More...

#include <json_reader.hpp>

Inheritance diagram for caf::json_reader:
caf::deserializer

Public Types

enum class  position {
  value ,
  object ,
  null ,
  key ,
  sequence ,
  members ,
  past_the_end ,
  invalid
}
 Denotes the type at the current position.
 
using super = deserializer
 
using json_key = string_view
 
using value_type = std::variant< const detail::json::value *, const detail::json::object *, detail::json::null_t, json_key, sequence, members >
 
using stack_allocator = detail::monotonic_buffer_resource::allocator< value_type >
 
using stack_type = std::vector< value_type, stack_allocator >
 
- Public Types inherited from caf::deserializer
using super = load_inspector_base< deserializer >
 

Public Member Functions

 json_reader (actor_system &sys)
 
 json_reader (execution_unit *ctx)
 
 json_reader (const json_reader &)=delete
 
json_readeroperator= (const json_reader &)=delete
 
string_view field_type_suffix () const noexcept
 Returns the suffix for generating type annotation fields for variant fields.
 
void field_type_suffix (string_view suffix) noexcept
 Configures whether the writer omits empty fields.
 
bool load (string_view json_text)
 Parses json_text into an internal representation.
 
void revert ()
 Reverts the state of the reader back to where it was after calling load.
 
void reset ()
 Removes any loaded JSON data and reclaims memory resources.
 
bool fetch_next_object_type (type_id_t &type) override
 Reads run-time-type information for the next object if available.
 
bool fetch_next_object_name (string_view &type_name) override
 Reads run-time-type information for the next object if available.
 
bool begin_object (type_id_t type, string_view name) override
 Begins processing of an object, may perform a type check depending on the data format.
 
bool end_object () override
 Ends processing of an object.
 
bool begin_field (string_view) override
 
bool begin_field (string_view name, bool &is_present) override
 
bool begin_field (string_view name, span< const type_id_t > types, size_t &index) override
 
bool begin_field (string_view name, bool &is_present, span< const type_id_t > types, size_t &index) override
 
bool end_field () override
 
bool begin_tuple (size_t size) override
 Begins processing of a fixed-size sequence.
 
bool end_tuple () override
 Ends processing of a sequence.
 
bool begin_key_value_pair () override
 Begins processing of a tuple with two elements, whereas the first element represents the key in an associative array.
 
bool end_key_value_pair () override
 Ends processing of a key-value pair after both values were written.
 
bool begin_sequence (size_t &size) override
 Begins processing of a sequence.
 
bool end_sequence () override
 Ends processing of a sequence.
 
bool begin_associative_array (size_t &size) override
 Begins processing of an associative array (map).
 
bool end_associative_array () override
 Ends processing of an associative array (map).
 
bool value (byte &x) override
 Reads x from the input.
 
bool value (bool &x) override
 Reads x from the input.
 
bool value (int8_t &x) override
 Reads x from the input.
 
bool value (uint8_t &x) override
 Reads x from the input.
 
bool value (int16_t &x) override
 Reads x from the input.
 
bool value (uint16_t &x) override
 Reads x from the input.
 
bool value (int32_t &x) override
 Reads x from the input.
 
bool value (uint32_t &x) override
 Reads x from the input.
 
bool value (int64_t &x) override
 Reads x from the input.
 
bool value (uint64_t &x) override
 Reads x from the input.
 
bool value (float &x) override
 Reads x from the input.
 
bool value (double &x) override
 Reads x from the input.
 
bool value (long double &x) override
 Reads x from the input.
 
bool value (std::string &x) override
 Reads x from the input.
 
bool value (std::u16string &x) override
 Reads x from the input.
 
bool value (std::u32string &x) override
 Reads x from the input.
 
bool value (span< byte > x) override
 Reads a byte sequence from the input.
 
- Public Member Functions inherited from caf::deserializer
 deserializer (actor_system &sys) noexcept
 
 deserializer (execution_unit *ctx=nullptr) noexcept
 
auto context () 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 (string_view &type_name)
 Reads run-time-type information for the next object if available.
 
bool next_object_name_matches (string_view type_name)
 Convenience function for querying fetch_next_object_name comparing the result to type_name in one shot.
 
bool assert_next_object_name (string_view type_name)
 Like next_object_name_matches, but sets an error on the deserializer on a mismatch.
 
virtual bool begin_object (type_id_t type, string_view pretty_class_name)=0
 Begins processing of an object, may perform a type check depending on the data format.
 
virtual bool end_object ()=0
 Ends processing of an object.
 
virtual bool begin_field (string_view name)=0
 
virtual bool begin_field (string_view, bool &is_present)=0
 
virtual bool begin_field (string_view name, span< const type_id_t > types, size_t &index)=0
 
virtual bool begin_field (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.
 
virtual bool end_key_value_pair ()
 Ends processing of a key-value pair after both values were written.
 
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).
 
virtual bool end_associative_array ()
 Ends processing of an associative array (map).
 
virtual bool value (byte &x)=0
 Reads x from the input.
 
virtual bool value (bool &x)=0
 Reads x from the input.
 
virtual bool value (int8_t &)=0
 Reads x from the input.
 
virtual bool value (uint8_t &)=0
 Reads x from the input.
 
virtual bool value (int16_t &)=0
 Reads x from the input.
 
virtual bool value (uint16_t &)=0
 Reads x from the input.
 
virtual bool value (int32_t &)=0
 Reads x from the input.
 
virtual bool value (uint32_t &)=0
 Reads x from the input.
 
virtual bool value (int64_t &)=0
 Reads x from the input.
 
virtual bool value (uint64_t &)=0
 Reads x from the input.
 
template<class T >
std::enable_if_t< std::is_integral< T >::value, bool > value (T &x) noexcept
 Reads x from the input.
 
virtual bool value (float &)=0
 Reads x from the input.
 
virtual bool value (double &)=0
 Reads x from the input.
 
virtual bool value (long double &)=0
 Reads x from the input.
 
virtual bool value (std::string &)=0
 Reads x from the input.
 
virtual bool value (std::u16string &)=0
 Reads x from the input.
 
virtual bool value (std::u32string &)=0
 Reads x from the input.
 
virtual bool value (span< byte > x)=0
 Reads a byte sequence from the input.
 
virtual bool list (std::vector< bool > &xs)
 Adds each boolean in xs to the output.
 

Static Public Attributes

static constexpr string_view field_type_suffix_default = "-type"
 The value value for field_type_suffix().
 

Additional Inherited Members

- Protected Attributes inherited from caf::deserializer
execution_unitcontext_
 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.
 

Detailed Description

Deserializes an inspectable object from a JSON-formatted string.

Member Function Documentation

◆ begin_associative_array()

bool caf::json_reader::begin_associative_array ( size_t &  size)
overridevirtual

Begins processing of an associative array (map).

Note
the default implementation calls begin_sequence(size).

Reimplemented from caf::deserializer.

◆ begin_field() [1/4]

bool caf::json_reader::begin_field ( string_view  name,
bool &  is_present 
)
overridevirtual

Implements caf::deserializer.

◆ begin_field() [2/4]

bool caf::json_reader::begin_field ( string_view  name,
bool &  is_present,
span< const type_id_t types,
size_t &  index 
)
overridevirtual

Implements caf::deserializer.

◆ begin_field() [3/4]

bool caf::json_reader::begin_field ( string_view  name,
span< const type_id_t types,
size_t &  index 
)
overridevirtual

Implements caf::deserializer.

◆ begin_field() [4/4]

bool caf::json_reader::begin_field ( string_view  )
overridevirtual

Implements caf::deserializer.

◆ begin_key_value_pair()

bool caf::json_reader::begin_key_value_pair ( )
overridevirtual

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 from caf::deserializer.

◆ begin_object()

bool caf::json_reader::begin_object ( type_id_t  type,
string_view  pretty_class_name 
)
overridevirtual

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.

Implements caf::deserializer.

◆ begin_sequence()

bool caf::json_reader::begin_sequence ( size_t &  size)
overridevirtual

Begins processing of a sequence.

Implements caf::deserializer.

◆ begin_tuple()

bool caf::json_reader::begin_tuple ( size_t  size)
overridevirtual

Begins processing of a fixed-size sequence.

Implements caf::deserializer.

◆ end_associative_array()

bool caf::json_reader::end_associative_array ( )
overridevirtual

Ends processing of an associative array (map).

Note
the default implementation calls end_sequence().

Reimplemented from caf::deserializer.

◆ end_field()

bool caf::json_reader::end_field ( )
overridevirtual

Implements caf::deserializer.

◆ end_key_value_pair()

bool caf::json_reader::end_key_value_pair ( )
overridevirtual

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

Note
the default implementation calls end_tuple().

Reimplemented from caf::deserializer.

◆ end_object()

bool caf::json_reader::end_object ( )
overridevirtual

Ends processing of an object.

Implements caf::deserializer.

◆ end_sequence()

bool caf::json_reader::end_sequence ( )
overridevirtual

Ends processing of a sequence.

Implements caf::deserializer.

◆ end_tuple()

bool caf::json_reader::end_tuple ( )
overridevirtual

Ends processing of a sequence.

Implements caf::deserializer.

◆ fetch_next_object_name()

bool caf::json_reader::fetch_next_object_name ( string_view type_name)
overridevirtual

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 from caf::deserializer.

◆ fetch_next_object_type()

bool caf::json_reader::fetch_next_object_type ( type_id_t type)
overridevirtual

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

Implements caf::deserializer.

◆ field_type_suffix()

string_view caf::json_reader::field_type_suffix ( ) const
noexcept

Returns the suffix for generating type annotation fields for variant fields.

For example, CAF inserts field called "@foo${field_type_suffix}" for a variant field called "foo".

◆ load()

bool caf::json_reader::load ( string_view  json_text)

Parses json_text into an internal representation.

After loading the JSON input, the reader is ready for attempting to deserialize inspectable objects.

Warning
The internal data structure keeps pointers into json_text. Hence, the buffer pointed to by the string view must remain valid until either destroying this reader or calling reset.
Note
Implicitly calls reset.

◆ revert()

void caf::json_reader::revert ( )

Reverts the state of the reader back to where it was after calling load.

Postcondition
The reader is ready for attempting to deserialize another inspectable object.

◆ value() [1/17]

bool caf::json_reader::value ( bool &  x)
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [2/17]

bool caf::json_reader::value ( byte x)
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [3/17]

bool caf::json_reader::value ( double &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [4/17]

bool caf::json_reader::value ( float &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [5/17]

bool caf::json_reader::value ( int16_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [6/17]

bool caf::json_reader::value ( int32_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [7/17]

bool caf::json_reader::value ( int64_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [8/17]

bool caf::json_reader::value ( int8_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [9/17]

bool caf::json_reader::value ( long double &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [10/17]

bool caf::json_reader::value ( span< byte x)
overridevirtual

Reads a byte sequence from the input.

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

Implements caf::deserializer.

◆ value() [11/17]

bool caf::json_reader::value ( std::string &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [12/17]

bool caf::json_reader::value ( std::u16string &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [13/17]

bool caf::json_reader::value ( std::u32string &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [14/17]

bool caf::json_reader::value ( uint16_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [15/17]

bool caf::json_reader::value ( uint32_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [16/17]

bool caf::json_reader::value ( uint64_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.

◆ value() [17/17]

bool caf::json_reader::value ( uint8_t &  )
overridevirtual

Reads x from the input.

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

Implements caf::deserializer.


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