diff --git a/src/basic_type/string_serializer.h b/src/basic_type/string_serializer.h index 8241747..a73d982 100644 --- a/src/basic_type/string_serializer.h +++ b/src/basic_type/string_serializer.h @@ -14,30 +14,15 @@ class Serializer { static void serialize(const std::string& str, OutputBuffer& ob) { const size_t n_bytes = str.size(); Serializer::serialize(n_bytes, ob); - ob.write(str.c_str(), n_bytes); + ob.write(str.data(), n_bytes); } static void parse(std::string& str, InputBuffer& ib) { size_t n_bytes; Serializer::parse(n_bytes, ib); - char buf[PARSE_BUFFER_SIZE]; - str.clear(); - str.reserve(n_bytes); - while (n_bytes > 0) { - if (n_bytes > PARSE_BUFFER_SIZE) { - ib.read(buf, PARSE_BUFFER_SIZE); - str.append(buf, PARSE_BUFFER_SIZE); - n_bytes -= PARSE_BUFFER_SIZE; - } else { - ib.read(buf, n_bytes); - str.append(buf, n_bytes); - n_bytes = 0; - } - } + str.resize(n_bytes); + ib.read(&str[0], n_bytes); } - - private: - constexpr static size_t PARSE_BUFFER_SIZE = 1 << 10; }; } // namespace hps