|
JSON Voorhees
Killer JSON for C++
|
An encoder is responsible for writing values to some form of output. More...
#include <jsonv/encode.hpp>
Inheritance diagram for jsonv::encoder:Public Member Functions | |
| void | encode (const jsonv::value &source) |
Encode some source value into this encoder, through write_tree. | |
Protected Member Functions | |
| virtual void | write_null ()=0 |
| Write the null value. | |
| virtual void | write_object_begin ()=0 |
| Write the opening of an object value. | |
| virtual void | write_object_end ()=0 |
| Write the closing of an object value. | |
| virtual void | write_object_key (std::string_view key)=0 |
| Write the key for an object, including the separator. | |
| virtual void | write_object_delimiter ()=0 |
| Write the delimiter between two entries in an object. | |
| virtual void | write_array_begin ()=0 |
| Write the opening of an array value. | |
| virtual void | write_array_end ()=0 |
| Write the closing of an array value. | |
| virtual void | write_array_delimiter ()=0 |
| Write the delimiter between two entries in an array. | |
| virtual void | write_string (std::string_view value)=0 |
| Write a string value. | |
| virtual void | write_integer (std::int64_t value)=0 |
| Write an integer value. | |
| virtual void | write_decimal (double value)=0 |
| Write a decimal value. | |
| virtual void | write_boolean (bool value)=0 |
| Write a boolean value. | |
| virtual void | write_tree (jsonv::value &&source) |
| Write source and everything under it as one value, taking it over. | |
| virtual void | write_tree (const jsonv::value &source) |
| Write source and everything under it as one value. | |
Friends | |
| class | writer |
The hooks above are driven by a writer, which is what keeps the sequence of calls spelling a valid document. | |
An encoder is responsible for writing values to some form of output.
It is a sink for the tokens of a JSON document: a writer drives the write_ hooks below one token at a time, writing the delimiters between elements and members itself. A whole value, handed to encode or to writer::write, arrives through write_tree, which by default walks it through those same hooks. An implementation turns each token into text, as ostream_encoder does, or into anything else.
Definition at line 34 of file encode.hpp.
| void jsonv::encoder::encode | ( | const jsonv::value & | source | ) |
Encode some source value into this encoder, through write_tree.
To write a document token by token instead of from a finished value, construct a writer over this encoder; its writer::write does the same.
|
protectedpure virtual |
Write the opening of an array value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the delimiter between two entries in an array.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the closing of an array value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write a boolean value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write a decimal value.
| value | is the decimal to write. Keep in mind that standard JSON does not support special IEEE 754 values such as NaN and infinity. It is the implementation's choice of how to deal with such values. Two common options are to output null or to encode a string description of the special value. |
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write an integer value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the null value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the opening of an object value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the delimiter between two entries in an object.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the closing of an object value.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write the key for an object, including the separator.
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedpure virtual |
Write a string value.
| value | is the string to write. It will hopefully be encoded as valid UTF-8. It is the implementation's choice of how to deal with malformed string values. Two common options are to replace malformed sequences with ?s or to simply output these encodings and let the receiver deal with them. |
Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.
|
protectedvirtual |
Write source and everything under it as one value.
encode calls this, and so does a writer for a value it is handed as an lvalue. The default walks the tree through the hooks above, with an object's members in the order the object keeps them and the delimiters written here, which is what a sink producing text wants: a value is well-formed by construction, so nothing checks the grammar inside one. A sink which builds a tree, as value_encoder does, overrides it to copy the value whole rather than rebuild it node by node.
Reimplemented in jsonv::value_encoder.
|
protectedvirtual |
Write source and everything under it as one value, taking it over.
A writer calls this for a value it is handed as an rvalue. The default writes it as an lvalue is written, through the overload below; a sink which builds a tree, as value_encoder does, overrides it to take the value as it is rather than copy it.
Reimplemented in jsonv::value_encoder.
|
friend |
The hooks above are driven by a writer, which is what keeps the sequence of calls spelling a valid document.
Definition at line 171 of file encode.hpp.