Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

WORD PASNObject::GetASNUnsignedLength ( PASNUnsigned  data  )  [static, inherited]

Parameters:
data  value to get length of

Definition at line 429 of file pasn.cxx.

References PASNObject::GetASNHeaderLength().

Referenced by GetEncodedLength().

{
  long mask;
  WORD intsize = sizeof(data);
  int  add_null_byte = 0;

  mask = 0xFFL << (8 * (sizeof(long) - 1));
  /* mask is 0xFF000000 on a big-endian machine */
  if ((u_char)((data & mask) >> (8 * (sizeof(PASNUnsigned) - 1))) & 0x80) {
    /* if MSB is set */
    add_null_byte = 1;
    intsize++;
  }

  // create a mask which is the top nine bits of a DWORD, or 0xFF800000
  // on a big endian machine
  mask = 0x1FFL << ((8 * (sizeof(DWORD) - 1)) - 1);

  // remove all sequences of nine 0's or 1's at the start of the value
  while ((((data & mask) == 0) || (((long)data & mask) == mask))
    && intsize > 1) {
    intsize--;
    data <<= 8;
  }

  // insert the header
  return (WORD)(intsize + GetASNHeaderLength(intsize) + add_null_byte);
}


Generated by  Doxygen 1.6.0   Back to index