Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 647 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* vector | * vector | ||||
* vectors of uint8_t are a special case and are intended to be serialized as a | * vectors of uint8_t are a special case and are intended to be serialized as a | ||||
* single opaque blob. | * single opaque blob. | ||||
*/ | */ | ||||
template <typename Stream, typename T, typename A> | template <typename Stream, typename T, typename A> | ||||
void Serialize_impl(Stream &os, const std::vector<T, A> &v, const uint8_t &); | void Serialize_impl(Stream &os, const std::vector<T, A> &v, const uint8_t &); | ||||
template <typename Stream, typename T, typename A> | |||||
void Serialize_impl(Stream &os, const std::vector<T, A> &v, const bool &); | |||||
template <typename Stream, typename T, typename A, typename V> | template <typename Stream, typename T, typename A, typename V> | ||||
void Serialize_impl(Stream &os, const std::vector<T, A> &v, const V &); | void Serialize_impl(Stream &os, const std::vector<T, A> &v, const V &); | ||||
template <typename Stream, typename T, typename A> | template <typename Stream, typename T, typename A> | ||||
inline void Serialize(Stream &os, const std::vector<T, A> &v); | inline void Serialize(Stream &os, const std::vector<T, A> &v); | ||||
template <typename Stream, typename T, typename A> | template <typename Stream, typename T, typename A> | ||||
void Unserialize_impl(Stream &is, std::vector<T, A> &v, const uint8_t &); | void Unserialize_impl(Stream &is, std::vector<T, A> &v, const uint8_t &); | ||||
template <typename Stream, typename T, typename A, typename V> | template <typename Stream, typename T, typename A, typename V> | ||||
void Unserialize_impl(Stream &is, std::vector<T, A> &v, const V &); | void Unserialize_impl(Stream &is, std::vector<T, A> &v, const V &); | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | |||||
template <typename Stream, typename T, typename A> | template <typename Stream, typename T, typename A> | ||||
void Serialize_impl(Stream &os, const std::vector<T, A> &v, const uint8_t &) { | void Serialize_impl(Stream &os, const std::vector<T, A> &v, const uint8_t &) { | ||||
WriteCompactSize(os, v.size()); | WriteCompactSize(os, v.size()); | ||||
if (!v.empty()) { | if (!v.empty()) { | ||||
os.write((char *)v.data(), v.size() * sizeof(T)); | os.write((char *)v.data(), v.size() * sizeof(T)); | ||||
} | } | ||||
} | } | ||||
template <typename Stream, typename T, typename A> | |||||
void Serialize_impl(Stream &os, const std::vector<T, A> &v, const bool &) { | |||||
// A special case for std::vector<bool>, as dereferencing | |||||
// std::vector<bool>::const_iterator does not result in a const bool& | |||||
// due to std::vector's special casing for bool arguments. | |||||
WriteCompactSize(os, v.size()); | |||||
for (bool elem : v) { | |||||
::Serialize(os, elem); | |||||
} | |||||
} | |||||
template <typename Stream, typename T, typename A, typename V> | template <typename Stream, typename T, typename A, typename V> | ||||
void Serialize_impl(Stream &os, const std::vector<T, A> &v, const V &) { | void Serialize_impl(Stream &os, const std::vector<T, A> &v, const V &) { | ||||
WriteCompactSize(os, v.size()); | WriteCompactSize(os, v.size()); | ||||
for (const T &i : v) { | for (const T &i : v) { | ||||
::Serialize(os, i); | ::Serialize(os, i); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |