MMTF-C++
The C++ language MMTF libraries
|
Helper class to decode msgpack maps into object fields. More...
#include <map_decoder.hpp>
Public Member Functions | |
MapDecoder (const msgpack::object &obj) | |
Initialize object given a msgpack object. Reads out all key-value pairs and converts key to string if possible (warns otherwise). More... | |
template<typename T > | |
void | decode (const std::string &key, bool required, T &target) |
Extract value from map and decode into target. More... | |
void | checkExtraKeys () |
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. More... | |
Helper class to decode msgpack maps into object fields.
|
inline |
Initialize object given a msgpack object. Reads out all key-value pairs and converts key to string if possible (warns otherwise).
mmtf::DecodeError | if obj is not a map. |
|
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.
void mmtf::MapDecoder::decode | ( | const std::string & | key, |
bool | required, | ||
T & | target | ||
) |
Extract value from map and decode into target.
[in] | key | Key into msgpack map. |
[in] | required | True if field is required by MMTF specs. |
[out] | target | Store 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.