@@ -158,16 +158,6 @@ namespace fc {
158
158
fc::raw::unpack ( s, *v, _max_depth - 1 );
159
159
} FC_RETHROW_EXCEPTIONS ( warn, " std::shared_ptr<T>" , (" type" ,fc::get_typename<T>::name ()) ) }
160
160
161
- template <typename Stream> inline void pack ( Stream& s, const signed_int& v, uint32_t _max_depth ) {
162
- uint32_t val = (v.value <<1 ) ^ (v.value >>31 );
163
- do {
164
- uint8_t b = uint8_t (val) & 0x7f ;
165
- val >>= 7 ;
166
- b |= ((val > 0 ) << 7 );
167
- s.write ((char *)&b,1 );// .put(b);
168
- } while ( val );
169
- }
170
-
171
161
template <typename Stream> inline void pack ( Stream& s, const unsigned_int& v, uint32_t _max_depth ) {
172
162
uint64_t val = v.value ;
173
163
do {
@@ -178,25 +168,16 @@ namespace fc {
178
168
}while ( val );
179
169
}
180
170
181
- template <typename Stream> inline void unpack ( Stream& s, signed_int& vi, uint32_t _max_depth ) {
182
- uint32_t v = 0 ; char b = 0 ; int by = 0 ;
183
- do {
184
- s.get (b);
185
- v |= uint32_t (uint8_t (b) & 0x7f ) << by;
186
- by += 7 ;
187
- } while ( uint8_t (b) & 0x80 );
188
- vi.value = ((v>>1 ) ^ (v>>31 )) + (v&0x01 );
189
- vi.value = v&0x01 ? vi.value : -vi.value ;
190
- vi.value = -vi.value ;
191
- }
192
171
template <typename Stream> inline void unpack ( Stream& s, unsigned_int& vi, uint32_t _max_depth ) {
193
172
uint64_t v = 0 ; char b = 0 ; uint8_t by = 0 ;
194
173
do {
195
174
s.get (b);
196
- v |= uint32_t (uint8_t (b) & 0x7f ) << by;
175
+ if ( by >= 64 || (by == 63 && uint8_t (b) > 1 ) )
176
+ FC_THROW_EXCEPTION ( overflow_exception, " Invalid packed unsigned_int!" );
177
+ v |= uint64_t (uint8_t (b) & 0x7f ) << by;
197
178
by += 7 ;
198
179
} while ( uint8_t (b) & 0x80 );
199
- vi.value = static_cast <uint32_t >(v);
180
+ vi.value = static_cast <uint64_t >(v);
200
181
}
201
182
202
183
template <typename Stream, typename T> inline void unpack ( Stream& s, const T& vi, uint32_t _max_depth )
@@ -273,9 +254,9 @@ namespace fc {
273
254
// std::vector<char>
274
255
template <typename Stream> inline void pack ( Stream& s, const std::vector<char >& value, uint32_t _max_depth ) {
275
256
FC_ASSERT ( _max_depth > 0 );
276
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth - 1 );
257
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth - 1 );
277
258
if ( value.size () )
278
- s.write ( &value.front (), ( uint32_t ) value.size () );
259
+ s.write ( &value.front (), value.size () );
279
260
}
280
261
template <typename Stream> inline void unpack ( Stream& s, std::vector<char >& value, uint32_t _max_depth ) {
281
262
FC_ASSERT ( _max_depth > 0 );
@@ -289,7 +270,7 @@ namespace fc {
289
270
// fc::string
290
271
template <typename Stream> inline void pack ( Stream& s, const fc::string& v, uint32_t _max_depth ) {
291
272
FC_ASSERT ( _max_depth > 0 );
292
- fc::raw::pack ( s, unsigned_int (( uint32_t ) v.size ()), _max_depth - 1 );
273
+ fc::raw::pack ( s, unsigned_int (v.size ()), _max_depth - 1 );
293
274
if ( v.size () ) s.write ( v.c_str (), v.size () );
294
275
}
295
276
@@ -433,7 +414,7 @@ namespace fc {
433
414
inline void pack ( Stream& s, const std::unordered_set<T>& value, uint32_t _max_depth ) {
434
415
FC_ASSERT ( _max_depth > 0 );
435
416
--_max_depth;
436
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth );
417
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth );
437
418
auto itr = value.begin ();
438
419
auto end = value.end ();
439
420
while ( itr != end ) {
@@ -478,7 +459,7 @@ namespace fc {
478
459
inline void pack ( Stream& s, const std::unordered_map<K,V>& value, uint32_t _max_depth ) {
479
460
FC_ASSERT ( _max_depth > 0 );
480
461
--_max_depth;
481
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth );
462
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth );
482
463
auto itr = value.begin ();
483
464
auto end = value.end ();
484
465
while ( itr != end ) {
@@ -506,7 +487,7 @@ namespace fc {
506
487
inline void pack ( Stream& s, const std::map<K,V>& value, uint32_t _max_depth ) {
507
488
FC_ASSERT ( _max_depth > 0 );
508
489
--_max_depth;
509
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth );
490
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth );
510
491
auto itr = value.begin ();
511
492
auto end = value.end ();
512
493
while ( itr != end ) {
@@ -534,7 +515,7 @@ namespace fc {
534
515
inline void pack ( Stream& s, const std::deque<T>& value, uint32_t _max_depth ) {
535
516
FC_ASSERT ( _max_depth > 0 );
536
517
--_max_depth;
537
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth );
518
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth );
538
519
auto itr = value.begin ();
539
520
auto end = value.end ();
540
521
while ( itr != end ) {
@@ -562,7 +543,7 @@ namespace fc {
562
543
inline void pack ( Stream& s, const std::vector<T>& value, uint32_t _max_depth ) {
563
544
FC_ASSERT ( _max_depth > 0 );
564
545
--_max_depth;
565
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth );
546
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth );
566
547
auto itr = value.begin ();
567
548
auto end = value.end ();
568
549
while ( itr != end ) {
@@ -590,7 +571,7 @@ namespace fc {
590
571
inline void pack ( Stream& s, const std::set<T>& value, uint32_t _max_depth ) {
591
572
FC_ASSERT ( _max_depth > 0 );
592
573
--_max_depth;
593
- fc::raw::pack ( s, unsigned_int (( uint32_t ) value.size ()), _max_depth );
574
+ fc::raw::pack ( s, unsigned_int (value.size ()), _max_depth );
594
575
auto itr = value.begin ();
595
576
auto end = value.end ();
596
577
while ( itr != end ) {
0 commit comments