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

Return TypeFunction nameArguments
voidWriteSerialSINT64(hzChain&,uint32_t&,int64_t,)

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

Function Logic:

0:START 1:unknown 2:bNeg - nValue 3:unknown 4:nLen items byte items 5:nValue<0x0800 6:nLen items nValue byte items items 7:nValue<0x080000 8:nLen items nValue byte items items items 9:nValue<0x08000000 10:nLen items nValue byte items items items items 11:nValue<0x0800000000 12:nLen items nValue byte items items items items items 13:nValue<0x080000000000 14:nLen items nValue byte items items items items items items 15:nValue<0x08000000000000 16:nLen items nValue byte items items items items items items items 17:nValue<0x08000000000000 18:nLen items nValue byte items items items items items items items items 19:nLen items nValue byte items items items items items items items items items 20: No text

Function body:

void WriteSerialSINT64 (hzChain& Z)uint32_t& nLen, int64_t nValue, 
{
   //  Category: Number Serialization
   //  
   //  Serialize signed 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
   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 < 0x0800)
   {
       //  Bit 0 is 1, bits 1, 2 and 3 are controls (000), bit 4 is the negator, bits 5-7 are top 3 bits of value, 1 more byte to go
       nLen = 2;
       byte = bNeg ? 0x88:0x80;
       byte |= ((nValue & 0x0700)>>8);
       Z.AddByte(byte) ;
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x080000)
   {
       //  Bit 0 is 1, bits 1, 2 and 3 are controls (001), bit 4 is the negator, bits 5-7 are top 3 bits of value, 2 more bytes to go
       nLen = 3;
       byte = bNeg ? 0x98:0x90;
       byte |= ((nValue & 0x070000)>>16);
       Z.AddByte(byte) ;
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x08000000)
   {
       //  Bit 0 is 1, bits 1 and 2 are controls (010), bit 4 is the negator, bits 5-7 are top 3 bits of value, 3 more bytes to go
       nLen = 4;
       byte = bNeg ? 0xA8:0xA0;
       byte |= ((nValue & 0x07000000)>>24);
       Z.AddByte(byte) ;
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x0800000000)
   {
       //  Bit 0 is 1, bits 1 and 2 are controls (011), bit 4 is the negator, bits 5-7 are top 3 bits of value, 4 more bytes to go
       nLen = 4;
       byte = bNeg ? 0xB8:0xB0;
       byte |= ((nValue & 0x0700000000)>>32);
       Z.AddByte(byte) ;
       Z.AddByte((nValue & 0xff000000)>>24);
       Z.AddByte((nValue & 0xff0000)>>16);
       Z.AddByte((nValue & 0xff00)>>8);
       Z.AddByte(nValue & 0xff);
   }
   else if (nValue < 0x080000000000)
   {
       //  Bit 0 is 1, bits 1 and 2 are controls (100), bit 4 is the negator, bits 5-7 are top 3 bits of value, 5 more bytes to go
       nLen = 4;
       byte = bNeg ? 0xC8:0xC0;
       byte |= ((nValue & 0x0700000000)>>40);
       Z.AddByte(byte) ;
       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 < 0x08000000000000)
   {
       //  Bit 0 is 1, bits 1 and 2 are controls (101), bit 4 is the negator, bits 5-7 are top 3 bits of value, 6 more bytes to go
       nLen = 4;
       byte = bNeg ? 0xD8:0xD0;
       byte |= ((nValue & 0x070000000000)>>48);
       Z.AddByte(byte) ;
       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 < 0x08000000000000)
   {
       //  Bit 0 is 1, bits 1 and 2 are controls (110), bit 4 is the negator, bits 5-7 are top 3 bits of value, 7 more bytes to go
       nLen = 4;
       byte = bNeg ? 0xD8:0xD0;
       byte |= ((nValue & 0x07000000000000)>>56);
       Z.AddByte(byte) ;
       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
   {
       //  Bit 0 is 1, bits 1 and 2 are controls (111), bit 4 is the negator, 8 more bytes to go
       nLen = 5;
       byte = bNeg ? 0xF8:0xF0;
       byte |= ((nValue & 0x0f000000)>>24);
       Z.AddByte(0xC0);
       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);
   }
}