Turi Create  4.0
turi::oarchive Class Reference

The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities. More...

#include <core/storage/serialization/oarchive.hpp>

Public Member Functions

 oarchive (std::ostream &outstream)
 constructor. Takes a generic std::ostream object
 
void write (const char *c, std::streamsize s)
 
bool fail ()
 Returns true if the underlying stream is in a failure state.
 

Detailed Description

The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.

Given a standard output stream, you can construct an oarchive object by:

// where strm is an ostream object
turi::oarchive oarc(strm);

For instance, to serialize to a file,

std::ofstream fout("outputfile.bin");
turi::oarchive oarc(fout);

Once the oarc object is constructed, Serializable objects can be written to it using the << stream operator.

oarc << a << b << c;

Alternatively, data can be directly written to the stream using the oarchive::write() function.

Written data can be deserialized using turi::iarchive. For more usage details, see serialization

The oarchive object should not be used once the associated stream object is closed or is destroyed.

The oarc object does not flush the associated stream, and the user may need to manually flush the associated stream to clear any stream buffers. For instance, while the std::stringstream may be used for both output and input, it is necessary to flush the stream before all bytes written to the stringstream are available for input.

If the oarchive is constructed without an ostream, writes go into a newly allocated buffer in oarc.buf. The serialized length is oarc.off and the entire buffer allocated length is oarc.len.

If the oarchive is constructed with a std::vector<char>&, it will behave as like the above case, but it will keep a reference to the std::vector<char> and use that for resizing. At completion, the std::vector<char> will contain the data and oarc.off contains the serialized length.

and the entire buffer allocated length is oarc.len.

To use this class, include core/storage/serialization/serialization_includes.hpp

Definition at line 80 of file oarchive.hpp.

Member Function Documentation

◆ write()

void turi::oarchive::write ( const char *  c,
std::streamsize  s 
)
inline

Directly writes "s" bytes from the memory location pointed to by "c" into the stream.

Definition at line 118 of file oarchive.hpp.


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