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>
|
| 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.
◆ 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
-
◆ 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).
◆ 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] | 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.
◆ 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] | 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.
◆ initFromBuffer()
void mmtf::MapDecoder::initFromBuffer |
( |
const char * | buffer, |
|
|
size_t | size ) |
|
inline |
◆ initFromObject()
void mmtf::MapDecoder::initFromObject |
( |
const msgpack::object & | obj | ) |
|
|
inline |
The documentation for this class was generated from the following file:
- /home/abuild/rpmbuild/BUILD/mmtf-cpp-1.1.0-build/mmtf-cpp-1.1.0/include/mmtf/map_decoder.hpp