C++ Actor Framework 1.0.0
|
Deserializes an inspectable object from a JSON-formatted string. More...
#include <json_reader.hpp>
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 = std::string_view |
using | value_type |
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 (const json_reader &)=delete | |
json_reader & | operator= (const json_reader &)=delete |
std::string_view | field_type_suffix () const noexcept |
Returns the suffix for generating type annotation fields for variant fields. | |
void | field_type_suffix (std::string_view suffix) noexcept |
Configures whether the writer omits empty fields. | |
const type_id_mapper * | mapper () const noexcept |
Returns the type ID mapper used by the writer. | |
void | mapper (const type_id_mapper *ptr) noexcept |
Changes the type ID mapper for the writer. | |
bool | load (std::string_view json_text) |
Parses json_text into an internal representation. | |
bool | load_file (const char *path) |
Parses the content of the file under the given path . | |
bool | load_file (const std::string &path) |
Parses the content of the file under the given path . | |
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 (std::string_view &type_name) override |
Reads run-time-type information for the next object if available. | |
bool | begin_object (type_id_t type, std::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 (std::string_view) override |
bool | begin_field (std::string_view name, bool &is_present) override |
bool | begin_field (std::string_view name, span< const type_id_t > types, size_t &index) override |
bool | begin_field (std::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 (std::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< std::byte > x) override |
Reads a byte sequence from the input. | |
Public Member Functions inherited from caf::deserializer | |
deserializer (actor_system &sys) noexcept | |
actor_system * | context () const noexcept |
bool | has_human_readable_format () const noexcept |
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. | |
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. | |
template<class T > | |
std::enable_if_t< std::is_integral_v< T >, bool > | value (T &x) noexcept |
Reads x from the input. | |
virtual bool | list (std::vector< bool > &xs) |
Adds each boolean in xs to the output. | |
Static Public Attributes | |
static constexpr std::string_view | field_type_suffix_default = "-type" |
The value value for field_type_suffix() . | |
Additional Inherited Members | |
Protected Attributes inherited from caf::deserializer | |
actor_system * | context_ = 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. | |
Deserializes an inspectable object from a JSON-formatted string.
using caf::json_reader::value_type |
|
overridevirtual |
Begins processing of an associative array (map).
begin_sequence(size)
. Reimplemented from caf::deserializer.
|
overridevirtual |
Implements caf::deserializer.
|
overridevirtual |
Implements caf::deserializer.
|
overridevirtual |
Implements caf::deserializer.
|
overridevirtual |
Implements caf::deserializer.
|
overridevirtual |
Begins processing of a tuple with two elements, whereas the first element represents the key in an associative array.
begin_tuple(2)
. Reimplemented from caf::deserializer.
|
overridevirtual |
Begins processing of an object, may perform a type check depending on the data format.
type | 16-bit ID for known types, invalid_type_id otherwise. |
pretty_class_name | Either the output of type_name_or_anonymous or the optionally defined pretty name. |
Implements caf::deserializer.
|
overridevirtual |
Begins processing of a sequence.
Implements caf::deserializer.
|
overridevirtual |
Begins processing of a fixed-size sequence.
Implements caf::deserializer.
|
overridevirtual |
Ends processing of an associative array (map).
end_sequence()
. Reimplemented from caf::deserializer.
|
overridevirtual |
Implements caf::deserializer.
|
overridevirtual |
Ends processing of a key-value pair after both values were written.
end_tuple()
. Reimplemented from caf::deserializer.
|
overridevirtual |
Ends processing of an object.
Implements caf::deserializer.
|
overridevirtual |
Ends processing of a sequence.
Implements caf::deserializer.
|
overridevirtual |
Ends processing of a sequence.
Implements caf::deserializer.
|
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.
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.
|
overridevirtual |
Reads run-time-type information for the next object if available.
Implements caf::deserializer.
|
nodiscardnoexcept |
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".
bool caf::json_reader::load | ( | std::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.
json_text
. Hence, the buffer pointed to by the string view must remain valid until either destroying this reader or calling reset
. reset
. bool caf::json_reader::load_file | ( | const char * | path | ) |
Parses the content of the file under the given path
.
After loading the content of the JSON file, the reader is ready for attempting to deserialize inspectable objects.
reset
. bool caf::json_reader::load_file | ( | const std::string & | path | ) |
Parses the content of the file under the given path
.
After loading the content of the JSON file, the reader is ready for attempting to deserialize inspectable objects.
reset
. void caf::json_reader::revert | ( | ) |
Reverts the state of the reader back to where it was after calling load
.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads a byte sequence from the input.
x | The byte sequence. |
sec::success
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.
|
overridevirtual |
Reads x
from the input.
x | A reference to a builtin type. |
true
on success, false
otherwise. Implements caf::deserializer.