⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asner.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 5 页
字号:
  ByteAlign();  return value.CommonDecode(*this, dataLen);}void PPER_Stream::ObjectIdEncode(const PASN_ObjectId & value){  // X.691 Section 23  PBYTEArray eObjId;  value.CommonEncode(eObjId);  LengthEncode(eObjId.GetSize(), 0, 255);  BlockEncode(eObjId, eObjId.GetSize());}///////////////////////////////////////////////////////////////////////PASN_BitString::PASN_BitString(unsigned tag, TagClass tagClass, unsigned nBits)  : PASN_ConstrainedObject(tag, tagClass),    totalBits(nBits),    bitData((totalBits+7)/8){}PASN_BitString::PASN_BitString(const PASN_BitString & other)  : PASN_ConstrainedObject(other),    bitData(other.bitData, other.bitData.GetSize()){  totalBits = other.totalBits;}PASN_BitString & PASN_BitString::operator=(const PASN_BitString & other){  PASN_ConstrainedObject::operator=(other);  totalBits = other.totalBits;  bitData = PBYTEArray(other.bitData, other.bitData.GetSize());  return *this;}void PASN_BitString::SetData(unsigned nBits, const PBYTEArray & bytes){  bitData = bytes;  totalBits = nBits;}void PASN_BitString::SetData(unsigned nBits, const BYTE * buf, PINDEX size){  bitData = PBYTEArray(buf, size);  totalBits = nBits;}BOOL PASN_BitString::SetSize(unsigned nBits){  totalBits = nBits;  return bitData.SetSize((nBits+7)/8);}BOOL PASN_BitString::operator[](PINDEX bit) const{  if ((unsigned)bit < totalBits)    return (bitData[bit>>3] & (1 << (7 - (bit&7)))) != 0;  return FALSE;}void PASN_BitString::Set(unsigned bit){  if (bit < totalBits)    bitData[(PINDEX)(bit>>3)] |= 1 << (7 - (bit&7));}void PASN_BitString::Clear(unsigned bit){  if (bit < totalBits)    bitData[(PINDEX)(bit>>3)] &= ~(1 << (7 - (bit&7)));}void PASN_BitString::Invert(unsigned bit){  if (bit < totalBits)    bitData[(PINDEX)(bit>>3)] ^= 1 << (7 - (bit&7));}void PASN_BitString::SetConstraints(ConstraintType type, int lower, unsigned upper){  PAssert(lower >= 0, PInvalidParameter);  PASN_ConstrainedObject::SetConstraints(type, lower, upper);  if (constraint != Unconstrained) {    if (totalBits < (unsigned)lowerLimit)      SetSize(lowerLimit);    else if ((unsigned)totalBits > upperLimit)      SetSize(upperLimit);  }}PObject::Comparison PASN_BitString::Compare(const PObject & obj) const{  PAssert(obj.IsDescendant(PASN_BitString::Class()), PInvalidCast);  const PASN_BitString & other = (const PASN_BitString &)obj;  if (totalBits < other.totalBits)    return LessThan;  if (totalBits > other.totalBits)    return GreaterThan;  return bitData.Compare(other.bitData);}PObject * PASN_BitString::Clone() const{  PAssert(IsClass(PASN_BitString::Class()), PInvalidCast);  return new PASN_BitString(*this);}void PASN_BitString::PrintOn(ostream & strm) const{  BYTE mask = 0x80;  PINDEX offset = 0;  for (unsigned i = 0; i < totalBits; i++) {    strm << ((bitData[offset]&mask) != 0 ? '1' : '0');    mask >>= 1;    if (mask == 0) {      mask = 0x80;      offset++;    }  }}PString PASN_BitString::GetTypeAsString() const{  return "Bit String";}PINDEX PASN_BitString::GetDataLength() const{  return (totalBits+7)/8 + 1;}BOOL PASN_BitString::Decode(PASN_Stream & strm){  return strm.BitStringDecode(*this);}void PASN_BitString::Encode(PASN_Stream & strm) const{  strm.BitStringEncode(*this);}BOOL PASN_BitString::DecodeBER(PBER_Stream & strm, unsigned len){  totalBits = len*8 - strm.ByteDecode();  unsigned nBytes = (totalBits+7)/8;  return strm.BlockDecode(bitData.GetPointer(nBytes), nBytes) == nBytes;}void PASN_BitString::EncodeBER(PBER_Stream & strm) const{  if (totalBits == 0)    strm.ByteEncode(0);  else {    strm.ByteEncode(8-totalBits%8);    strm.BlockEncode(bitData, (totalBits+7)/8);  }}BOOL PASN_BitString::DecodePER(PPER_Stream & strm){  // X.691 Section 15  if (ConstrainedLengthDecode(strm, totalBits) < 0)    return FALSE;  SetSize(totalBits);  if (totalBits == 0)    return TRUE;   // 15.7  if (totalBits > strm.GetBitsLeft())    return FALSE;  if (totalBits > 16) {    unsigned nBytes = (totalBits+7)/8;    return strm.BlockDecode(bitData.GetPointer(), nBytes) == nBytes;   // 15.9  }  if (totalBits <= 8)    bitData[0] = (BYTE)(strm.MultiBitDecode(totalBits) << (8-totalBits));  else {  // 15.8    bitData[0] = (BYTE)strm.MultiBitDecode(8);    bitData[1] = (BYTE)(strm.MultiBitDecode(totalBits-8) << (16-totalBits));  }  return TRUE;}void PASN_BitString::EncodePER(PPER_Stream & strm) const{  // X.691 Section 15  ConstrainedLengthEncode(strm, totalBits);  if (totalBits == 0)    return;  if (totalBits > 16)    strm.BlockEncode(bitData, (totalBits+7)/8);   // 15.9  else if (totalBits <= 8)  // 15.8    strm.MultiBitEncode(bitData[0] >> (8 - totalBits), totalBits);  else {    strm.MultiBitEncode(bitData[0], 8);    strm.MultiBitEncode(bitData[1] >> (16 - totalBits), totalBits-8);  }}BOOL PBER_Stream::BitStringDecode(PASN_BitString & value){  unsigned len;  if (!HeaderDecode(value, len) || len == 0 || IsAtEnd())    return FALSE;  return value.DecodeBER(*this, len);}void PBER_Stream::BitStringEncode(const PASN_BitString & value){  HeaderEncode(value);  value.EncodeBER(*this);}BOOL PPER_Stream::BitStringDecode(PASN_BitString & value){  return value.DecodePER(*this);}void PPER_Stream::BitStringEncode(const PASN_BitString & value){  value.EncodePER(*this);}///////////////////////////////////////////////////////////////////////PASN_OctetString::PASN_OctetString(unsigned tag, TagClass tagClass)  : PASN_ConstrainedObject(tag, tagClass){}PASN_OctetString::PASN_OctetString(const PASN_OctetString & other)  : PASN_ConstrainedObject(other),    value(other.value, other.GetSize()){}PASN_OctetString & PASN_OctetString::operator=(const PASN_OctetString & other){  PASN_ConstrainedObject::operator=(other);  value = PBYTEArray(other.value, other.GetSize());  return *this;}PASN_OctetString & PASN_OctetString::operator=(const char * str){  SetValue((const BYTE *)str, strlen(str));  return *this;}PASN_OctetString & PASN_OctetString::operator=(const PString & str){  SetValue((const BYTE *)(const char *)str, str.GetSize()-1);  return *this;}PASN_OctetString & PASN_OctetString::operator=(const PBYTEArray & arr){  PINDEX len = arr.GetSize();  if ((unsigned)len > upperLimit || (int)len < lowerLimit)    SetValue(arr, len);  else    value = arr;  return *this;}void PASN_OctetString::SetValue(const BYTE * data, PINDEX len){  if ((unsigned)len > upperLimit)    len = upperLimit;  value.SetSize((int)len < lowerLimit ? lowerLimit : len);  memcpy(value.GetPointer(), data, len);}PString PASN_OctetString::AsString() const{  if (value.IsEmpty())    return PString();  return PString((const char *)(const BYTE *)value, value.GetSize());}void PASN_OctetString::SetConstraints(ConstraintType type, int lower, unsigned upper){  PAssert(lower >= 0, PInvalidParameter);  PASN_ConstrainedObject::SetConstraints(type, lower, upper);  if (constraint != Unconstrained) {    if (value.GetSize() < (PINDEX)lowerLimit)      value.SetSize(lowerLimit);    else if ((unsigned)value.GetSize() > upperLimit)      value.SetSize(upperLimit);  }}PObject::Comparison PASN_OctetString::Compare(const PObject & obj) const{  PAssert(obj.IsDescendant(PASN_OctetString::Class()), PInvalidCast);  const PASN_OctetString & other = (const PASN_OctetString &)obj;  return value.Compare(other.value);}PObject * PASN_OctetString::Clone() const{  PAssert(IsClass(PASN_OctetString::Class()), PInvalidCast);  return new PASN_OctetString(*this);}void PASN_OctetString::PrintOn(ostream & strm) const{  int indent = strm.precision() + 2;  strm << ' ' << value.GetSize() << " octets {\n";  PINDEX i = 0;  while (i < value.GetSize()) {    strm << setw(indent) << " " << hex << setfill('0');    PINDEX j;    for (j = 0; j < 16; j++) {      if (i+j < value.GetSize())        strm << setw(2) << (unsigned)value[i+j] << ' ';      else        strm << "   ";    }    strm << "  ";    for (j = 0; j < 16; j++) {      if (i+j < value.GetSize()) {        if (isprint(value[i+j]))          strm << value[i+j];        else          strm << ' ';      }    }    strm << dec << setfill(' ') << '\n';    i += 16;  }  strm << setw(indent-1) << "}";}PString PASN_OctetString::GetTypeAsString() const{  return "Octet String";}PINDEX PASN_OctetString::GetDataLength() const{  return value.GetSize();}BOOL PASN_OctetString::Decode(PASN_Stream & strm){  return strm.OctetStringDecode(*this);}void PASN_OctetString::Encode(PASN_Stream & strm) const{  strm.OctetStringEncode(*this);}BOOL PASN_OctetString::DecodePER(PPER_Stream & strm){  // X.691 Section 16  unsigned nBytes;  if (ConstrainedLengthDecode(strm, nBytes) < 0)    return FALSE;  value.SetSize(nBytes);   // 16.5  switch (nBytes) {    case 0 :      break;    case 1 :  // 16.6      if (strm.IsAtEnd())        return FALSE;      value[0] = (BYTE)strm.MultiBitDecode(8);      break;    case 2 :  // 16.6      if (strm.IsAtEnd())        return FALSE;      value[0] = (BYTE)strm.MultiBitDecode(8);      value[1] = (BYTE)strm.MultiBitDecode(8);      break;    default: // 16.7      return strm.BlockDecode(value.GetPointer(), nBytes) == nBytes;  }  return TRUE;}void PASN_OctetString::EncodePER(PPER_Stream & strm) const{  // X.691 Section 16  PINDEX nBytes = value.GetSize();  ConstrainedLengthEncode(strm, nBytes);  switch (nBytes) {    case 0 :  // 16.5      break;    case 1 :  // 16.6      strm.MultiBitEncode(value[0], 8);      break;    case 2 :  // 16.6      strm.MultiBitEncode(value[0], 8);      strm.MultiBitEncode(value[1], 8);      break;    default: // 16.7      strm.BlockEncode(value, nBytes);  }}BOOL PBER_Stream::OctetStringDecode(PASN_OctetString & value){  unsigned len;  if (!HeaderDecode(value, len))    return FALSE;  return BlockDecode(value.GetPointer(len), len) == len;}void PBER_Stream::OctetStringEncode(const PASN_OctetString & value){  HeaderEncode(value);  BlockEncode(value, value.GetSize());}BOOL PPER_Stream::OctetStringDecode(PASN_OctetString & value){  return value.DecodePER(*this);}void PPER_Stream::OctetStringEncode(const PASN_OctetString & value){  value.EncodePER(*this);}///////////////////////////////////////////////////////////////////////PASN_ConstrainedString::PASN_ConstrainedString(const char * canonical, PINDEX size,                                               unsigned tag, TagClass tagClass)  : PASN_ConstrainedObject(tag, tagClass){  canonicalSet = canonical;  canonicalSetSize = size;  canonicalSetBits = CountBits(size);  charSetUnalignedBits = 8;  charSetAlignedBits = 8;}PASN_ConstrainedString & PASN_ConstrainedString::operator=(const char * str){  value = PString();  PINDEX len = strlen(str);  for (PINDEX i = 0; i < len; i++) {    PINDEX sz = characterSet.GetSize();    if (sz == 0 || memchr(characterSet, str[i], sz) != NULL)      value += str[i];  }  return *this;}void PASN_ConstrainedString::SetCharacterSet(ConstraintType ctype, const char * set){  SetCharacterSet(set, strlen(set), ctype);}void PASN_ConstrainedString::SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar){  char buffer[256];  for (unsigned i = firstChar; i < lastChar; i++)    buffer[i] = (char)i;  SetCharacterSet(buffer, lastChar - firstChar + 1, ctype);}void PASN_ConstrainedString::SetCharacterSet(const char * set, PINDEX setSize, ConstraintType ctype){  if (ctype == Unconstrained)    characterSet.SetSize(0);  else {    characterSet.SetSize(setSize);    PINDEX count = 0;    for (PINDEX i = 0; i < canonicalSetSize; i++) {      if (memchr(set, canonicalSet[i], setSize) != NULL)        characterSet[count++] = canonicalSet[i];    }    PAssert(count > 0, PInvalidParameter);    characterSet.SetSize(count);  }  if (characterSet.IsEmpty())    charSetUnalignedBits = 8;  else    charSetUnalignedBits = CountBits(characterSet.GetSize());  charSetAlignedBits = 1;  while (charSetUnalignedBits > charSetAlignedBits)    charSetAlignedBits <<= 1;}PObject::Comparison PASN_ConstrainedString::Compare(const PObject & obj) const{  PAssert(obj.IsDescendant(PASN_ConstrainedString::Class()), PInvalidCast);  const PASN_ConstrainedString & other = (const PASN_ConstrainedString &)obj;  return value.Compare(other.value);}void PASN_ConstrainedString::PrintOn(ostream & strm) const{  strm << value.ToLiteral();}PINDEX PASN_ConstrainedString::GetDataLength() const{  return value.GetSize()-1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -