util: Add bytes version of serialize_string

This commit is contained in:
Asias He
2015-03-16 15:47:07 +08:00
committed by Tomasz Grabiec
parent b9a67c6d67
commit 2e24dc93f4

View File

@@ -219,6 +219,20 @@ void serialize_string(std::ostream& out, const sstring& s) {
out.write(s.c_str(), s.size());
}
inline
void serialize_string(bytes::iterator& out, const sstring& s) {
for (char c : s) {
if (c == '\0') {
throw UTFDataFormatException();
}
}
if (s.size() > std::numeric_limits<uint16_t>::max()) {
throw UTFDataFormatException();
}
serialize_int16(out, (uint16_t) s.size());
out = std::copy(s.begin(), s.end(), out);
}
inline
size_t serialize_string_size(const sstring& s) {;
// As above, this code is missing the case of modified utf-8