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

An input archive designed to load data saved using ExtendableBinaryOutputArchive. More...

#include </home/breiker/code/git/cereal_fwd_github/include/cereal/archives/extendable_binary.hpp>

Inheritance diagram for cereal::ExtendableBinaryInputArchive:
cereal::InputArchive< ExtendableBinaryInputArchive, Flags::ForwardSupport > cereal::detail::InputArchiveBase

Classes

class  Options
 A class containing various advanced options for the ExtendableBinaryInput archive. More...
 

Public Member Functions

 ExtendableBinaryInputArchive (std::istream &stream, Options const &options=Options::Default())
 Construct, loading from the provided stream. More...
 
template<std::size_t DataSize>
void loadBinary (void *const data, std::size_t size)
 Reads size bytes of data from the input stream. More...
 
template<std::size_t DataSize>
void loadBinarySingle (void *const data, std::size_t size)
 Load least significant size bytes of type which sizeof is DataSize. More...
 
template<std::size_t DataSize>
void copyBinarySingleNoSwap (void *dest_, void *const src_, std::size_t size_)
 Copies size bytes from input buffer to the output buffer without any byte order swapping. More...
 
void skipData (std::size_t size)
 Discards size bytes from the input stream. More...
 
bool loadTypeTag ()
 Load type tag from input stream. More...
 
template<extendable_binary_detail::FieldType expected_type>
auto getTypeTag () -> decltype(extendable_binary_detail::readType(std::uint8_t
 Gets last type tag loaded from input stream. More...
 
 if (lastTypeTag.first !=expected_type &&lastTypeTag.first !=FieldType::omitted_field) throw Exception("Loaded wrong lastTypeTag
 
template<extendable_binary_detail::FieldType expected_type>
auto getTypeTagNoError () noexcept -> decltype(extendable_binary_detail::readType(std::uint8_t
 Gets last type tag loaded from input stream. More...
 
template<class T >
void loadVarint (T &v)
 Load varint from the stream. More...
 
void skipVarint ()
 Load varint from the stream, discard input value.
 
void loadObjectBeginning ()
 Load metadata of new object.
 
void loadEndOfObjectData ()
 Read all remaining data from current object. More...
 
void loadOmittedObject ()
 Read/Skip object which was not loaded explicitly.
 
std::uint32_t getLoadedClassVersion () const
 Gets last loaded class version.
 
std::int32_t getLoadedPolymorphicId () const
 Gets last loaded polymorphic id.
 
const std::string & getLoadedPolymorphicName () const
 Gets last loaded polymorphic name.
 
std::uint32_t getLoadedObjectId () const
 Gets last loaded object id for shared pointers.
 
bool getLoadedPointerValidity () const
 Returns if last pointer was not nullptr.
 
void setLastSizeTag (std::size_t size)
 Sets value of loaded size tag.
 
std::size_t getLastSizeTag () const
 Returns value of last loaded size tag.
 
- Public Member Functions inherited from cereal::InputArchive< ExtendableBinaryInputArchive, Flags::ForwardSupport >
 InputArchive (ExtendableBinaryInputArchive *const derived)
 Construct the input archive. More...
 
InputArchive & operator= (InputArchive const &)=delete
 
ExtendableBinaryInputArchive & operator() (Types &&... args)
 Serializes all passed in data. More...
 
std::shared_ptr< void > getSharedPointer (std::uint32_t const id)
 Retrieves a shared pointer given a unique key for it. More...
 
void registerSharedPointer (std::uint32_t const id, std::shared_ptr< void > ptr)
 Registers a shared pointer to its unique identifier. More...
 
std::string getPolymorphicName (std::uint32_t const id)
 Retrieves the string for a polymorphic type given a unique key for it. More...
 
void registerPolymorphicName (std::uint32_t const id, std::string const &name)
 Registers a polymorphic name string to its unique identifier. More...
 
bool wasSerialized () const
 Indicates if last field was loaded. More...
 
ExtendableBinaryInputArchive & operator& (T &&arg)
 Serializes passed in data. More...
 
ExtendableBinaryInputArchive & operator>> (T &&arg)
 Serializes passed in data. More...
 
- Public Member Functions inherited from cereal::detail::InputArchiveBase
 InputArchiveBase (InputArchiveBase &&) CEREAL_NOEXCEPT
 
InputArchiveBase & operator= (InputArchiveBase &&) CEREAL_NOEXCEPT
 

Public Attributes

expected __pad0__: " + std::to_string(static_cast<int>(expected_type)) + " got: " + std::to_string(static_cast<int>(lastTypeTag.first)) )
 
return lastTypeTag
 

Additional Inherited Members

- Public Types inherited from cereal::InputArchive< ExtendableBinaryInputArchive, Flags::ForwardSupport >
using is_saving = std::false_type
 indicates if archive is used for saving
 
using is_loading = std::true_type
 indicates if archive is used for loading
 

Detailed Description

An input archive designed to load data saved using ExtendableBinaryOutputArchive.

This archive outputs data to a stream in an compact binary representation with additional metadata needed to support forward and backward compatibility.

This archive will load the endianness of the serialized data and if necessary transform it to match that of the local machine. This comes at a significant performance cost compared to non portable archives if the transformation is necessary, but causes no performance hit if swapping is not necessary.

The archive will save all integer values as variadic integers. Exception will be thrown when on deserialization value will be bigger than can be stored to target field. It is still recommended to use fixed size integers.

When using a binary archive and a file stream, you must use the std::ios::binary format flag to avoid having your data altered inadvertently.

Constructor & Destructor Documentation

◆ ExtendableBinaryInputArchive()

cereal::ExtendableBinaryInputArchive::ExtendableBinaryInputArchive ( std::istream &  stream,
Options const &  options = Options::Default() 
)
inline

Construct, loading from the provided stream.

Parameters
streamThe stream to read from. Should be opened with std::ios::binary flag.
optionsThe ExtendableBinary specific options to use. See the Options struct for the values of default parameters

Member Function Documentation

◆ copyBinarySingleNoSwap()

template<std::size_t DataSize>
void cereal::ExtendableBinaryInputArchive::copyBinarySingleNoSwap ( void *  dest_,
void *const  src_,
std::size_t  size_ 
)
inline

Copies size bytes from input buffer to the output buffer without any byte order swapping.

Used for loading least significant size_ bytes from integer of DataSize size.

Template Parameters
DataSizesize of destination type
Parameters
dest_destination address
src_source address
size_number of bytes to copy

◆ getTypeTag()

template<extendable_binary_detail::FieldType expected_type>
auto cereal::ExtendableBinaryInputArchive::getTypeTag ( ) -> decltype(extendable_binary_detail::readType(std::uint8_t
inline

Gets last type tag loaded from input stream.

Throws Exception if type is not expected_type or omitted.

See also
loadTypeTag()
Template Parameters
expected_typetype which is expected to be loaded
Returns
last loaded type tag

◆ getTypeTagNoError()

template<extendable_binary_detail::FieldType expected_type>
auto cereal::ExtendableBinaryInputArchive::getTypeTagNoError ( ) -> decltype(extendable_binary_detail::readType(std::uint8_t
inlinenoexcept

Gets last type tag loaded from input stream.

Template Parameters
expected_typetype which is expected to be loaded
Returns
last loaded type tag Doesn't throw exception on type different than expected_type or omitted
See also
getTypeTag

◆ loadBinary()

template<std::size_t DataSize>
void cereal::ExtendableBinaryInputArchive::loadBinary ( void *const  data,
std::size_t  size 
)
inline

Reads size bytes of data from the input stream.

Parameters
dataThe data to save
sizeThe number of bytes in the data
Template Parameters
DataSizeT The size of the actual type of the data elements being loaded

◆ loadBinarySingle()

template<std::size_t DataSize>
void cereal::ExtendableBinaryInputArchive::loadBinarySingle ( void *const  data,
std::size_t  size 
)
inline

Load least significant size bytes of type which sizeof is DataSize.

Size has to be less than DataSize. Used to load integers using minimal number of bytes. Throws Exception if size bytes cannot be loaded from stream.

Parameters
dataThe data to save
sizeThe number of bytes in the data
Template Parameters
DataSizeT The size of the actual type of the data elements being loaded

◆ loadEndOfObjectData()

void cereal::ExtendableBinaryInputArchive::loadEndOfObjectData ( )
inline

Read all remaining data from current object.

Tries to read end of object tag. Any unknown fields which were not loaded explicitly are skipped.

◆ loadTypeTag()

bool cereal::ExtendableBinaryInputArchive::loadTypeTag ( )
inline

Load type tag from input stream.

Type is saved to lastTypeTag field and can be accessed with getTypeTag() method.

See also
getTypeTag()
getTypeTagNoError()
Returns
if type is not omitted_field

◆ loadVarint()

template<class T >
void cereal::ExtendableBinaryInputArchive::loadVarint ( T &  v)
inline

Load varint from the stream.

Based on Protocol Buffers usage.

See also
ExtendableBinaryOutputArchive::saveVarint(T)

◆ skipData()

void cereal::ExtendableBinaryInputArchive::skipData ( std::size_t  size)
inline

Discards size bytes from the input stream.

Parameters
sizeThe number of bytes to skip Throws Exception if not enough bytes are read

Member Data Documentation

◆ lastTypeTag

return cereal::ExtendableBinaryInputArchive::lastTypeTag
Initial value:
{
using namespace extendable_binary_detail

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