#ifndef BYTE_STRING
#define BYTE_STRING
#include <vector>
typedef std::vector<uint8_t> byte_string;
inline bool operator==(const byte_string &l, const byte_string::value_type &value) {
return l.size() == 1 && l.at(0) == value;
}
inline byte_string &operator+=(byte_string &l, const byte_string::value_type &value) {
l.push_back(value);
return l;
}
inline byte_string &operator+=(byte_string &l, const char &value) {
l.push_back(value);
return l;
}
inline byte_string &operator+=(byte_string &l, const byte_string::value_type *value) {
l.insert(l.end(), value, value + strlen((char*)value));
return l;
}
inline byte_string &operator+=(byte_string &l, const byte_string &r) {
l.insert(l.end(), r.begin(), r.end());
return l;
}
inline bool operator==(const byte_string& l, const byte_string::value_type* r) {
byte_string::size_type lSize = l.size();
byte_string::size_type rSize = strlen((const char*)r);
if(lSize != rSize)
return false;
return equal(l.begin(), l.end(), r);
}
inline bool operator!=(const byte_string& l, const byte_string::value_type* r) {
return !(l == r);
}
inline unsigned char *malloc_copy(const byte_string &l) {
unsigned char *output = (unsigned char*)malloc(l.size());
if(!output)
return NULL;
memcpy(output, &l[0], l.size());
return output;
}
#endif