Skip to content

Commit 5249dac

Browse files
committed
Add COMPACTSIZE wrapper similar to VARINT for serialization
1 parent cbda71c commit 5249dac

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/serialize.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ I ReadVarInt(Stream& is)
373373

374374
#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
375375
#define VARINT(obj) REF(WrapVarInt(REF(obj)))
376+
#define COMPACTSIZE(obj) REF(CCompactSize(REF(obj)))
376377
#define LIMITED_STRING(obj,n) REF(LimitedString< n >(REF(obj)))
377378

378379
/**
@@ -443,6 +444,28 @@ class CVarInt
443444
}
444445
};
445446

447+
class CCompactSize
448+
{
449+
protected:
450+
uint64_t &n;
451+
public:
452+
CCompactSize(uint64_t& nIn) : n(nIn) { }
453+
454+
unsigned int GetSerializeSize(int, int) const {
455+
return GetSizeOfCompactSize(n);
456+
}
457+
458+
template<typename Stream>
459+
void Serialize(Stream &s, int, int) const {
460+
WriteCompactSize<Stream>(s, n);
461+
}
462+
463+
template<typename Stream>
464+
void Unserialize(Stream& s, int, int) {
465+
n = ReadCompactSize<Stream>(s);
466+
}
467+
};
468+
446469
template<size_t Limit>
447470
class LimitedString
448471
{

0 commit comments

Comments
 (0)