Removed signed_int
This commit is contained in:
parent
4b61f3ca3d
commit
1dcacbafc9
6 changed files with 0 additions and 91 deletions
|
|
@ -158,16 +158,6 @@ namespace fc {
|
|||
fc::raw::unpack( s, *v, _max_depth - 1 );
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<T>", ("type",fc::get_typename<T>::name()) ) }
|
||||
|
||||
template<typename Stream> inline void pack( Stream& s, const signed_int& v, uint32_t _max_depth ) {
|
||||
uint32_t val = (v.value<<1) ^ (v.value>>31);
|
||||
do {
|
||||
uint8_t b = uint8_t(val) & 0x7f;
|
||||
val >>= 7;
|
||||
b |= ((val > 0) << 7);
|
||||
s.write((char*)&b,1);//.put(b);
|
||||
} while( val );
|
||||
}
|
||||
|
||||
template<typename Stream> inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth ) {
|
||||
uint64_t val = v.value;
|
||||
do {
|
||||
|
|
@ -178,17 +168,6 @@ namespace fc {
|
|||
}while( val );
|
||||
}
|
||||
|
||||
template<typename Stream> inline void unpack( Stream& s, signed_int& vi, uint32_t _max_depth ) {
|
||||
uint32_t v = 0; char b = 0; int by = 0;
|
||||
do {
|
||||
s.get(b);
|
||||
v |= uint32_t(uint8_t(b) & 0x7f) << by;
|
||||
by += 7;
|
||||
} while( (uint8_t(b) & 0x80) && by < 32 );
|
||||
vi.value = ((v>>1) ^ (v>>31)) + (v&0x01);
|
||||
vi.value = v&0x01 ? vi.value : -vi.value;
|
||||
vi.value = -vi.value;
|
||||
}
|
||||
template<typename Stream> inline void unpack( Stream& s, unsigned_int& vi, uint32_t _max_depth ) {
|
||||
uint64_t v = 0; char b = 0; uint8_t by = 0;
|
||||
do {
|
||||
|
|
|
|||
|
|
@ -116,9 +116,6 @@ namespace fc {
|
|||
template<typename Stream, typename T> inline void pack( Stream& s, const std::vector<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> inline void unpack( Stream& s, std::vector<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
||||
template<typename Stream> inline void pack( Stream& s, const signed_int& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream> inline void unpack( Stream& s, signed_int& vi, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
||||
template<typename Stream> inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream> inline void unpack( Stream& s, unsigned_int& vi, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
||||
|
|
|
|||
|
|
@ -33,42 +33,8 @@ struct unsigned_int {
|
|||
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief serializes a 32 bit signed interger in as few bytes as possible
|
||||
*
|
||||
* Uses the google protobuf algorithm for seralizing signed numbers
|
||||
*/
|
||||
struct signed_int {
|
||||
signed_int( int32_t v = 0 ):value(v){}
|
||||
operator int32_t()const { return value; }
|
||||
template<typename T>
|
||||
signed_int& operator=( const T& v ) { value = v; return *this; }
|
||||
signed_int operator++(int) { return value++; }
|
||||
signed_int& operator++(){ ++value; return *this; }
|
||||
|
||||
int32_t value;
|
||||
|
||||
friend bool operator==( const signed_int& i, const int32_t& v ) { return i.value == v; }
|
||||
friend bool operator==( const int32_t& i, const signed_int& v ) { return i == v.value; }
|
||||
friend bool operator==( const signed_int& i, const signed_int& v ) { return i.value == v.value; }
|
||||
|
||||
friend bool operator!=( const signed_int& i, const int32_t& v ) { return i.value != v; }
|
||||
friend bool operator!=( const int32_t& i, const signed_int& v ) { return i != v.value; }
|
||||
friend bool operator!=( const signed_int& i, const signed_int& v ) { return i.value != v.value; }
|
||||
|
||||
friend bool operator<( const signed_int& i, const int32_t& v ) { return i.value < v; }
|
||||
friend bool operator<( const int32_t& i, const signed_int& v ) { return i < v.value; }
|
||||
friend bool operator<( const signed_int& i, const signed_int& v ) { return i.value < v.value; }
|
||||
|
||||
friend bool operator>=( const signed_int& i, const int32_t& v ) { return i.value >= v; }
|
||||
friend bool operator>=( const int32_t& i, const signed_int& v ) { return i >= v.value; }
|
||||
friend bool operator>=( const signed_int& i, const signed_int& v ) { return i.value >= v.value; }
|
||||
};
|
||||
|
||||
class variant;
|
||||
|
||||
void to_variant( const signed_int& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, signed_int& vo, uint32_t max_depth = 1 );
|
||||
void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth = 1 );
|
||||
|
||||
|
|
@ -77,15 +43,6 @@ void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth = 1
|
|||
#include <unordered_map>
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<fc::signed_int>
|
||||
{
|
||||
public:
|
||||
size_t operator()(const fc::signed_int &a) const
|
||||
{
|
||||
return std::hash<int32_t>()(a.value);
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct hash<fc::unsigned_int>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -96,10 +96,8 @@ namespace fc {
|
|||
}
|
||||
};
|
||||
|
||||
struct signed_int;
|
||||
struct unsigned_int;
|
||||
struct variant_object;
|
||||
template<> struct get_typename<signed_int> { static const char* name() { return "signed_int"; } };
|
||||
template<> struct get_typename<unsigned_int> { static const char* name() { return "unsigned_int"; } };
|
||||
template<> struct get_typename<variant_object> { static const char* name() { return "fc::variant_object"; } };
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
namespace fc
|
||||
{
|
||||
void to_variant( const signed_int& var, variant& vo, uint32_t max_depth ) { vo = var.value; }
|
||||
void from_variant( const variant& var, signed_int& vo, uint32_t max_depth ) { vo.value = static_cast<int32_t>(var.as_int64()); }
|
||||
void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth ) { vo = var.value; }
|
||||
void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth ) { vo.value = var.as_uint64(); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,26 +99,6 @@ BOOST_AUTO_TEST_CASE( test_limits )
|
|||
BOOST_CHECK_EQUAL( 0x4000000000000000ULL, unpacked_u[1].value );
|
||||
BOOST_CHECK_EQUAL( 0x8000000000000000ULL, unpacked_u[2].value );
|
||||
BOOST_CHECK_EQUAL( 0xc000000000000000ULL, unpacked_u[3].value );
|
||||
|
||||
/* Hm, seems that signed_int is broken, see below
|
||||
static const std::string PACKED_S = "\04"
|
||||
"\200\1"
|
||||
"\200\200\200\200\04"
|
||||
"\200\200\200\200\210" // not terminated
|
||||
"\200\200\200\200\214"; // not terminated
|
||||
std::vector<fc::signed_int> unpacked_s;
|
||||
fc::raw::unpack( std::vector<char>( PACKED_S.begin(), PACKED_S.end() ), unpacked_s, 3 );
|
||||
BOOST_REQUIRE_EQUAL( 4, unpacked_s.size() );
|
||||
BOOST_CHECK_EQUAL( 0x40, unpacked_s[0].value );
|
||||
BOOST_CHECK_EQUAL( 0x20000000, unpacked_s[1].value );
|
||||
BOOST_CHECK_EQUAL( 0x40000000, unpacked_s[2].value );
|
||||
BOOST_CHECK_EQUAL( 0x60000000, unpacked_s[3].value );
|
||||
*/
|
||||
|
||||
std::vector<char> packed_s = fc::raw::pack( fc::signed_int(0x40000000), 3 );
|
||||
fc::signed_int tmp = fc::raw::unpack<fc::signed_int>( packed_s, 3 );
|
||||
BOOST_CHECK_EQUAL( 0x40000000, tmp.value );
|
||||
|
||||
} FC_LOG_AND_RETHROW() }
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
|||
Loading…
Reference in a new issue