mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
serializer: Add serializer<std::vector<T>>
This commit is contained in:
@@ -96,14 +96,4 @@ inline void skip(seastar::simple_input_stream& v, boost::type<sstring>) {
|
||||
v.skip(deserialize(v, boost::type<size_type>()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void skip(seastar::simple_input_stream& v, boost::type<std::vector<T>>) {
|
||||
auto ln = deserialize(v, boost::type<size_type>());
|
||||
for (size_type i = 0; i < ln; i++) {
|
||||
skip(v, boost::type<T>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -91,12 +91,6 @@ inline T deserialize(Input& in, boost::type<T> t) {
|
||||
return serializer<T>::read(in);
|
||||
};
|
||||
|
||||
// For vectors
|
||||
template<typename T, typename Output>
|
||||
inline void serialize(Output& out, const std::vector<T>& v);
|
||||
template<typename T, typename Input>
|
||||
inline std::vector<T> deserialize(Input& in, boost::type<std::vector<T>>);
|
||||
|
||||
template<size_t N, typename T, typename Output>
|
||||
inline void serialize(Output& out, const std::array<T, N>& v);
|
||||
template<size_t N, typename T, typename Input>
|
||||
|
||||
@@ -138,19 +138,29 @@ static inline void deserialize_array(Input& in, Container& v, size_t sz) {
|
||||
deserialize_array_helper<can_serialize_fast<T>(), T>::doit(in, v, sz);
|
||||
}
|
||||
|
||||
template<typename T, typename Output>
|
||||
inline void serialize(Output& out, const std::vector<T>& v) {
|
||||
safe_serialize_as_uint32(out, v.size());
|
||||
serialize_array<T>(out, v);
|
||||
}
|
||||
template<typename T, typename Input>
|
||||
inline std::vector<T> deserialize(Input& in, boost::type<std::vector<T>>) {
|
||||
auto sz = deserialize(in, boost::type<uint32_t>());
|
||||
std::vector<T> v;
|
||||
v.reserve(sz);
|
||||
deserialize_array<T>(in, v, sz);
|
||||
return v;
|
||||
}
|
||||
template<typename T>
|
||||
struct serializer<std::vector<T>> {
|
||||
template<typename Input>
|
||||
static std::vector<T> read(Input& in) {
|
||||
auto sz = deserialize(in, boost::type<uint32_t>());
|
||||
std::vector<T> v;
|
||||
v.reserve(sz);
|
||||
deserialize_array<T>(in, v, sz);
|
||||
return v;
|
||||
}
|
||||
template<typename Output>
|
||||
static void write(Output& out, const std::vector<T>& v) {
|
||||
safe_serialize_as_uint32(out, v.size());
|
||||
serialize_array<T>(out, v);
|
||||
}
|
||||
template<typename Input>
|
||||
static void skip(Input& in) {
|
||||
auto ln = deserialize(in, boost::type<size_type>());
|
||||
for (size_type i = 0; i < ln; i++) {
|
||||
serializer<T>::skip(in);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename Ratio, typename Output>
|
||||
inline void serialize(Output& out, const std::chrono::duration<T, Ratio>& d) {
|
||||
|
||||
Reference in New Issue
Block a user