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

void PASNObjectID::Encode ( PBYTEArray &  buffer  )  [virtual]

Virtual function used to encode the object into ASN format

Reimplemented from PASNObject.

Definition at line 768 of file pasn.cxx.

References PASNObject::EncodeASNHeader(), and PASNObject::ObjectID.

{
  PBYTEArray  eObjId;
  PINDEX      offs = 0;
  PASNOid     subId, mask, testmask;
  int         bits, testbits;
  PINDEX      objIdLen = value.GetSize();
  PASNOid     *objId = value.GetPointer();

  if (objIdLen < 2) {
    eObjId [offs++] = 0;
    objIdLen = 0;
  } else {
    eObjId [offs++] = (BYTE)(objId[1] + (objId[0] * 40));
    objIdLen -= 2;
    objId += 2;
  }

  while (objIdLen-- > 0) {
    subId = *objId++;
    if (subId < 128) 
      eObjId [offs++] = (BYTE)subId;
    else {
      mask = 0x7F; /* handle subid == 0 case */
      bits = 0;

      /* testmask *MUST* !!!! be of an unsigned type */
      for (testmask = 0x7F, testbits = 0;
           testmask != 0;
           testmask <<= 7, testbits += 7) {
        if (subId & testmask) {  /* if any bits set */
          mask = testmask;
          bits = testbits;
        }
      }

      /* mask can't be zero here */
      for(;mask != 0x7F; mask >>= 7, bits -= 7) {
        /* fix a mask that got truncated above */
        if (mask == 0x1E00000)
          mask = 0xFE00000;
        eObjId [offs++] = (u_char)(((subId & mask) >> bits) | ASN_BIT8);
      }
      eObjId [offs++] = (u_char)(subId & mask);
    }
  }

  PINDEX s = eObjId.GetSize();
  EncodeASNHeader (buffer, ObjectID, (WORD)s);
  offs = buffer.GetSize();
  for (PINDEX i = 0; i < s; i++)
    buffer [offs + i] = eObjId[i];
}


Generated by  Doxygen 1.6.0   Back to index