Convert a serialized integer into a 32-bit signed integer.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | ReadSerialSINT32 | (int32_t&,uint32_t&,unsigned char*,) |
Declared in file: hzCodec.h
Defined in file : hzCodec.cpp
Function Logic:
Function body:
hzEcode ReadSerialSINT32 (int32_t& nValue)uint32_t& nLen, unsigned char* ptr,
{
// Category: Number Serialization
//
// Convert a serialized integer into a 32-bit signed integer.
//
// Arguments: 1) nValue Indicated length or value
// 2) nLen The size of the indicator itself
// 3) ptr Pointer into a uchar buffer (start of indicator)
//
// Returns: E_ARGUMENT If no ptr is supplied
// E_OK Operation successful
uint32_t val ; // Value
bool bNeg ; // Negative
if (!ptr)
{ nValue = 0; nLen = 0; return E_ARGUMENT ; }
if (!(*ptr & 0x80))
{
bNeg = *ptr & 0x40;
val = *ptr & 0x3f;
}
else
{
// Top bit set so indicator length will be ...
bNeg = *ptr & 0x10;
nLen = (*ptr & 0x60)>>5;
nLen += 2;
switch (nLen)
{
case 2: val = ((ptr[0]& 0x0f)<<8);
val += ptr[1];
break ;
case 3: val = ((ptr[0]& 0x0f)<<16);
val += ((ptr[1]<< 8)+ ptr[2]);
break ;
case 4: val = ((ptr[0]& 0x0f)<<24);
val += ((ptr[1]<< 16)+(ptr[2]<< 8)+ ptr[3]);
break ;
case 5: _endian_import4(val, ptr) ;
break ;
}
}
nValue = bNeg ? -val : val ;
return E_OK ;
}