| cereal::JSONInputArchive(3) | Library Functions Manual | cereal::JSONInputArchive(3) |
NAME
cereal::JSONInputArchive - An input archive designed to load data from JSON.
SYNOPSIS
#include </home/build/include/cereal/archives/json.hpp>
Inherits cereal::InputArchive< JSONInputArchive >, and cereal::traits::TextArchive.
Public Member Functions
Common Functionality
Common use cases for directly interacting with an JSONInputArchive
JSONInputArchive (std::istream &stream)
Construct, reading from the provided stream. void loadBinaryValue (void
*data, size_t size, const char *name=nullptr)
Loads some binary data, encoded as a base64 string.
Public Member Functions inherited from cereal::InputArchive<
JSONInputArchive >
InputArchive (JSONInputArchive *const derived)
Construct the output archive. InputArchive & operator=
(InputArchive const &)=delete
JSONInputArchive & operator() (Types &&... args)
Serializes all passed in data. void serializeDeferments ()
Serializes any data marked for deferment using defer. std::shared_ptr< void
> getSharedPointer (std::uint32_t const id)
Retrieves a shared pointer given a unique key for it. void
registerSharedPointer (std::uint32_t const id, std::shared_ptr<
void > ptr)
Registers a shared pointer to its unique identifier. std::string
getPolymorphicName (std::uint32_t const id)
Retrieves the string for a polymorphic type given a unique key for it. void
registerPolymorphicName (std::uint32_t const id, std::string const
&name)
Registers a polymorphic name string to its unique identifier.
JSONInputArchive & operator& (T &&arg)
Serializes passed in data.
JSONInputArchive & operator>> (T &&arg)
Serializes passed in data.
Public Member Functions inherited from
cereal::detail::InputArchiveBase
InputArchiveBase (InputArchiveBase &&) CEREAL_NOEXCEPT
InputArchiveBase & operator= (InputArchiveBase &&)
CEREAL_NOEXCEPT
Internal Functionality
Functionality designed for use by those requiring control over the
inner mechanisms of the JSONInputArchive
void startNode ()
Starts a new node, going into its proper iterator. void finishNode ()
Finishes the most recently started node. const char * getNodeName ()
const
Retrieves the current node name. void setNextName (const char *name)
Sets the name for the next node created with startNode.
Additional Inherited Members
using is_loading
Indicates this archive is intended for loading.
using is_saving
Indicates this archive is not intended for saving.
Detailed Description
An input archive designed to load data from JSON.
This archive uses RapidJSON to read in a JSON archive.
As with the output JSON archive, the preferred way to use this archive is in an RAII fashion, ensuring its destruction after all data has been read.
Input JSON should have been produced by the JSONOutputArchive. Data can only be added to dynamically sized containers (marked by JSON arrays) - the input archive will determine their size by looking at the number of child nodes. Only JSON originating from a JSONOutputArchive is officially supported, but data from other sources may work if properly formatted.
The JSONInputArchive does not require that nodes are loaded in the same order they were saved by JSONOutputArchive. Using name value pairs (NVPs), it is possible to load in an out of order fashion or otherwise skip/select specific nodes to load.
The default behavior of the input archive is to read sequentially starting with the first node and exploring its children. When a given NVP does not match the read in name for a node, the archive will search for that node at the current level and load it if it exists. After loading an out of order node, the archive will then proceed back to loading sequentially from its new position.
Consider this simple example where loading of some data is skipped:
// imagine the input file has someData(1-9) saved in order at the top level node ar( someData1, someData2, someData3 ); // XML loads in the order it sees in the file ar( cereal::make_nvp( "hello", someData6 ) ); // NVP given does not
// match expected NVP name, so we search
// for the given NVP and load that value ar( someData7, someData8, someData9 ); // with no NVP given, loading resumes at its
// current location, proceeding sequentially
Constructor & Destructor Documentation
cereal::JSONInputArchive::JSONInputArchive (std::istream & stream) [inline]
Construct, reading from the provided stream.
Parameters
Member Function Documentation
const char * cereal::JSONInputArchive::getNodeName () const [inline]
Retrieves the current node name.
Returns
void cereal::JSONInputArchive::loadBinaryValue (void * data, size_t size, const char * name = nullptr) [inline]
Loads some binary data, encoded as a base64 string. This will automatically start and finish a node to load the data, and can be called directly by users.
Note that this follows the same ordering rules specified in the class description in regards to loading in/out of order
void cereal::JSONInputArchive::startNode () [inline]
Starts a new node, going into its proper iterator. This places an iterator for the next node to be parsed onto the iterator stack. If the next node is an array, this will be a value iterator, otherwise it will be a member iterator.
By default our strategy is to start with the document root node and then recursively iterate through all children in the order they show up in the document. We don't need to know NVPs to do this; we'll just blindly load in the order things appear in.
If we were given an NVP, we will search for it if it does not match our the name of the next node that would normally be loaded. This functionality is provided by search().
Author
Generated automatically by Doxygen for cereal from the source code.
| Sat Oct 10 2026 08:08:15 | cereal |