diff --git a/libraries/eosiolib/core/eosio/datastream.hpp b/libraries/eosiolib/core/eosio/datastream.hpp index 571d7236cb..7b9cb4e75c 100644 --- a/libraries/eosiolib/core/eosio/datastream.hpp +++ b/libraries/eosiolib/core/eosio/datastream.hpp @@ -766,7 +766,7 @@ datastream& operator >> ( datastream& ds, std::vector& v ) { } /** - * Serialize a basic_string + * Serialize a basic_string * * @param ds - The stream to write * @param s - The value to serialize @@ -783,7 +783,7 @@ datastream& operator << ( datastream& ds, const std::basic_strin } /** - * Deserialize a basic_string + * Deserialize a basic_string * * @param ds - The stream to read * @param s - The destination for deserialized value @@ -800,6 +800,42 @@ datastream& operator >> ( datastream& ds, std::basic_string& return ds; } +/** + * Serialize a basic_string + * + * @param ds - The stream to write + * @param s - The value to serialize + * @tparam Stream - Type of datastream buffer + * @tparam T - Type of the object contained in the basic_string + * @return datastream& - Reference to the datastream + */ +template +datastream& operator << ( datastream& ds, const std::basic_string& s ) { + ds << unsigned_int(s.size()); + if (s.size()) + ds.write(s.data(), s.size()); + return ds; +} + +/** + * Deserialize a basic_string + * + * @param ds - The stream to read + * @param s - The destination for deserialized value + * @tparam Stream - Type of datastream buffer + * @tparam T - Type of the object contained in the basic_string + * @return datastream& - Reference to the datastream + */ +template +datastream& operator >> ( datastream& ds, std::basic_string& s ) { + unsigned_int v; + ds >> v; + s.resize(v.value); + ds.read(s.data(), s.size()); + return ds; +} + + /** * Serialize a set *