extra raw io helpers

This commit is contained in:
Daniel Larimer 2015-02-11 18:27:33 -05:00
parent 323d59b054
commit 057861c608
3 changed files with 13 additions and 2 deletions

View file

@ -2,6 +2,7 @@
#include <fc/fwd.hpp> #include <fc/fwd.hpp>
#include <fc/string.hpp> #include <fc/string.hpp>
#include <fc/reflect/typename.hpp> #include <fc/reflect/typename.hpp>
#include <fc/io/raw_fwd.hpp>
namespace fc{ namespace fc{
@ -28,7 +29,7 @@ class ripemd160
static ripemd160 hash( const T& t ) static ripemd160 hash( const T& t )
{ {
ripemd160::encoder e; ripemd160::encoder e;
e << t; fc::raw::pack(e,t);
return e.result(); return e.result();
} }

View file

@ -2,6 +2,7 @@
#include <fc/fwd.hpp> #include <fc/fwd.hpp>
#include <fc/string.hpp> #include <fc/string.hpp>
#include <fc/platform_independence.hpp> #include <fc/platform_independence.hpp>
#include <fc/io/raw_fwd.hpp>
namespace fc namespace fc
{ {
@ -25,7 +26,7 @@ class sha256
static sha256 hash( const T& t ) static sha256 hash( const T& t )
{ {
sha256::encoder e; sha256::encoder e;
e << t; fc::raw::pack(e,t);
return e.result(); return e.result();
} }

View file

@ -486,6 +486,15 @@ namespace fc {
return tmp; return tmp;
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) } } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
template<typename T>
inline void unpack( const std::vector<char>& s, T& tmp )
{ try {
if( s.size() ) {
datastream<const char*> ds( s.data(), size_t(s.size()) );
raw::unpack(ds,tmp);
}
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
template<typename T> template<typename T>
inline void pack( char* d, uint32_t s, const T& v ) { inline void pack( char* d, uint32_t s, const T& v ) {
datastream<char*> ds(d,s); datastream<char*> ds(d,s);