1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
//BinaryDeserializerStream
template <typename It>
void serialize_sequence(It begin, It end, size_t length){
this->serialize(nullptr, (wire_size_t)length);
for (; begin != end; ++begin)
this->serialize(nullptr, *begin);
}
template <typename T>
void serialize(const char *name, const std::vector<T> &v){
this->serialize_sequence(v.begin(), v.end(), v.size());
}
template <typename T>
void serialize(const char *name, const std::set<T> &s){
this->serialize_sequence(s.begin(), s.end(), s.size());
}
//...
//JsonDeserializerStream
template <typename It>
void serialize_sequence(const char *name, It begin, It end, size_t length){
this->push(name);
this->get_top() = nlohmann::json::array_t();
for (; begin != end; ++begin)
this->serialize("", *begin);
this->merge_top();
}
template <typename T>
void serialize(const char *name, const std::vector<T> &v){
this->serialize_sequence(name, v.begin(), v.end(), v.size());
}
template <typename T>
void serialize(const char *name, const std::set<T> &s){
this->serialize_sequence(name, s.begin(), s.end(), s.size());
}
|