MMTF-C++
The C++ language MMTF libraries
|
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. | |
Helper class to decode msgpack maps into object fields. Class cannot be copied as it contains unique pointers to msgpack data.
|
inline |
Construct empty decoder. Use init-functions to fill it.
|
inline |
Construct decoder 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 |
Construct decoder given a string to msgpack::object map. Reads out all key-value pairs and converts key to string if possible (warns otherwise).
|
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.
|
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.
[in] | key | Key into msgpack map. |
[in] | required | True if field is required by MMTF specs or you |
[out] | target | std::map<std::string, msgpack::object> that holds access to data on zone. |
[in] | zone | msgpack::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.
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.
Initialize from byte buffer of given size. Unpacks data and then same effect as MapDecoder::initFromObject.
Initialize given a msgpack::object. Clears internal data and has same effect as MapDecoder::MapDecoder(const msgpack::object&).