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

📄 asner.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 5 页
字号:
}BOOL PASN_ConstrainedString::Decode(PASN_Stream & strm){  return strm.ConstrainedStringDecode(*this);}void PASN_ConstrainedString::Encode(PASN_Stream & strm) const{  strm.ConstrainedStringEncode(*this);}BOOL PASN_ConstrainedString::DecodeBER(PBER_Stream & strm, unsigned len){  return strm.BlockDecode((BYTE *)value.GetPointer(len+1), len) == len;}void PASN_ConstrainedString::EncodeBER(PBER_Stream & strm) const{  strm.BlockEncode(value, value.GetSize()-1);}BOOL PASN_ConstrainedString::DecodePER(PPER_Stream & strm){  // X.691 Section 26  unsigned len;  if (ConstrainedLengthDecode(strm, len) < 0)    return FALSE;  unsigned nBits = strm.IsAligned() ? charSetAlignedBits : charSetUnalignedBits;  if (constraint == Unconstrained || upperLimit*nBits > 16) {    if (nBits == 8)      return strm.BlockDecode((BYTE *)value.GetPointer(len+1), len) == len;    if (strm.IsAligned())      strm.ByteAlign();  }  value.SetSize(len+1);  PINDEX i;  for (i = 0; i < (PINDEX)len; i++) {    if (strm.IsAtEnd())      return FALSE;    if (nBits >= canonicalSetBits && canonicalSetBits > 4)      value[i] = (char)strm.MultiBitDecode(nBits);    else      value[i] = characterSet[strm.MultiBitDecode(nBits)];  }  value[i] = '\0';  return TRUE;}void PASN_ConstrainedString::EncodePER(PPER_Stream & strm) const{  // X.691 Section 26  PINDEX len = value.GetSize()-1;  ConstrainedLengthEncode(strm, len);  unsigned nBits = strm.IsAligned() ? charSetAlignedBits : charSetUnalignedBits;  if (constraint == Unconstrained || upperLimit*nBits > 16) {    if (nBits == 8) {      strm.BlockEncode((const BYTE *)(const char *)value, len);      return;    }    if (strm.IsAligned())      strm.ByteAlign();  }  for (PINDEX i = 0; i < len; i++) {    if (nBits >= canonicalSetBits && canonicalSetBits > 4)      strm.MultiBitEncode(value[i], nBits);    else {      const void * ptr = memchr(characterSet, value[i], characterSet.GetSize());      PINDEX pos = 0;      if (ptr != NULL)        pos = ((const char *)ptr - (const char *)characterSet);      strm.MultiBitEncode(pos, nBits);    }  }}BOOL PBER_Stream::ConstrainedStringDecode(PASN_ConstrainedString & value){  unsigned len;  if (!HeaderDecode(value, len))    return FALSE;  return value.DecodeBER(*this, len);}void PBER_Stream::ConstrainedStringEncode(const PASN_ConstrainedString & value){  HeaderEncode(value);  value.Encode(*this);}BOOL PPER_Stream::ConstrainedStringDecode(PASN_ConstrainedString & value){  return value.DecodePER(*this);}void PPER_Stream::ConstrainedStringEncode(const PASN_ConstrainedString & value){  value.EncodePER(*this);}#define DEFINE_STRING_CLASS(name, set) \  static const char name##StringSet[] = set; \  PASN_##name##String::PASN_##name##String(unsigned tag, TagClass tagClass) \    : PASN_ConstrainedString(name##StringSet, sizeof(name##StringSet)-1, tag, tagClass) \    { } \    PASN_##name##String & PASN_##name##String::operator=(const char * str) \    { PASN_ConstrainedString::SetValue(str); return *this; } \  PASN_##name##String & PASN_##name##String::operator=(const PString & str) \    { PASN_ConstrainedString::SetValue(str); return *this; } \  PObject * PASN_##name##String::Clone() const \    { PAssert(IsClass(PASN_##name##String::Class()), PInvalidCast); \      return new PASN_##name##String(*this); } \  PString PASN_##name##String::GetTypeAsString() const \    { return #name " String"; }DEFINE_STRING_CLASS(Numeric,   " 0123456789")DEFINE_STRING_CLASS(Printable, " '()+,-./0123456789:=?"                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                               "abcdefghijklmnopqrstuvwxyz")DEFINE_STRING_CLASS(Visible,   " !\"#$%&'()*+,-./0123456789:;<=>?"                               "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"                               "`abcdefghijklmnopqrstuvwxyz{|}~")DEFINE_STRING_CLASS(IA5,       "\000\001\002\003\004\005\006\007"                               "\010\011\012\013\014\015\016\017"                               "\020\021\022\023\024\025\026\027"                               "\030\031\032\033\034\035\036\037"                               " !\"#$%&'()*+,-./0123456789:;<=>?"                               "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"                               "`abcdefghijklmnopqrstuvwxyz{|}~\177")DEFINE_STRING_CLASS(General,   "\000\001\002\003\004\005\006\007"                               "\010\011\012\013\014\015\016\017"                               "\020\021\022\023\024\025\026\027"                               "\030\031\032\033\034\035\036\037"                               " !\"#$%&'()*+,-./0123456789:;<=>?"                               "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"                               "`abcdefghijklmnopqrstuvwxyz{|}~\177"                               "\200\201\202\203\204\205\206\207"                               "\210\211\212\213\214\215\216\217"                               "\220\221\222\223\224\225\226\227"                               "\230\231\232\233\234\235\236\237"                               "\240\241\242\243\244\245\246\247"                               "\250\251\252\253\254\255\256\257"                               "\260\261\262\263\264\265\266\267"                               "\270\271\272\273\274\275\276\277"                               "\300\301\302\303\304\305\306\307"                               "\310\311\312\313\314\315\316\317"                               "\320\321\322\323\324\325\326\327"                               "\330\331\332\333\334\335\336\337"                               "\340\341\342\343\344\345\346\347"                               "\350\351\352\353\354\355\356\357"                               "\360\361\362\363\364\365\366\367"                               "\370\371\372\373\374\375\376\377")///////////////////////////////////////////////////////////////////////PASN_BMPString::PASN_BMPString(unsigned tag, TagClass tagClass)  : PASN_ConstrainedObject(tag, tagClass){  firstChar = 0;  lastChar = 0xffff;  charSetAlignedBits = 16;  charSetUnalignedBits = 16;}PASN_BMPString::PASN_BMPString(const PASN_BMPString & other)  : PASN_ConstrainedObject(other),    value(other.value, other.value.GetSize()),    characterSet(other.characterSet){  firstChar = other.firstChar;  lastChar = other.lastChar;  charSetAlignedBits = other.charSetAlignedBits;  charSetUnalignedBits = other.charSetUnalignedBits;}PASN_BMPString & PASN_BMPString::operator=(const PASN_BMPString & other){  PASN_ConstrainedObject::operator=(other);  value = PWORDArray(other.value, other.value.GetSize());  characterSet = other.characterSet;  firstChar = other.firstChar;  lastChar = other.lastChar;  charSetAlignedBits = other.charSetAlignedBits;  charSetUnalignedBits = other.charSetUnalignedBits;  return *this;}BOOL PASN_BMPString::IsLegalCharacter(WORD ch){  if (ch < firstChar)    return FALSE;  if (ch > lastChar)    return FALSE;  if (characterSet.IsEmpty())    return TRUE;  const WORD * wptr = characterSet;  PINDEX count = characterSet.GetSize();  while (count-- > 0) {    if (*wptr == ch)      return TRUE;    wptr++;  }  return FALSE;}PASN_BMPString & PASN_BMPString::operator=(const PString & str){  PINDEX sz = str.GetLength();  value.SetSize(sz);  PINDEX count = 0;  for (PINDEX i = 0; i < sz; i++) {    WORD c = (BYTE)str[i];    if (IsLegalCharacter(c))      value[count++] = c;  }  value.SetSize(count);  return *this;}PASN_BMPString & PASN_BMPString::operator=(const PWORDArray & array){  PINDEX sz = array.GetSize();  value.SetSize(sz);  PINDEX count = 0;  for (PINDEX i = 0; i < sz; i++) {    WORD c = array[i];    if (IsLegalCharacter(c))      value[count++] = c;  }  value.SetSize(count);  return *this;}PString PASN_BMPString::GetValue() const{  PString str;  for (PINDEX i = 0; i < value.GetSize(); i++) {    if (value[i] < 256)      str += (char)value[i];  }  return str;}void PASN_BMPString::SetCharacterSet(ConstraintType ctype, const char * charSet){  PWORDArray array(strlen(charSet));  PINDEX count = 0;  while (*charSet != '\0')    array[count++] = (BYTE)*charSet++;  SetCharacterSet(ctype, array);}void PASN_BMPString::SetCharacterSet(ConstraintType ctype, const PWORDArray & charSet){  if (ctype == Unconstrained) {    firstChar = 0;    lastChar = 0xffff;    characterSet.SetSize(0);  }  else {    characterSet = charSet;    charSetUnalignedBits = CountBits(lastChar - firstChar + 1);    if (!charSet.IsEmpty()) {      unsigned count = 0;      for (PINDEX i = 0; i < charSet.GetSize(); i++) {        if (characterSet[i] >= firstChar && characterSet[i] <= lastChar)          count++;      }      count = CountBits(count);      if (charSetUnalignedBits > count)        charSetUnalignedBits = count;    }    charSetAlignedBits = 1;    while (charSetUnalignedBits > charSetAlignedBits)      charSetAlignedBits <<= 1;    SetValue(value);  }}void PASN_BMPString::SetCharacterSet(ConstraintType ctype, unsigned first, unsigned last){  if (ctype != Unconstrained) {    PAssert(first < 0x10000 && last < 0x10000 && last > first, PInvalidParameter);    firstChar = (WORD)first;    lastChar = (WORD)last;  }  SetCharacterSet(ctype, characterSet);}PObject * PASN_BMPString::Clone() const{  PAssert(IsClass(PASN_BMPString::Class()), PInvalidCast);  return new PASN_BMPString(*this);}PObject::Comparison PASN_BMPString::Compare(const PObject & obj) const{  PAssert(obj.IsDescendant(PASN_BMPString::Class()), PInvalidCast);  const PASN_BMPString & other = (const PASN_BMPString &)obj;  return value.Compare(other.value);}void PASN_BMPString::PrintOn(ostream & strm) const{  int indent = strm.precision() + 2;  PINDEX sz = value.GetSize();  strm << ' ' << sz << " characters {\n";  PINDEX i = 0;  while (i < sz) {    strm << setw(indent) << " " << hex << setfill('0');    PINDEX j;    for (j = 0; j < 8; j++)      if (i+j < sz)        strm << setw(4) << value[i+j] << ' ';      else        strm << "     ";    strm << "  ";    for (j = 0; j < 8; j++) {      if (i+j < sz) {        WORD c = value[i+j];        if (c < 128 && isprint(c))          strm << (char)c;        else          strm << ' ';      }    }    strm << dec << setfill(' ') << '\n';    i += 8;  }  strm << setw(indent-1) << "}";}PString PASN_BMPString::GetTypeAsString() const{  return "BMP String";}PINDEX PASN_BMPString::GetDataLength() const{  return value.GetSize()*2;}BOOL PASN_BMPString::Decode(PASN_Stream & strm){  return strm.BMPStringDecode(*this);}void PASN_BMPString::Encode(PASN_Stream & strm) const{  strm.BMPStringEncode(*this);}BOOL PASN_BMPString::DecodeBER(PBER_Stream & strm, unsigned len){  value.SetSize(len/2);  return strm.BlockDecode((BYTE *)value.GetPointer(len), len) == len;}void PASN_BMPString::EncodeBER(PBER_Stream & strm) const{  strm.BlockEncode((const BYTE *)(const WORD *)value, value.GetSize()*2);}BOOL PASN_BMPString::DecodePER(PPER_Stream & strm){  // X.691 Section 26  unsigned len;  if (ConstrainedLengthDecode(strm, len) < 0)    return FALSE;  value.SetSize(len);  PINDEX nBits = strm.IsAligned() ? charSetAlignedBits : charSetUnalignedBits;  if ((constraint == Unconstrained || upperLimit*nBits > 16) && strm.IsAligned())    strm.ByteAlign();  for (PINDEX i = 0; i < (PINDEX)len; i++) {    if (strm.IsAtEnd())      return FALSE;    if (characterSet.IsEmpty())      value[i] = (WORD)(strm.MultiBitDecode(nBits) + firstChar);    else      value[i] = characterSet[strm.MultiBitDecode(nBits)];  }  return TRUE;}void PASN_BMPString::EncodePER(PPER_Stream & strm) const{  // X.691 Section 26  PINDEX len = value.GetSize();  ConstrainedLengthEncode(strm, len);  PINDEX nBits = strm.IsAligned() ? charSetAlignedBits : charSetUnalignedBits;  if ((constraint == Unconstrained || upperLimit*nBits > 16) && strm.IsAligned())    strm.ByteAlign();  for (PINDEX i = 0; i < len; i++) {    if (characterSet.IsEmpty())      strm.MultiBitEncode(value[i] - firstChar, nBits);    else {      for (PINDEX pos = 0; pos < characterSet.GetSize(); pos++) {        if (characterSet[pos] == value[i]) {          strm.MultiBitEncode(pos, nBits);          break;        }      }    }  }}BOOL PBER_Stream::BMPStringDecode(PASN_BMPString & value){  unsigned len;  if (!HeaderDecode(value, len))    return FALSE;  return value.DecodeBER(*this, len);}void PBER_Stream::BMPStringEncode(const PASN_BMPString & value){  HeaderEncode(value);  value.EncodeBER(*this);}BOOL PPER_Stream::BMPStringDecode(PASN_BMPString & value){  return value.DecodePER(*this);}void PPER_Stream::BMPStringEncode(const PASN_BMPString & value){  value.EncodePER(*this);}///////////////////////////////////////////////////////////////////////PASN_Choice::PASN_Choice(unsigned nChoices, BOOL extend)  : PASN_Object(0, ApplicationTagClass, extend){  numChoices = nChoices;  choice = NULL;}PASN_Choice::PASN_Choice(unsigned tag, TagClass tagClass,                         unsigned upper, BOOL extend)  : PASN_Object(tag, tagClass, extend){  numChoices = upper;  choice = NULL;}PASN_Choice::PASN_Choice(unsigned tag, TagClass tagClass,                         unsigned upper, BOOL extend, const PString & nameSpec)  : PASN_Object(tag, tagClass, extend),    names(BuildNamesDict(nameSpec)){  numChoices = upper;  choice = NULL;}PASN_Choice::PASN_Choice(const PASN_Choice & other)  : PASN_Object(other),    names(other.names){  numChoices = other.numChoices;  if (other.choice != NULL)    choice = (PASN_Object *)other.choice->Clone();  else    choice = NULL;}PASN_Choice & PASN_Choice::operator=(const PASN_Choice & other){  delete choice;  PASN_Object::operator=(other);  numChoices = other.numChoices;  names = other.names;  if (other.choice != NULL)    choice = (PASN_Object *)other.choice->Clone();  else    choice = NULL;  return *this;}PASN_Choice::~PASN_Choice(){  delete choice;}void PASN_Choice::SetTag(unsigned newTag, TagClass tagClass){  PASN_Object::SetTag(newTag, tagClass);  delete choice;  if (CreateObject())    choice->SetTag(newTag, tagClass);}PString PASN_Choice::GetTagName() const{  if (tag == UINT_MAX)    return "<uninitialised>";

⌨️ 快捷键说明

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