Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0 -> main] add explicit overloads #227

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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