Serialize signed 32-bit integer to a hzChain. Returns: None
| Return Type | Function name | Arguments |
|---|---|---|
| void | WriteSerialSINT32 | (hzChain&,uint32_t&,int32_t,) |
Declared in file: hzCodec.h
Defined in file : hzCodec.cpp
Function Logic:
Function body:
void WriteSerialSINT32 (hzChain& Z)uint32_t& nLen, int32_t nValue,
{
// Category: Number Serialization
//
// Serialize signed 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
bool bNeg ; // Set if negative
char byte ; // Byte to write
if (nValue < 0)
{ bNeg = true ; nValue *= -1; }
if (nValue < 0x40)
{
// Bit 0 is 0, bit 1 is negator, bits 2 thru 7 are the value
nLen = 1;
byte = bNeg ? 0x40:0;
byte |= nValue ;
Z.AddByte(byte) ;
}
else if (nValue < 0x1000)
{
// Bit 0 is 1, bits 1 and 2 are controls (00), bit 3 is the negator, bits 4-7 are top 4 bits of value, 1 more byte to go
nLen = 2;
byte = bNeg ? 0x90:0x80;
byte |= ((nValue & 0x0f00)>>8);
Z.AddByte(byte) ;
Z.AddByte(nValue & 0xff);
}
else if (nValue < 0x400000)
{
// Bit 0 is 1, bits 1 and 2 are controls (01), bit 3 is the negator, bits 4-7 are top 4 bits of value, 2 more bytes to go
nLen = 3;
byte = bNeg ? 0xB0:0xA0;
byte |= ((nValue & 0x0f0000)>>16);
Z.AddByte(byte) ;
Z.AddByte((nValue & 0xff00)>>8);
Z.AddByte(nValue & 0xff);
}
else if (nValue < 0x40000000)
{
// Bit 0 is 1, bits 1 and 2 are controls (10), bit 3 is the negator, bits 4-7 are top 4 bits of value, 3 more bytes to go
nLen = 4;
byte = bNeg ? 0xD0:0xC0;
byte |= ((nValue & 0x0f000000)>>24);
Z.AddByte(byte) ;
Z.AddByte((nValue & 0xff0000)>>16);
Z.AddByte((nValue & 0xff00)>>8);
Z.AddByte(nValue & 0xff);
}
else
{
// Bit 0 is 1, bits 1 and 2 are controls (11), bit 3 is the negator, bits 4-7 are top 4 bits of value, 3 more bytes to go
nLen = 5;
byte = bNeg ? 0xF0:0xE0;
byte |= ((nValue & 0x0f000000)>>24);
Z.AddByte(0xC0);
Z.AddByte((nValue & 0xff000000)>>24);
Z.AddByte((nValue & 0xff0000)>>16);
Z.AddByte((nValue & 0xff00)>>8);
Z.AddByte(nValue & 0xff);
}
}