Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

serializer

A serializer for JSON.

Synopsis

Defined in header <boost/json/serializer.hpp>

class serializer
Member Functions

Name

Description

done

Returns true if the serialization is complete.

read

Read the next buffer of serialized JSON.

reset

Reset the serializer for a new element.

Reset the serializer for a new string.

serializer [constructor]

Move constructor (deleted)

Default constructor.

~serializer [destructor]

Destructor.

Description

This class traverses an instance of a library type and emits serialized JSON text by filling in one or more caller-provided buffers. To use, declare a variable and call reset with a pointer to the variable you want to serialize. Then call read over and over until done returns true.

Example

This demonstrates how the serializer may be used to print a JSON value to an output stream.

void print( std::ostream& os, value const& jv)
{
    serializer sr;
    sr.reset( &jv );
    while( ! sr.done() )
    {
        char buf[ 4000 ];
        os << sr.read( buf );
    }
}
Thread Safety

The same instance may not be accessed concurrently.

Convenience header <boost/json.hpp>


PrevUpHomeNext