22
22
#include < vector>
23
23
24
24
#include < prevector.h>
25
+ #include < span.h>
25
26
26
27
static const unsigned int MAX_SIZE = 0x02000000 ;
27
28
@@ -41,7 +42,7 @@ constexpr deserialize_type deserialize {};
41
42
42
43
/* *
43
44
* Used to bypass the rule against non-const reference to temporary
44
- * where it makes sense with wrappers such as CFlatData or CTxDB
45
+ * where it makes sense with wrappers.
45
46
*/
46
47
template <typename T>
47
48
inline T& REF (const T& val)
@@ -185,6 +186,8 @@ template<typename Stream> inline void Serialize(Stream& s, float a ) { ser_wri
185
186
template <typename Stream> inline void Serialize (Stream& s, double a ) { ser_writedata64 (s, ser_double_to_uint64 (a)); }
186
187
template <typename Stream, int N> inline void Serialize (Stream& s, const char (&a)[N]) { s.write (a, N); }
187
188
template <typename Stream, int N> inline void Serialize (Stream& s, const unsigned char (&a)[N]) { s.write (CharCast (a), N); }
189
+ template <typename Stream> inline void Serialize (Stream& s, const Span<const unsigned char >& span) { s.write (CharCast (span.data ()), span.size ()); }
190
+ template <typename Stream> inline void Serialize (Stream& s, const Span<unsigned char >& span) { s.write (CharCast (span.data ()), span.size ()); }
188
191
189
192
template <typename Stream> inline void Unserialize (Stream& s, char & a ) { a = ser_readdata8 (s); } // TODO Get rid of bare char
190
193
template <typename Stream> inline void Unserialize (Stream& s, int8_t & a ) { a = ser_readdata8 (s); }
@@ -199,6 +202,7 @@ template<typename Stream> inline void Unserialize(Stream& s, float& a ) { a =
199
202
template <typename Stream> inline void Unserialize (Stream& s, double & a ) { a = ser_uint64_to_double (ser_readdata64 (s)); }
200
203
template <typename Stream, int N> inline void Unserialize (Stream& s, char (&a)[N]) { s.read (a, N); }
201
204
template <typename Stream, int N> inline void Unserialize (Stream& s, unsigned char (&a)[N]) { s.read (CharCast (a), N); }
205
+ template <typename Stream> inline void Unserialize (Stream& s, Span<unsigned char >& span) { s.read (CharCast (span.data ()), span.size ()); }
202
206
203
207
template <typename Stream> inline void Serialize (Stream& s, bool a) { char f=a; ser_writedata8 (s, f); }
204
208
template <typename Stream> inline void Unserialize (Stream& s, bool & a) { char f=ser_readdata8 (s); a=f; }
@@ -384,51 +388,10 @@ I ReadVarInt(Stream& is)
384
388
}
385
389
}
386
390
387
- #define FLATDATA (obj ) CFlatData((char *)&(obj), (char *)&(obj) + sizeof (obj))
388
391
#define VARINT (obj, ...) WrapVarInt<__VA_ARGS__>(REF(obj))
389
392
#define COMPACTSIZE (obj ) CCompactSize(REF(obj))
390
393
#define LIMITED_STRING (obj,n ) LimitedString< n >(REF(obj))
391
394
392
- /* *
393
- * Wrapper for serializing arrays and POD.
394
- */
395
- class CFlatData
396
- {
397
- protected:
398
- char * pbegin;
399
- char * pend;
400
- public:
401
- CFlatData (void * pbeginIn, void * pendIn) : pbegin((char *)pbeginIn), pend((char *)pendIn) { }
402
- template <class T , class TAl >
403
- explicit CFlatData (std::vector<T,TAl> &v)
404
- {
405
- pbegin = (char *)v.data ();
406
- pend = (char *)(v.data () + v.size ());
407
- }
408
- template <unsigned int N, typename T, typename S, typename D>
409
- explicit CFlatData (prevector<N, T, S, D> &v)
410
- {
411
- pbegin = (char *)v.data ();
412
- pend = (char *)(v.data () + v.size ());
413
- }
414
- char * begin () { return pbegin; }
415
- const char * begin () const { return pbegin; }
416
- char * end () { return pend; }
417
- const char * end () const { return pend; }
418
-
419
- template <typename Stream>
420
- void Serialize (Stream& s) const
421
- {
422
- s.write (pbegin, pend - pbegin);
423
- }
424
-
425
- template <typename Stream>
426
- void Unserialize (Stream& s)
427
- {
428
- s.read (pbegin, pend - pbegin);
429
- }
430
- };
431
-
432
395
template <VarIntMode Mode, typename I>
433
396
class CVarInt
434
397
{
0 commit comments