mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Add COMPACTSIZE wrapper similar to VARINT for serialization
This commit is contained in:
parent
cbda71cf04
commit
5249daca5a
@ -373,6 +373,7 @@ I ReadVarInt(Stream& is)
|
|||||||
|
|
||||||
#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
|
#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
|
||||||
#define VARINT(obj) REF(WrapVarInt(REF(obj)))
|
#define VARINT(obj) REF(WrapVarInt(REF(obj)))
|
||||||
|
#define COMPACTSIZE(obj) REF(CCompactSize(REF(obj)))
|
||||||
#define LIMITED_STRING(obj,n) REF(LimitedString< n >(REF(obj)))
|
#define LIMITED_STRING(obj,n) REF(LimitedString< n >(REF(obj)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -443,6 +444,28 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CCompactSize
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
uint64_t &n;
|
||||||
|
public:
|
||||||
|
CCompactSize(uint64_t& nIn) : n(nIn) { }
|
||||||
|
|
||||||
|
unsigned int GetSerializeSize(int, int) const {
|
||||||
|
return GetSizeOfCompactSize(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Serialize(Stream &s, int, int) const {
|
||||||
|
WriteCompactSize<Stream>(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Unserialize(Stream& s, int, int) {
|
||||||
|
n = ReadCompactSize<Stream>(s);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<size_t Limit>
|
template<size_t Limit>
|
||||||
class LimitedString
|
class LimitedString
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user