diff --git a/model/sync-digest.cc b/model/sync-digest.cc index f6ad110..a6f91f7 100644 --- a/model/sync-digest.cc +++ b/model/sync-digest.cc @@ -26,7 +26,16 @@ #include #include +// for printing, may be disabled in optimized build +#include +#include +#include + using namespace boost; +using namespace std; + +using namespace boost::archive::iterators; +typedef base64_from_binary > base64_t; namespace Sync { @@ -128,5 +137,27 @@ Digest::operator << (const Digest &src) } +std::ostream& +Digest::print (std::ostream &os) const +{ + BOOST_ASSERT (m_hashLength != 0); + + ostreambuf_iterator out_it (os); // ostream iterator + // need to encode to base64 + copy (base64_t (reinterpret_cast (m_buffer)), + base64_t (reinterpret_cast (m_buffer+m_hashLength)), + out_it); + + return os; +} + +std::ostream & +operator << (std::ostream &os, const Digest &digest) +{ + digest.print (os); + return os; +} + + } // Sync diff --git a/model/sync-digest.h b/model/sync-digest.h index adf4d96..7c7174c 100644 --- a/model/sync-digest.h +++ b/model/sync-digest.h @@ -96,6 +96,9 @@ public: // template // inline Digest & // operator << (INT value); + + std::ostream& + print (std::ostream &os) const; private: /** @@ -141,6 +144,9 @@ Digest::operator << (uint32_t value) return *this; } +std::ostream & +operator << (std::ostream &os, const Digest &digest); + // template // Digest & // Digest::operator << (INT value)