Serialize unsigned 64-bit integer to a hzChain. Returns: None

Return TypeFunction nameArguments
voidWriteSerialUINT64(hzChain&,uint32_t&,uint64_t,)

Declared in file: hzCodec.h
Defined in file : hzCodec.cpp

Function Logic:

0:START 1:unknown 2:nLen items 3:nValue<0x1000 4:nLen items items 5:nValue<0x100000 6:nLen items items items 7:nValue<0x10000000 8:nLen items items items items 9:nValue<0x1000000000 10:nLen items items items items items 11:nValue<0x100000000000 12:nLen items items items items items items 13:nValue<0x10000000000000 14:nLen items items items items items items items 15:nValue<0x1000000000000000 16:nLen items items items items items items items items 17:nLen items items items items items items items items items 18: No text

Function body:

void WriteSerialUINT64 (hzChain& Z)uint32_t& nLen, uint64_t nValue, 
{
   //  Category: Number Serialization
   //  
   //  Serialize unsigned 64-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 < 0x1000)
   {
       //  2 byte serial integer. Control byte is 1000 xxxx. Total range 12 bits.
       nLen = 2;
       Z.AddByte(0x80+((nValue&0x0f00)>>8));
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x100000)
   {
       //  3 byte serial integer. Control byte is 1001 xxxx. Total range 20 bits.
       nLen = 3;
       Z.AddByte(0x90+((nValue&0x0f0000)>>16));
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x10000000)
   {
       //  4 byte serial integer. Control byte is 1010 xxxx. Total range 28 bits.
       nLen = 4;
       Z.AddByte(0xA0+((nValue&0x0f000000)>>24));
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x1000000000)
   {
       //  5 byte serial integer. Control byte is 1011 xxxx. Total range 36 bits.
       nLen = 5;
       Z.AddByte(0xB0+((nValue&0x0f00000000)>>32));
       Z.AddByte((nValue & 0xff000000)>>24);
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x100000000000)
   {
       //  6 byte serial integer. Control byte is 1100 xxxx. Total range 44 bits.
       nLen = 6;
       Z.AddByte(0xC0+((nValue&0x0f0000000000)>>40));
       Z.AddByte((nValue & 0xff00000000)>>32);
       Z.AddByte((nValue & 0xff000000)>>24);
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x10000000000000)
   {
       //  7 byte serial integer. Control byte is 1101 xxxx. Total range 52 bits.
       nLen = 7;
       Z.AddByte(0xD0+((nValue&0x0f000000000000)>>48));
       Z.AddByte((nValue & 0xff0000000000)>>40);
       Z.AddByte((nValue & 0xff00000000)>>32);
       Z.AddByte((nValue & 0xff000000)>>24);
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x1000000000000000)
   {
       //  8 byte serial integer. Control byte is 1110 xxxx. Total range 60 bits.
       nLen = 8;
       Z.AddByte(0xE0+((nValue&0x0f00000000000000)>>56));
       Z.AddByte((nValue & 0xff000000000000)>>48);
       Z.AddByte((nValue & 0xff0000000000)>>40);
       Z.AddByte((nValue & 0xff00000000)>>32);
       Z.AddByte((nValue & 0xff000000)>>24);
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else
   {
       //  9 byte serial integer (8 byte absolute value). Control byte is 1111 0000. Total range 64 bits.
       nLen = 5;
       Z.AddByte(0xf0);
       Z.AddByte((nValue & 0xff00000000000000)>>56);
       Z.AddByte((nValue & 0xff000000000000)>>48);
       Z.AddByte((nValue & 0xff0000000000)>>40);
       Z.AddByte((nValue & 0xff00000000)>>32);
       Z.AddByte((nValue & 0xff000000)>>24);
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
}