当前位置: 首页>>代码示例>>C++>>正文


C++ AsnBuf类代码示例

本文整理汇总了C++中AsnBuf的典型用法代码示例。如果您正苦于以下问题:C++ AsnBuf类的具体用法?C++ AsnBuf怎么用?C++ AsnBuf使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AsnBuf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

// ASN.1 related methods
void 
Person::serialize(ENetPacket* buf)
{
  ASNPerson p;
  p.name = name.c_str();
  p.age = age;

  AsnBuf abuf;
  const size_t dataSize = 1024;
  char data[dataSize];
  size_t encodedLen;
  abuf.Init (data, dataSize);
  abuf.ResetInWriteRvsMode();
  AsnLen len = p.BEncPdu ( abuf, encodedLen );

#ifndef ASN_USE_FILE
  ofstream outputFile;  
  outputFile.open ("pr.ber");
  abuf.ResetInReadMode();
  for (; encodedLen > 0; encodedLen--)
    outputFile.put (abuf.GetByte());
#else
# error "Char Asn Encoding not implemented"
#endif

}
开发者ID:dreamsxin,项目名称:rainbrurpg,代码行数:27,代码来源:Person.cpp

示例2: if

// FUNCTION: BEnc()
// PUPROSE: Encode ANY DEFINED BY if "value" is present otherwise encode ANY if 
//          anyBuf is present.  If neither is present an exception is thrown.
//
AsnLen
AsnAny::BEnc (AsnBuf &b) const
{
   FUNC("AsnAny::BEnc()");

   if (value != NULL)
      return value->BEnc(b);
   else if (anyBuf != NULL)
   {
		anyBuf->ResetMode();
		b.insert(*anyBuf);
		return anyBuf->length();

#ifdef OLD
      std::string data;
      
		// PIERCE: make this more efficient
      //
      anyBuf->ResetMode();
      anyBuf->GetSeg(data);
      anyBuf->ResetMode();
      b.PutSegRvs(data.data(), data.length());
      return anyBuf->length();
#endif
   }
   else
      throw EXCEPT("Unknown any with no value", ENCODE_ERROR);
}
开发者ID:neeraj9,项目名称:esnacc-ng,代码行数:32,代码来源:asn-any.cpp

示例3: checkBuf

void checkBuf(AsnBuf &b)
{
   Deck::const_iterator i;
   
   for (i = b.deck().begin(); i != b.deck().end(); i++)
   {
      Card *tmpCard = *i;
   }
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:9,代码来源:testsetsorting.cpp

示例4: bittests

void bittests(void)
{

   std::cout << "*** Start of AsnBits tests ***\n";

   for (int index=0; gBitTestTable[index].input != NULL; index++)
   {
      AsnBits asnBits(gBitTestTable[index].input);
      asnBits.UseNamedBitListRules(gBitTestTable[index].nblFlag);
      AsnBuf expectedResult(&gBitTestTable[index].result[0], 
         DecTagLen((unsigned char *)gBitTestTable[index].result+1) + 2);
      AsnBuf result;
      AsnLen bytesEncoded;

      std::cout << "AsnBits test " << index << " matches expected result? ";

      try
      {
         asnBits.BEnc(result);
         if (!(result == expectedResult))
         {
            std::string str;
            int i;
            int ch;
            std::cout << "NO!\n";

            std::cout << "FAILED!\n";
            std::cout << "Expected Result: ";

            expectedResult.hexDump(std::cout);

            std::cout << "\n";
   
            std::cout << "\nActual Result: ";

            result.hexDump(std::cout);

            std::cout << "\n";
         }
         else
         {
            std::cout << "YES!\n";
         }
         
      }
      catch (SnaccException &e)
      {
         std::cout << "Encode FAILED: \n";
         std::cout << "Error: " << e.what() << std::endl;
         std::cout << "Stack:\n";
         e.getCallStack(std::cout);
      }
   }
   std::cout << "*** End of AsnBits tests ***\n";
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:55,代码来源:bitstest.cpp

示例5: if

bool AsnBuf::operator<(const AsnBuf &rhs) const
{
   bool lessThan = true;
   bool firstTime = true;
   ResetMode();
   rhs.ResetMode();
   std::streambuf::int_type ch1;
   std::streambuf::int_type ch2;
   while ( lessThan )
   {
      try
      {
         ch1 = GetUByte();
      }
      catch (BufferException &)
      {
         ch1 = EOF;
      }

      try
      {
         ch2 = rhs.GetUByte();
      }
      catch (BufferException &)
      {
         ch2 = EOF;
      }

      if ((ch1 == EOF) && (ch2 == EOF))
      {
         if (firstTime)
            lessThan = false;
         break;
      } 
      else if (ch2 == EOF)
      {
         lessThan = false;
         break;
      }
      else if (ch1 == EOF)
      {
         break;
      }

      if (ch1 > ch2)
         lessThan = false;
      else if (ch1 < ch2)
         break;

      firstTime = false;
   }
   ResetMode();
   rhs.ResetMode();
   return lessThan;
}
开发者ID:azsnaccbuilds,项目名称:esnacc-ng,代码行数:55,代码来源:asn-buf.cpp

示例6: TestSetSorting

void TestSetSorting(void)
{
   int i = 0;
   while (gSetSortingTable[i].input != NULL)
   {
      AsnLen bytesDecoded=0, bytesEncoded;
      //TestSetSorting1 testSetSorting1;
      int ch;

      std::string input, result;
      
      hex2str(gSetSortingTable[i].input, input);
      hex2str(gSetSortingTable[i].derSorted, result);
     
      std::stringstream ssInput(input);
      std::stringstream ssResult(result);
      
      AsnBuf inputBuf(ssInput);
      AsnBuf expectedResultBuf(ssResult);
      AsnBuf outputBuf;

      inputBuf.ResetMode();
      expectedResultBuf.ResetMode();

      gSetSortingTable[i].asnType->BDec(inputBuf, bytesDecoded);
      bytesEncoded = gSetSortingTable[i].asnType->BEnc(outputBuf);
      if (bytesEncoded != bytesDecoded)
      {
         std::cout << "Encoded / Decode byte length mismatch!!!\n";
      }
      
      if (outputBuf == expectedResultBuf)
      {
         std::cout << "SET sorting SUCCESS!\n";
      }
      else
      {

         std::cout << "SET sorting FAILURE!\n";
         std::string str;
         std::cout << "Expected result: ";
         expectedResultBuf.hexDump(std::cout);
         std::cout << std::endl;
         std::cout << "Actual result  : ";
         outputBuf.ResetMode();
         outputBuf.hexDump(std::cout);

         std::cout << std::endl;
      }
      i++;
   }
   multiCardSetTest();
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:53,代码来源:testsetsorting.cpp

示例7: exit

void 
Person::deserialize(ENetPacket* buf)
{
#ifndef ASN_USE_FILE
  // open the data file  
  ifstream dataFile;  
  dataFile.open ("pr.ber");

  // get size of the data file file  
  dataFile.seekg (0, ios::end);  
  int dataSize = dataFile.tellg();  
  dataFile.seekg (0);

  // read data from file into contiguous block for a buffer
  char data[dataSize];  
  dataFile.read (data, dataSize);  
  dataFile.close();  

  //  
  // put the BER data read from the file  
  // into buffer format, ready for reading from the  
  // beginning  
  //  
  AsnBuf inputBuf;  
  inputBuf.InstallData ((char*)data, dataSize);  

  size_t decodedLen;  
  ASNPerson p;

  if (!p.BDecPdu (inputBuf, decodedLen))  
    {  
      std::cerr << "ERROR - Decode routines failed, exiting..." << endl;  
        exit (1);  
    }  

#else
# error "Char Asn Decoding not implemented"
#endif

  /*
  ASNPerson p;
  const size_t dataSize = 10;
  char data[dataSize];
  size_t decodedLen;
  //buf.Init (data, dataSize);
  buf.ResetInReadMode();
  if (!p.BDecPdu ( buf, decodedLen ))
    {
      std::cerr << "Failed to decode Asn.1"<< std::endl;
      exit (1);
    }
  */
}
开发者ID:dreamsxin,项目名称:rainbrurpg,代码行数:53,代码来源:Person.cpp

示例8: BytesInLen

/* any's and these are the ONLY any's that should call this function.                         */
void AsnAny::BDecContent (const AsnBuf &b, AsnTag tag, AsnLen len, AsnLen &bytesDecoded)
{

    long lBytesToUnget = 0;
    
    lBytesToUnget += BytesInLen(len);
    lBytesToUnget += BytesInTag(tag);
      
    b.UnGetBytes(lBytesToUnget);
    anyBuf = new AsnBuf;
    b.GrabAny(*anyBuf, bytesDecoded);
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:13,代码来源:asn-any.cpp

示例9: multiCardSetTest

void multiCardSetTest()
{
   OctetStringSetOf octsSet;
   unsigned char test[10213];
   fillTestBuffer(test,10213);

   octsSet.insert(octsSet.end(), SNACC::AsnOcts())->Set((char*)test, 10213);

   std::cout << "**** LARGE SET OF OCTET STRING TEST ****\n";

   AsnBuf tmpBuf;
   AsnLen bytesEncoded = octsSet.BEnc(tmpBuf);
   checkBuf(tmpBuf);
   AsnLen bytesDecoded = 0;
   std::stringstream ss;
   ss << tmpBuf;
   

   OctetStringSetOf octsSet2;
   tmpBuf.ResetMode();
   octsSet2.BDec(tmpBuf, bytesDecoded);

   if (bytesEncoded != bytesDecoded)
   {
      std::cout << "Bytes encoded/decoded do not match\n";
   }

   if (checkTestBuffer(octsSet2.front().c_ustr(), octsSet2.front().Len()))
   {
      std::cout << "SUCCESS!\n";
   }
   else
   {
      std::cout << "FAILURE!\n";
   }

   std::cout << "**** END OF LARGE SET OF OCTET STRING TEST ****\n";
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:38,代码来源:testsetsorting.cpp

示例10: BDecContent

// Decodes a BER BIT STRING from the given buffer and stores
// the value in this object.
void AsnBits::BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded)
{
   FUNC("AsnBits::BDecContent");

	if (elmtLen == INDEFINITE_LEN || elmtLen > b.length())
	{
	   throw MemoryException(elmtLen, "elmtLen requests for too much data", STACK_ENTRY);
	}

   /*
    * tagId is encoded tag shifted into long int.
    * if CONS bit is set then constructed bit string
    */
   if (tagId & 0x20000000)
     BDecConsBits (b, elmtLen, bytesDecoded);

   else /* primitive octet string */
   {
     if (elmtLen == INDEFINITE_LEN)
        throw BoundsException("indefinite length on primitive", STACK_ENTRY);

	 if (elmtLen > b.length() || elmtLen <= 0)
        throw BoundsException("length problem on decoding content", STACK_ENTRY);

     bytesDecoded += elmtLen;
     elmtLen--;

	 unsigned int iUnusedBitLen= (unsigned int)b.GetByte();
	 if (iUnusedBitLen > 7)
        throw BoundsException("Length problem - Unused bits > 7", STACK_ENTRY);

     bitLen = (elmtLen * 8) - iUnusedBitLen;
     bits =  new unsigned char[elmtLen];
     b.GetUSeg (bits, elmtLen);
   }

} /* AsnBits::BDecContent */
开发者ID:,项目名称:,代码行数:39,代码来源:

示例11: ResetMode

bool AsnBuf::operator == (const AsnBuf &b) const
{
   bool equal = true;
   ResetMode();
   b.ResetMode();
   std::streambuf::int_type ch1;
   std::streambuf::int_type ch2;
   while ( equal )
   {
      try
      {
         ch1 = GetUByte();
      }
      catch (BufferException &)
      {
         ch1 = EOF;
      }

      try
      {
         ch2 = b.GetUByte();
      }
      catch (BufferException &)
      {
         ch2 = EOF;
      }

      if ((ch1 == EOF) && (ch1 == EOF))
         break;

      if (ch1 != ch2)
         equal = false;
   }
   ResetMode();
   b.ResetMode();
   return equal;
}
开发者ID:azsnaccbuilds,项目名称:esnacc-ng,代码行数:37,代码来源:asn-buf.cpp

示例12: splice

// insert()
//
// insert cards from b into this AsnBuf
//
// TBD: is it necessary to return the length?
//
long AsnBuf::splice(AsnBuf &b)
{
    if (m_card != m_deck.end() &&
        ((*m_card == NULL) || (*m_card)->length() == 0)) {
        delete *m_card;
        m_card = m_deck.erase(m_card);
    }

    long length = b.length();
    Deck::reverse_iterator ib;
    for (ib = b.m_deck.rbegin(); ib != b.m_deck.rend(); ++ib) {
        m_card = m_deck.insert(m_deck.begin(), *ib);
    }
    b.m_deck.clear();

    return length;
}
开发者ID:azsnaccbuilds,项目名称:esnacc-ng,代码行数:23,代码来源:asn-buf.cpp

示例13: if

// FUNCTION: BEnc()
// PUPROSE: Encode ANY DEFINED BY if "value" is present otherwise encode ANY if 
//          anyBuf is present.  If neither is present an exception is thrown.
//
AsnLen
AsnAny::BEnc (AsnBuf &b) const
{
   FUNC("AsnAny::BEnc()");

   if (value != NULL)
      return value->BEnc(b);
   else if (anyBuf != NULL)
   {
		anyBuf->ResetMode();
		b.insert(*anyBuf);
		return anyBuf->length();

   }
   else
      throw EXCEPT("Unknown any with no value", ENCODE_ERROR);
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:21,代码来源:asn-any.cpp

示例14: splice

// insert()
//
// insert cards from b into this AsnBuf
//
// TBD: is it necessary to return the length?
//
long AsnBuf::splice(AsnBuf &b)
{
    Deck::iterator ib = b.m_deck.end();
//#ifdef _DEBUG
//   Card *tmpCard = *ib;
//#endif
    long length = b.length();

    if (m_card != m_deck.end() && (*m_card)->length() == 0)
        m_card = m_deck.erase(m_card);

    do
    {
        ib--;
//#ifdef _DEBUG
//      tmpCard = *ib;
//#endif
        m_card = m_deck.insert(m_deck.begin(), *ib);
        ib = b.m_deck.erase(ib);
    } while (ib != b.m_deck.begin()) ;

    return length;
}
开发者ID:sunshi0583,项目名称:esnacc-ng,代码行数:29,代码来源:asn-buf.cpp

示例15: FUNC

// BDec()
//
// Decoded ANY DEFINED BY or UNKNOWN ANY from 'b'.  If an ANY DEFINED
// BY is found it's will be decoded into value.  If an UNKNOWN ANY is
// found it's binary values will be copied into 'anyBuf'.
//
void AsnAny::BDec (const AsnBuf &b, AsnLen &bytesDecoded)
{
   FUNC("AsnAny::BDec");

   // ai will be NULL if this is an ANY (not an ANY DEFINED BY)
   if (ai == NULL)
   {             
      anyBuf = new AsnBuf;
      b.GrabAny(*anyBuf, bytesDecoded);
   }
   else
   {
      // the type is already known clone it and use it's BDec to decode the 
      // ASN.1
      //
      value = ai->typeToClone->Clone();
      if (value == NULL)
      {
         throw SnaccException(STACK_ENTRY, "typeToClone->Clone() failed", INVALID_ANY);
      }
      else
         value->BDec (b, bytesDecoded);
   }
}
开发者ID:atigyi,项目名称:esnacc-ng,代码行数:30,代码来源:asn-any.cpp


注:本文中的AsnBuf类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。