Added convert<> specialization for Binary

This commit is contained in:
beder
2012-01-21 01:54:54 -06:00
parent e17734de33
commit 2731f862a5
3 changed files with 43 additions and 0 deletions

View File

@@ -35,6 +35,19 @@ namespace YAML
}
}
bool operator == (const Binary& rhs) const {
const std::size_t s = size();
if(s != rhs.size())
return false;
const unsigned char *d1 = data();
const unsigned char *d2 = rhs.data();
for(std::size_t i=0;i<s;i++) {
if(*d1++ != *d2++)
return false;
}
return true;
}
private:
std::vector<unsigned char> m_data;
const unsigned char *m_unownedData;

View File

@@ -6,6 +6,7 @@
#endif
#include "yaml-cpp/binary.h"
#include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/null.h"
@@ -183,6 +184,26 @@ namespace YAML
return true;
}
};
// binary
template<>
struct convert<Binary> {
static Node encode(const Binary& rhs) {
return Node(EncodeBase64(rhs.data(), rhs.size()));
}
static bool decode(const Node& node, Binary& rhs) {
if(!node.IsScalar())
return false;
std::vector<unsigned char> data = DecodeBase64(node.Scalar());
if(data.empty() && !node.Scalar().empty())
return false;
rhs.swap(data);
return true;
}
};
}
#endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66