json::writer
| Type | Class |
| Namespace | conjure::core::json |
| Include File Path | engine/include/conjure/core/json/writer.h |
| Source File Path | engine/src/core/json/writer.cpp |
| API ↗ | JSON |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | writer(); | |
| public | writer(
const writer &) = default; | |
| public | writer(
writer &&) noexcept = default; |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~writer(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mBuffer | std::string | {} | |
| private | mRootWritten | bool | false | |
| private | mStack | std::vector<frame> | {} |
Functions
Public
begin_array
begin_arrayvoid begin_array();Opens an array as the root, an array element or the value of the pending key.
begin_object
begin_objectvoid begin_object();Opens an object as the root, an array element or the value of the pending key.
end_array
end_arrayvoid end_array();Closes the innermost array. Asserts when the innermost scope is not an array.
end_object
end_objectvoid end_object();Closes the innermost object. Asserts when the innermost scope is not an object or a key is pending.
finish
finish[[nodiscard]] std::string finish();Returns the text and resets the writer. Asserts when containers are still open or no root was written (the partial text is still returned).
is_complete
is_complete[[nodiscard]] bool is_complete() const noexcept;True when exactly one root value has been written and every container is closed.
key
keyvoid key(
std::string_view name);Writes a member key. Asserts outside an object or when a key is already pending.
reset
resetvoid reset();Discards everything written so far.
text
text[[nodiscard]] std::string_view text() const noexcept;The text written so far (possibly incomplete).
value
valuevoid value(
bool item);Writes a scalar as the root, an array element or the value of the pending key. Non-finite reals assert and are written as null; a null C string writes null, as in the document API. Strings must be valid UTF-8 (asserted in Debug, written as-is otherwise). Integral types without an overload of their own widen to i64 or u64.
void value(
i32 item);void value(
u32 item);void value(
i64 item);void value(
u64 item);void value(
f32 item);void value(
f64 item);void value(
std::string_view item);void value(
const char *item);void value(
std::nullptr_t);write_raw_json
write_raw_jsonvoid write_raw_json(
std::string_view rawJson);Inserts pre-serialised JSON verbatim where a value is expected. Debug builds parse the text and assert when it is not a single valid JSON value.
Private
append_string
append_stringvoid append_string(
std::string_view text);begin_value
begin_value[[nodiscard]] bool begin_value();