2222#include < vector>
2323
2424#include < prevector.h>
25+ #include < span.h>
2526
2627static const unsigned int MAX_SIZE = 0x02000000 ;
2728
@@ -41,7 +42,7 @@ constexpr deserialize_type deserialize {};
4142
4243/* *
4344 * 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.
4546 */
4647template <typename T>
4748inline T& REF (const T& val)
@@ -185,6 +186,8 @@ template<typename Stream> inline void Serialize(Stream& s, float a ) { ser_wri
185186template <typename Stream> inline void Serialize (Stream& s, double a ) { ser_writedata64 (s, ser_double_to_uint64 (a)); }
186187template <typename Stream, int N> inline void Serialize (Stream& s, const char (&a)[N]) { s.write (a, N); }
187188template <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 ()); }
188191
189192template <typename Stream> inline void Unserialize (Stream& s, char & a ) { a = ser_readdata8 (s); } // TODO Get rid of bare char
190193template <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 =
199202template <typename Stream> inline void Unserialize (Stream& s, double & a ) { a = ser_uint64_to_double (ser_readdata64 (s)); }
200203template <typename Stream, int N> inline void Unserialize (Stream& s, char (&a)[N]) { s.read (a, N); }
201204template <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 ()); }
202206
203207template <typename Stream> inline void Serialize (Stream& s, bool a) { char f=a; ser_writedata8 (s, f); }
204208template <typename Stream> inline void Unserialize (Stream& s, bool & a) { char f=ser_readdata8 (s); a=f; }
@@ -384,51 +388,10 @@ I ReadVarInt(Stream& is)
384388 }
385389}
386390
387- #define FLATDATA (obj ) CFlatData((char *)&(obj), (char *)&(obj) + sizeof (obj))
388391#define VARINT (obj, ...) WrapVarInt<__VA_ARGS__>(REF(obj))
389392#define COMPACTSIZE (obj ) CCompactSize(REF(obj))
390393#define LIMITED_STRING (obj,n ) LimitedString< n >(REF(obj))
391394
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-
432395template <VarIntMode Mode, typename I>
433396class CVarInt
434397{
0 commit comments