JSON Voorhees
Killer JSON for C++
jsonv::ostream_encoder Class Reference

An encoder that outputs to an std::ostream. More...

#include <jsonv/encode.hpp>

+ Inheritance diagram for jsonv::ostream_encoder:

Public Member Functions

 ostream_encoder (std::ostream &output)
 Create an instance which places text into output. More...
 
void ensure_ascii (bool value)
 If set to true (the default), then all non-ASCII characters in strings will be replaced with their numeric encodings. More...
 
- Public Member Functions inherited from jsonv::encoder
void encode (const jsonv::value &source)
 Encode some source value into this encoder. More...
 

Protected Member Functions

virtual void write_null () override
 Write the null value. More...
 
virtual void write_object_begin () override
 Write the opening of an object value. More...
 
virtual void write_object_end () override
 Write the closing of an object value. More...
 
virtual void write_object_key (string_view key) override
 Write the key for an object, including the separator. More...
 
virtual void write_object_delimiter () override
 Write the delimiter between two entries in an object. More...
 
virtual void write_array_begin () override
 Write the opening of an array value. More...
 
virtual void write_array_end () override
 Write the closing of an array value. More...
 
virtual void write_array_delimiter () override
 Write the delimiter between two entries in an array. More...
 
virtual void write_string (string_view value) override
 Write a string value. More...
 
virtual void write_integer (std::int64_t value) override
 Write an integer value. More...
 
virtual void write_decimal (double value) override
 When a special value is given, this will output null. More...
 
virtual void write_boolean (bool value) override
 Write a boolean value. More...
 
std::ostream & output ()
 

Detailed Description

An encoder that outputs to an std::ostream.

This implementation is used for operator<< on a value.

Definition at line 141 of file encode.hpp.

Constructor & Destructor Documentation

jsonv::ostream_encoder::ostream_encoder ( std::ostream &  output)
explicit

Create an instance which places text into output.

Member Function Documentation

void jsonv::ostream_encoder::ensure_ascii ( bool  value)

If set to true (the default), then all non-ASCII characters in strings will be replaced with their numeric encodings.

Since JSON allows for encoded text to be contained in a document, this is inefficient if you have many non-ASCII characters. If you know that your decoding side can properly handle UTF-8 encoding, then you should turn this on.

Note
This functionality cannot be used to passthrough malformed UTF-8 encoded strings. If a given string is invalid UTF-8, it will still get replaced with a numeric encoding.
virtual void jsonv::ostream_encoder::write_array_begin ( )
overrideprotectedvirtual

Write the opening of an array value.

[

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_array_delimiter ( )
overrideprotectedvirtual

Write the delimiter between two entries in an array.

,

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_array_end ( )
overrideprotectedvirtual

Write the closing of an array value.

]

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_boolean ( bool  value)
overrideprotectedvirtual

Write a boolean value.

true

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_decimal ( double  value)
overrideprotectedvirtual

When a special value is given, this will output null.

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_integer ( std::int64_t  value)
overrideprotectedvirtual

Write an integer value.

902

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_null ( )
overrideprotectedvirtual

Write the null value.

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_object_begin ( )
overrideprotectedvirtual

Write the opening of an object value.

{

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_object_delimiter ( )
overrideprotectedvirtual

Write the delimiter between two entries in an object.

,

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_object_end ( )
overrideprotectedvirtual

Write the closing of an object value.

}

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_object_key ( string_view  key)
overrideprotectedvirtual

Write the key for an object, including the separator.

"key":

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.

virtual void jsonv::ostream_encoder::write_string ( string_view  value)
overrideprotectedvirtual

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"

Implements jsonv::encoder.

Reimplemented in jsonv::ostream_pretty_encoder.


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