Protocol Serialization

C++ serialization of various encoding formats:

Supports two types of serialization: full parsing results in a Document Object Model, and pull parsing is useful for streaming input.

Compatible with Boost.Serialization.

Full Parsing

The full parser transforms the entire input into a data structure. This is done via an input archive (called iarchive.) You can either use a generic tree data structure, such as dynamic-cpp, as the Document Object Model, or you can parse the input directly into your own data structures or the standard containers in C++.

iarchive input(buffer.data(), buffer.data() + buffer.size());
dynamic::var result;
input >> result;

Formatting a full data struture is done with an output archive (called oarchive.)

dynamic::var data;
// Insert some values into data
std::ostringstream result;
stream_oarchive output(result)
output << data;

Pull Parsing

The pull parser (called reader) is based on the Iterator design pattern, where the input is interpreted piece by piece. A simple example is:

std::string buffer = "[42, 43]";
json::reader reader(buffer.data(), buffer.data() + buffer.size());
assert(reader.type() == token::token_array_begin);
std::cout << reader.get_integer() << std::endl;
std::cout << reader.get_integer() << std::endl;
assert(reader.type() == token::token_array_end);
assert(reader.type() == token::token_eof);

Pull parsers are often paired with push formatters (called writer), which will create the output stream piece by piece. This example shows how to recreate the parsed buffer from the previous example:

std::ostringstream output;
output_stream<char> buffer(output);
json::writer writer(buffer);
std::cout << output.str() << std::endl;


Depends on Boost.Serialization. Test suites depends on Boost.Test.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks