MMTF-C++
The C++ language MMTF libraries
Loading...
Searching...
No Matches
mmtf::MapDecoder Class Reference

Helper class to decode msgpack maps into object fields. Class cannot be copied as it contains unique pointers to msgpack data. More...

#include <map_decoder.hpp>

Public Member Functions

 MapDecoder ()
 Construct empty decoder. Use init-functions to fill it.
 
 MapDecoder (const msgpack::object &obj)
 Construct decoder given a msgpack::object. Reads out all key-value pairs and converts key to string if possible (warns otherwise).
 
 MapDecoder (const std::map< std::string, msgpack::object > &map_in)
 Construct decoder given a string to msgpack::object map. Reads out all key-value pairs and converts key to string if possible (warns otherwise).
 
void initFromObject (const msgpack::object &obj)
 Initialize given a msgpack::object. Clears internal data and has same effect as MapDecoder::MapDecoder(const msgpack::object&).
 
void initFromBuffer (const char *buffer, size_t size)
 Initialize from byte buffer of given size. Unpacks data and then same effect as MapDecoder::initFromObject.
 
template<typename T>
void decode (const std::string &key, bool required, T &target) const
 Extract value from map and decode into target.
 
void copy_decode (const std::string &key, bool required, std::map< std::string, msgpack::object > &target, msgpack::zone &zone) const
 Don't decode, but instead just copy map-contents onto a zone for later decoding/processing you should use this when you have nested msgpack objects. Note: There is some copy overhead here. If speed becomes an issue we should come up with a way to keep the original handle alive.
 
void checkExtraKeys () const
 Check if there are any keys, that were not decoded. This is to be called after all expected fields have been decoded. A warning is written to stderr for each non-decoded key.
 

Detailed Description

Helper class to decode msgpack maps into object fields. Class cannot be copied as it contains unique pointers to msgpack data.

Constructor & Destructor Documentation

◆ MapDecoder() [1/3]

mmtf::MapDecoder::MapDecoder ( )
inline

Construct empty decoder. Use init-functions to fill it.

◆ MapDecoder() [2/3]

mmtf::MapDecoder::MapDecoder ( const msgpack::object & obj)
inline

Construct decoder given a msgpack::object. Reads out all key-value pairs and converts key to string if possible (warns otherwise).

Exceptions
mmtf::DecodeErrorif obj is not a map.

◆ MapDecoder() [3/3]

mmtf::MapDecoder::MapDecoder ( const std::map< std::string, msgpack::object > & map_in)
inline

Construct decoder given a string to msgpack::object map. Reads out all key-value pairs and converts key to string if possible (warns otherwise).

Member Function Documentation

◆ checkExtraKeys()

void mmtf::MapDecoder::checkExtraKeys ( ) const
inline

Check if there are any keys, that were not decoded. This is to be called after all expected fields have been decoded. A warning is written to stderr for each non-decoded key.

◆ copy_decode()

void mmtf::MapDecoder::copy_decode ( const std::string & key,
bool required,
std::map< std::string, msgpack::object > & target,
msgpack::zone & zone ) const
inline

Don't decode, but instead just copy map-contents onto a zone for later decoding/processing you should use this when you have nested msgpack objects. Note: There is some copy overhead here. If speed becomes an issue we should come up with a way to keep the original handle alive.

Parameters
[in]keyKey into msgpack map.
[in]requiredTrue if field is required by MMTF specs or you
[out]targetstd::map<std::string, msgpack::object> that holds access to data on zone.
[in]zonemsgpack::zone to copy data onto

If msgpack type is not as expected, we write a warning to stderr. If conversion to the target type fails, msgpack throws an exception. If a required field is missing in the map or if binary decoding fails, we throw an mmtf::DecodeError.

◆ decode()

template<typename T>
void mmtf::MapDecoder::decode ( const std::string & key,
bool required,
T & target ) const
inline

Extract value from map and decode into target.

Parameters
[in]keyKey into msgpack map.
[in]requiredTrue if field is required by MMTF specs.
[out]targetStore decoded value into this field.

If msgpack type is not as expected, we write a warning to stderr. If conversion to the target type fails, msgpack throws an exception. If a required field is missing in the map or if binary decoding fails, we throw an mmtf::DecodeError.

◆ initFromBuffer()

void mmtf::MapDecoder::initFromBuffer ( const char * buffer,
size_t size )
inline

Initialize from byte buffer of given size. Unpacks data and then same effect as MapDecoder::initFromObject.

◆ initFromObject()

void mmtf::MapDecoder::initFromObject ( const msgpack::object & obj)
inline

Initialize given a msgpack::object. Clears internal data and has same effect as MapDecoder::MapDecoder(const msgpack::object&).


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