Skip to content

Commit 6f19971

Browse files
TheBlueMattcodablock
authored andcommitted
Add COMPACTSIZE wrapper similar to VARINT for serialization
1 parent fc5ced3 commit 6f19971

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
@@ -386,6 +386,7 @@ I ReadVarInt(Stream& is)
386386

387387
#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
388388
#define VARINT(obj) REF(WrapVarInt(REF(obj)))
389+
#define COMPACTSIZE(obj) REF(CCompactSize(REF(obj)))
389390
#define LIMITED_STRING(obj,n) REF(LimitedString< n >(REF(obj)))
390391

391392
/**
@@ -456,6 +457,28 @@ class CVarInt
456457
}
457458
};
458459

460+
class CCompactSize
461+
{
462+
protected:
463+
uint64_t &n;
464+
public:
465+
CCompactSize(uint64_t& nIn) : n(nIn) { }
466+
467+
unsigned int GetSerializeSize(int, int) const {
468+
return GetSizeOfCompactSize(n);
469+
}
470+
471+
template<typename Stream>
472+
void Serialize(Stream &s, int, int) const {
473+
WriteCompactSize<Stream>(s, n);
474+
}
475+
476+
template<typename Stream>
477+
void Unserialize(Stream& s, int, int) {
478+
n = ReadCompactSize<Stream>(s);
479+
}
480+
};
481+
459482
template<size_t Limit>
460483
class LimitedString
461484
{

0 commit comments

Comments
 (0)