mdbx++: add to_hex/to_base58/to_base64::output(std::ostream&) without using temporary objects/buffers/strings.

Change-Id: Ideffd0e7f450307e14d780dcdeb2458c1c7e4c18
This commit is contained in:
Leonid Yuriev
2022-01-15 17:48:35 +03:00
parent b139d8165b
commit b5b0a9a284
2 changed files with 139 additions and 3 deletions

View File

@@ -1146,6 +1146,11 @@ struct LIBMDBX_API to_hex {
/// \throws std::length_error if given buffer is too small.
char *write_bytes(char *dest, size_t dest_size) const;
/// \brief Output hexadecimal dump of passed slice to the std::ostream.
/// \throws std::ios_base::failure corresponding to std::ostream::write()
/// behaviour.
::std::ostream &output(::std::ostream &out) const;
/// \brief Checks whether a passed slice is empty,
/// and therefore there will be no output bytes.
bool is_empty() const noexcept { return source.empty(); }
@@ -1195,6 +1200,12 @@ struct LIBMDBX_API to_base58 {
/// \throws std::length_error if given buffer is too small.
char *write_bytes(char *dest, size_t dest_size) const;
/// \brief Output [Base58](https://en.wikipedia.org/wiki/Base58)
/// dump of passed slice to the std::ostream.
/// \throws std::ios_base::failure corresponding to std::ostream::write()
/// behaviour.
::std::ostream &output(::std::ostream &out) const;
/// \brief Checks whether a passed slice is empty,
/// and therefore there will be no output bytes.
bool is_empty() const noexcept { return source.empty(); }
@@ -1243,6 +1254,12 @@ struct LIBMDBX_API to_base64 {
/// \throws std::length_error if given buffer is too small.
char *write_bytes(char *dest, size_t dest_size) const;
/// \brief Output [Base64](https://en.wikipedia.org/wiki/Base64)
/// dump of passed slice to the std::ostream.
/// \throws std::ios_base::failure corresponding to std::ostream::write()
/// behaviour.
::std::ostream &output(::std::ostream &out) const;
/// \brief Checks whether a passed slice is empty,
/// and therefore there will be no output bytes.
bool is_empty() const noexcept { return source.empty(); }
@@ -1253,15 +1270,15 @@ struct LIBMDBX_API to_base64 {
};
inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) {
return out << wrapper.as_string();
return wrapper.output(out);
}
inline ::std::ostream &operator<<(::std::ostream &out,
const to_base58 &wrapper) {
return out << wrapper.as_string();
return wrapper.output(out);
}
inline ::std::ostream &operator<<(::std::ostream &out,
const to_base64 &wrapper) {
return out << wrapper.as_string();
return wrapper.output(out);
}
/// \brief Hexadecimal decoder which satisfy \ref SliceTranscoder concept.