Skip to content

Commit

Permalink
Merge pull request #191 from AntelopeIO/larryk85/basic_string_fix
Browse files Browse the repository at this point in the history
add explicit overloads
  • Loading branch information
dimas1185 authored Jun 29, 2023
2 parents 09611db + c1c2f2b commit d2f7b3c
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions libraries/eosiolib/core/eosio/datastream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ datastream<Stream>& operator >> ( datastream<Stream>& ds, std::vector<T>& v ) {
}

/**
* Serialize a basic_string
* Serialize a basic_string<T>
*
* @param ds - The stream to write
* @param s - The value to serialize
Expand All @@ -783,7 +783,7 @@ datastream<Stream>& operator << ( datastream<Stream>& ds, const std::basic_strin
}

/**
* Deserialize a basic_string
* Deserialize a basic_string<T>
*
* @param ds - The stream to read
* @param s - The destination for deserialized value
Expand All @@ -800,6 +800,42 @@ datastream<Stream>& operator >> ( datastream<Stream>& ds, std::basic_string<T>&
return ds;
}

/**
* Serialize a basic_string<uint8_t>
*
* @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<Stream>& - Reference to the datastream
*/
template<typename Stream>
datastream<Stream>& operator << ( datastream<Stream>& ds, const std::basic_string<uint8_t>& s ) {
ds << unsigned_int(s.size());
if (s.size())
ds.write(s.data(), s.size());
return ds;
}

/**
* Deserialize a basic_string<uint8_t>
*
* @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<Stream>& - Reference to the datastream
*/
template<typename Stream>
datastream<Stream>& operator >> ( datastream<Stream>& ds, std::basic_string<uint8_t>& s ) {
unsigned_int v;
ds >> v;
s.resize(v.value);
ds.read(s.data(), s.size());
return ds;
}


/**
* Serialize a set
*
Expand Down

0 comments on commit d2f7b3c

Please sign in to comment.