From 1dcacbafc9e85552e8bd9b8b5082e1ce3364fe43 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 19 Aug 2018 18:26:46 +0200 Subject: [PATCH] Removed signed_int --- include/fc/io/raw.hpp | 21 ---------------- include/fc/io/raw_fwd.hpp | 3 --- include/fc/io/varint.hpp | 43 --------------------------------- include/fc/reflect/typename.hpp | 2 -- src/io/varint.cpp | 2 -- tests/io/varint_tests.cpp | 20 --------------- 6 files changed, 91 deletions(-) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index e254cd3..48811c2 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -158,16 +158,6 @@ namespace fc { fc::raw::unpack( s, *v, _max_depth - 1 ); } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr", ("type",fc::get_typename::name()) ) } - template 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 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 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 inline void unpack( Stream& s, unsigned_int& vi, uint32_t _max_depth ) { uint64_t v = 0; char b = 0; uint8_t by = 0; do { diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index 157a745..87a9208 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -116,9 +116,6 @@ namespace fc { template inline void pack( Stream& s, const std::vector& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, std::vector& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template inline void pack( Stream& s, const signed_int& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template inline void unpack( Stream& s, signed_int& vi, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, unsigned_int& vi, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); diff --git a/include/fc/io/varint.hpp b/include/fc/io/varint.hpp index fe8e82e..30e42bb 100644 --- a/include/fc/io/varint.hpp +++ b/include/fc/io/varint.hpp @@ -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 - 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 namespace std { - template<> - struct hash - { - public: - size_t operator()(const fc::signed_int &a) const - { - return std::hash()(a.value); - } - }; template<> struct hash { diff --git a/include/fc/reflect/typename.hpp b/include/fc/reflect/typename.hpp index 55695c2..7223d83 100644 --- a/include/fc/reflect/typename.hpp +++ b/include/fc/reflect/typename.hpp @@ -96,10 +96,8 @@ namespace fc { } }; - struct signed_int; struct unsigned_int; struct variant_object; - template<> struct get_typename { static const char* name() { return "signed_int"; } }; template<> struct get_typename { static const char* name() { return "unsigned_int"; } }; template<> struct get_typename { static const char* name() { return "fc::variant_object"; } }; diff --git a/src/io/varint.cpp b/src/io/varint.cpp index 6384eec..a5c6bbb 100644 --- a/src/io/varint.cpp +++ b/src/io/varint.cpp @@ -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(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(); } } diff --git a/tests/io/varint_tests.cpp b/tests/io/varint_tests.cpp index ea0ef58..1d5c67c 100644 --- a/tests/io/varint_tests.cpp +++ b/tests/io/varint_tests.cpp @@ -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 unpacked_s; - fc::raw::unpack( std::vector( 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 packed_s = fc::raw::pack( fc::signed_int(0x40000000), 3 ); - fc::signed_int tmp = fc::raw::unpack( packed_s, 3 ); - BOOST_CHECK_EQUAL( 0x40000000, tmp.value ); - } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END()