Skip to content

Commit

Permalink
Add COMPACTSIZE wrapper similar to VARINT for serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Jun 19, 2016
1 parent cbda71c commit 5249dac
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ I ReadVarInt(Stream& is)

#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(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)))

/**
Expand Down Expand Up @@ -443,6 +444,28 @@ class CVarInt
}
};

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>
class LimitedString
{
Expand Down

0 comments on commit 5249dac

Please sign in to comment.