actor-framework
|
Serializes an inspectable object to a JSON-formatted string. More...
#include <json_writer.hpp>
Public Types | |
enum | type : uint8_t { element, type::object, type::member, type::key, type::array, type::string, type::number, type::boolean, type::null } |
Reflects the structure of JSON objects according to ECMA-404. More... | |
using | super = serializer |
Public Types inherited from caf::serializer | |
using | super = save_inspector_base< serializer > |
Public Types inherited from caf::save_inspector_base< serializer > | |
using | super = save_inspector |
Public Member Functions | |
json_writer (actor_system &sys) | |
std::string_view | str () const noexcept |
Returns a string view into the internal buffer. More... | |
size_t | indentation () const noexcept |
Returns the current indentation factor. | |
void | indentation (size_t factor) noexcept |
Sets the indentation level. More... | |
bool | compact () const noexcept |
Returns whether the writer generates compact JSON output without any spaces or newlines to separate values. More... | |
bool | skip_empty_fields () const noexcept |
Returns whether the writer omits empty fields entirely (true) or renders empty fields as $field: null (false). More... | |
void | skip_empty_fields (bool value) noexcept |
Configures whether the writer omits empty fields. | |
bool | skip_object_type_annotation () const noexcept |
Returns whether the writer omits '' annotations for JSON objects. | |
void | skip_object_type_annotation (bool value) noexcept |
Configures whether the writer omits '' annotations for JSON objects. | |
std::string_view | field_type_suffix () const noexcept |
Returns the suffix for generating type annotation fields for variant fields. More... | |
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. | |
void | reset () |
Removes all characters from the buffer and restores the writer to its initial state. More... | |
bool | begin_object (type_id_t type, std::string_view name) override |
Begins processing of an object. More... | |
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 tuple. | |
bool | end_tuple () override |
Ends processing of a tuple. | |
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. More... | |
bool | end_key_value_pair () override |
Ends processing of a key-value pair after both values were written. More... | |
bool | begin_sequence (size_t size) override |
Begins processing of a sequence. Saves the size to the underlying storage. | |
bool | end_sequence () override |
Ends processing of a sequence. | |
bool | begin_associative_array (size_t size) override |
Begins processing of an associative array (map). More... | |
bool | end_associative_array () override |
Ends processing of an associative array (map). More... | |
bool | value (std::byte x) override |
Adds x to the output. More... | |
bool | value (bool x) override |
Adds x to the output. More... | |
bool | value (int8_t x) override |
Adds x to the output. More... | |
bool | value (uint8_t x) override |
Adds x to the output. More... | |
bool | value (int16_t x) override |
Adds x to the output. More... | |
bool | value (uint16_t x) override |
Adds x to the output. More... | |
bool | value (int32_t x) override |
Adds x to the output. More... | |
bool | value (uint32_t x) override |
Adds x to the output. More... | |
bool | value (int64_t x) override |
Adds x to the output. More... | |
bool | value (uint64_t x) override |
Adds x to the output. More... | |
bool | value (float x) override |
Adds x to the output. More... | |
bool | value (double x) override |
Adds x to the output. More... | |
bool | value (long double x) override |
Adds x to the output. More... | |
bool | value (std::string_view x) override |
Adds x to the output. More... | |
bool | value (const std::u16string &x) override |
Adds x to the output. More... | |
bool | value (const std::u32string &x) override |
Adds x to the output. More... | |
bool | value (span< const std::byte > x) override |
Adds x as raw byte block to the output. More... | |
Public Member Functions inherited from caf::serializer | |
serializer (actor_system &sys) noexcept | |
actor_system * | context () const noexcept |
bool | has_human_readable_format () const noexcept |
template<class T > | |
std::enable_if_t< std::is_integral_v< T >, bool > | value (T x) |
Adds x 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 error & | get_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) |
Static Public Attributes | |
static constexpr bool | skip_empty_fields_default = true |
The default value for skip_empty_fields() . | |
static constexpr bool | skip_object_type_annotation_default = false |
The default value for skip_object_type_annotation() . | |
static constexpr std::string_view | field_type_suffix_default = "-type" |
The value value for field_type_suffix() . | |
Static Public Attributes inherited from caf::save_inspector | |
static constexpr bool | is_loading = false |
Enables dispatching on the inspector type. | |
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 &&...) |
Protected Attributes inherited from caf::serializer | |
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. | |
Protected Attributes inherited from caf::save_inspector | |
error | err_ |
Serializes an inspectable object to a JSON-formatted string.
|
strong |
Reflects the structure of JSON objects according to ECMA-404.
This enum skips types such as members
or value
since they are not needed to generate JSON.
|
overridevirtual |
Begins processing of an associative array (map).
begin_sequence(size)
. Reimplemented from caf::serializer.
|
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::serializer.
|
overridevirtual |
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.
Implements caf::serializer.
|
inlinenoexcept |
Returns whether the writer generates compact JSON output without any spaces or newlines to separate values.
|
overridevirtual |
Ends processing of an associative array (map).
end_sequence()
. Reimplemented from caf::serializer.
|
overridevirtual |
Ends processing of a key-value pair after both values were written.
end_tuple()
. Reimplemented from caf::serializer.
|
inlinenoexcept |
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".
|
inlinenoexcept |
Sets the indentation level.
factor | The number of spaces to add to each level of indentation. A value of 0 (the default) disables indentation, printing the entire JSON output into a single line. |
void caf::json_writer::reset | ( | ) |
Removes all characters from the buffer and restores the writer to its initial state.
|
inlinenoexcept |
Returns whether the writer omits empty fields entirely (true) or renders empty fields as $field: null
(false).
|
inlinenoexcept |
Returns a string view into the internal buffer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
to the output.
x | A value for a builtin type. |
true
on success, false
otherwise. Implements caf::serializer.
|
overridevirtual |
Adds x
as raw byte block to the output.
x | The byte sequence. |
sec::success
otherwise. Implements caf::serializer.