JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::encoder Class Referenceabstract

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.
 

Detailed Description

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.

See also
writer

Definition at line 34 of file encode.hpp.

Member Function Documentation

◆ encode()

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.

◆ write_array_begin()

virtual void jsonv::encoder::write_array_begin ( )
protectedpure virtual

Write the opening of an array value.

[

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_array_delimiter()

virtual void jsonv::encoder::write_array_delimiter ( )
protectedpure virtual

Write the delimiter between two entries in an array.

,

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_array_end()

virtual void jsonv::encoder::write_array_end ( )
protectedpure virtual

Write the closing of an array value.

]

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_boolean()

virtual void jsonv::encoder::write_boolean ( bool  value)
protectedpure virtual

Write a boolean value.

true

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_decimal()

virtual void jsonv::encoder::write_decimal ( double  value)
protectedpure virtual

Write a decimal value.

Parameters
valueis 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.
4.9

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_integer()

virtual void jsonv::encoder::write_integer ( std::int64_t  value)
protectedpure virtual

Write an integer value.

902

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_null()

virtual void jsonv::encoder::write_null ( )
protectedpure virtual

Write the null value.

JSONV_PUBLIC const value null
An instance with kind::null.

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_object_begin()

virtual void jsonv::encoder::write_object_begin ( )
protectedpure virtual

Write the opening of an object value.

{

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_object_delimiter()

virtual void jsonv::encoder::write_object_delimiter ( )
protectedpure virtual

Write the delimiter between two entries in an object.

,

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_object_end()

virtual void jsonv::encoder::write_object_end ( )
protectedpure virtual

Write the closing of an object value.

}

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_object_key()

virtual void jsonv::encoder::write_object_key ( std::string_view  key)
protectedpure virtual

Write the key for an object, including the separator.

"key":

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_string()

virtual void jsonv::encoder::write_string ( std::string_view  value)
protectedpure virtual

Write a string value.

Parameters
valueis 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.
"value"

Implemented in jsonv::ostream_encoder, jsonv::ostream_pretty_encoder, and jsonv::value_encoder.

◆ write_tree() [1/2]

virtual void jsonv::encoder::write_tree ( const jsonv::value &  source)
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.

◆ write_tree() [2/2]

virtual void jsonv::encoder::write_tree ( jsonv::value &&  source)
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.

Friends And Related Symbol Documentation

◆ writer

friend class writer
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.


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