cereal_fwd
Fork of cereal library adding archive supporting forward compatibility
Public Member Functions | List of all members
cereal::extendable_binary_detail::StreamAdapter Class Reference

Class used as an adapter to queue of streams. More...

#include </home/breiker/code/git/cereal_fwd_github/include/cereal/details/extendable_binary_details.hpp>

Public Member Functions

 StreamAdapter (std::istream &stream, std::stringstream &sharedObjectStream, std::size_t maxBytesInSharedStream)
 Construct new object with main and secondary stream. More...
 
void pushReadingPos (StreamPos &streamPos)
 Pushes new reading position on the stream. More...
 
std::size_t readBinary (void *const data, std::size_t size)
 Reads binary data from stream which is on top. More...
 
void skipData (std::size_t size)
 Discards size bytes from the input stream. More...
 
void checkIfMaxSize (std::size_t size, std::ostream &stream)
 Check if by adding size bytes limit for max copied data is hit. More...
 
void readToOtherStream (std::size_t size, std::ostream &stream)
 Reads size bytes from the input stream and copies them to other stream. More...
 

Detailed Description

Class used as an adapter to queue of streams.

Two streams are managed. Main stream can be used only for reading and reading position can move only forward. Position of reading for second stream can be moved freely. For second stream queue of start and end positions is kept. New StreamPos can be added when last StreamPos was not yet read fully. When StreamPos::end for top StreamPos is reached reading from next StreamPos is continued. If there are no StreamPos on the queue data is read from main stream.

Additional functions for copying data from one stream to the other are provided (readToOtherStream()).

Constructor & Destructor Documentation

◆ StreamAdapter()

cereal::extendable_binary_detail::StreamAdapter::StreamAdapter ( std::istream &  stream,
std::stringstream &  sharedObjectStream,
std::size_t  maxBytesInSharedStream 
)
inline

Construct new object with main and secondary stream.

Parameters
streammain reading stream
sharedObjectStreamsecondary stream for which new reading positions could be given
maxBytesInSharedStreammax size of data copied to other stream in readToOtherStream() method

Member Function Documentation

◆ checkIfMaxSize()

void cereal::extendable_binary_detail::StreamAdapter::checkIfMaxSize ( std::size_t  size,
std::ostream &  stream 
)
inline

Check if by adding size bytes limit for max copied data is hit.

Parameters
sizeadditional size bytes to read
streamStream used for data copying Throws Exception if limit would be hit

◆ pushReadingPos()

void cereal::extendable_binary_detail::StreamAdapter::pushReadingPos ( StreamPos &  streamPos)
inline

Pushes new reading position on the stream.

Parameters
streamPosnew reading pos, saves reference which has to be valid for whole object lifetime Throws if not enough bytes are read

◆ readBinary()

std::size_t cereal::extendable_binary_detail::StreamAdapter::readBinary ( void *const  data,
std::size_t  size 
)
inline

Reads binary data from stream which is on top.

Parameters
dataaddress to read to
sizesize of data to read Size has to be less or equal to data available at the current stream position. That is:
  • If using streamPos on queue - end of current streamPos
  • If using mainStream - end of mainStream Throws if not enough bytes are read.

◆ readToOtherStream()

void cereal::extendable_binary_detail::StreamAdapter::readToOtherStream ( std::size_t  size,
std::ostream &  stream 
)
inline

Reads size bytes from the input stream and copies them to other stream.

Parameters
sizeThe number of bytes to read and copy
streamStream to copy data to Throws Exception if not enough bytes are read

◆ skipData()

void cereal::extendable_binary_detail::StreamAdapter::skipData ( std::size_t  size)
inline

Discards size bytes from the input stream.

Parameters
sizeThe number of bytes of data Throws if not enough bytes are read

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