Serialize unsigned 32-bit integer to a hzChain. Returns: None
| Return Type | Function name | Arguments |
|---|---|---|
| void | WriteSerialUINT32 | (hzChain&,uint32_t&,uint32_t,) |
Declared in file: hzCodec.h
Defined in file : hzCodec.cpp
Function Logic:
Function body:
void WriteSerialUINT32 (hzChain& Z)uint32_t& nLen, uint32_t nValue,
{
// Category: Number Serialization
//
// Serialize unsigned 32-bit integer to a hzChain.
//
// Arguments: 1) Z Chain appended by the length indicator
// 2) nLen The size of the indicator itself (set by this function)
// 3) nValue Indicated length or value
//
// Returns: None
if (nValue < 0x80)
{
// Bit 0 is 0, bits 1-7 are the value
nLen = 1;
Z.AddByte(nValue & 0x7f);
}
else if (nValue < 0x2000)
{
// 100xxxxx: 2 byte value
nLen = 2;
Z.AddByte(0x80+((nValue&0x1f00)>>8));
Z.AddByte(nValue & 0xff);
}
else if (nValue < 0x200000)
{
// 101xxxxx: 3 byte value
nLen = 3;
Z.AddByte(0xA0+((nValue&0x1f0000)>>16));
Z.AddByte((nValue & 0xff00)>>8);
Z.AddByte(nValue & 0xff);
}
else if (nValue < 0x20000000)
{
// 110xxxxx: 4 byte value
nLen = 4;
Z.AddByte(0xC0+((nValue&0x1f000000)>>24));
Z.AddByte((nValue & 0xff0000)>>16);
Z.AddByte((nValue & 0xff00)>>8);
Z.AddByte(nValue & 0xff);
}
else
{
// 11100000: Value in the next 4 bytes
nLen = 5;
Z.AddByte(0xE0);
Z.AddByte((nValue & 0xff000000)>>24);
Z.AddByte((nValue & 0xff0000)>>16);
Z.AddByte((nValue & 0xff00)>>8);
Z.AddByte(nValue & 0xff);
}
}