From 2e24dc93f43759cf08bbf6382e54695f45ca328d Mon Sep 17 00:00:00 2001 From: Asias He Date: Mon, 16 Mar 2015 15:47:07 +0800 Subject: [PATCH] util: Add bytes version of serialize_string --- util/serialization.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/serialization.hh b/util/serialization.hh index 855e527592..206774c56a 100644 --- a/util/serialization.hh +++ b/util/serialization.hh @@ -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::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