Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 704 Lines • ▼ Show 20 Lines | |||||
* string | * string | ||||
*/ | */ | ||||
template <typename Stream, typename C> | template <typename Stream, typename C> | ||||
void Serialize(Stream &os, const std::basic_string<C> &str); | void Serialize(Stream &os, const std::basic_string<C> &str); | ||||
template <typename Stream, typename C> | template <typename Stream, typename C> | ||||
void Unserialize(Stream &is, std::basic_string<C> &str); | void Unserialize(Stream &is, std::basic_string<C> &str); | ||||
/** | /** | ||||
* string_view | |||||
*/ | |||||
template <typename Stream, typename C> | |||||
void Serialize(Stream &os, const std::basic_string_view<C> &str); | |||||
template <typename Stream, typename C> | |||||
void Unserialize(Stream &is, std::basic_string_view<C> &str); | |||||
/** | |||||
* prevector | * prevector | ||||
* prevectors of uint8_t are a special case and are intended to be serialized as | * prevectors of uint8_t are a special case and are intended to be serialized as | ||||
* a single opaque blob. | * a single opaque blob. | ||||
*/ | */ | ||||
template <typename Stream, unsigned int N, typename T> | template <typename Stream, unsigned int N, typename T> | ||||
void Serialize_impl(Stream &os, const prevector<N, T> &v, const uint8_t &); | void Serialize_impl(Stream &os, const prevector<N, T> &v, const uint8_t &); | ||||
template <typename Stream, unsigned int N, typename T, typename V> | template <typename Stream, unsigned int N, typename T, typename V> | ||||
void Serialize_impl(Stream &os, const prevector<N, T> &v, const V &); | void Serialize_impl(Stream &os, const prevector<N, T> &v, const V &); | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | void Unserialize(Stream &is, std::basic_string<C> &str) { | ||||
size_t nSize = ReadCompactSize(is); | size_t nSize = ReadCompactSize(is); | ||||
str.resize(nSize); | str.resize(nSize); | ||||
if (nSize != 0) { | if (nSize != 0) { | ||||
is.read((char *)str.data(), nSize * sizeof(C)); | is.read((char *)str.data(), nSize * sizeof(C)); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* string_view | |||||
*/ | |||||
template <typename Stream, typename C> | |||||
void Serialize(Stream &os, const std::basic_string_view<C> &str) { | |||||
WriteCompactSize(os, str.size()); | |||||
if (!str.empty()) { | |||||
os.write((char *)str.data(), str.size() * sizeof(C)); | |||||
} | |||||
} | |||||
template <typename Stream, typename C> | |||||
void Unserialize(Stream &is, std::basic_string_view<C> &str) { | |||||
size_t nSize = ReadCompactSize(is); | |||||
str.resize(nSize); | |||||
if (nSize != 0) { | |||||
is.read((char *)str.data(), nSize * sizeof(C)); | |||||
} | |||||
} | |||||
/** | |||||
* prevector | * prevector | ||||
*/ | */ | ||||
template <typename Stream, unsigned int N, typename T> | template <typename Stream, unsigned int N, typename T> | ||||
void Serialize_impl(Stream &os, const prevector<N, T> &v, const uint8_t &) { | void Serialize_impl(Stream &os, const prevector<N, T> &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)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 305 Lines • Show Last 20 Lines |