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


C++ Consumer::consume方法代码示例

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


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

示例1: processPayload

 void
 processPayload(Consumer& c, const uint8_t* buffer, size_t bufferSize)
 {
   std::string content1((char*)buffer, bufferSize);
   
   std::cout << "REASSEMBLED " << content1 << std::endl;
   std::cout << "Size " << bufferSize << std::endl;
   
   // chaining call
   if (!flag)
   {
     flag = true;
     std::cout << "consume zzz" << std::endl;
     c.consume(Name("zzz"));
   }
 }
开发者ID:pedosb,项目名称:Consumer-Producer-API,代码行数:16,代码来源:rdr-chaining-consumer.cpp

示例2: if

TEST_F(TestConsumer, CosumerWithLink)
{
  ptr_lib::shared_ptr<Data> contentData = createEncryptedContent();
  ptr_lib::shared_ptr<Data> cKeyData = createEncryptedCKey();
  ptr_lib::shared_ptr<Data> dKeyData = createEncryptedDKey();

  int contentCount = 0;
  int cKeyCount = 0;
  int dKeyCount = 0;

  // Prepare a TestFace to instantly answer calls to expressInterest.
  class TestFace : public Face {
  public:
    TestFace(ptr_lib::shared_ptr<Data> contentData,
             ptr_lib::shared_ptr<Data> cKeyData,
             ptr_lib::shared_ptr<Data> dKeyData,
             int* contentCount, int* cKeyCount, int* dKeyCount)
    : Face("localhost"),
      contentData_(contentData),
      cKeyData_(cKeyData),
      dKeyData_(dKeyData),
      contentCount_(contentCount),
      cKeyCount_(cKeyCount),
      dKeyCount_(dKeyCount)
    {}

    virtual uint64_t
    expressInterest
      (const Interest& interest, const OnData& onData,
       const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
       WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
    {
      if (interest.getLink()->getDelegations().size() != 3)
        throw runtime_error
          ("TestFace::expressInterest: The Interest link does not the expected number of delegates");

      if (interest.matchesName(contentData_->getName())) {
        *contentCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), contentData_);
      }
      else if (interest.matchesName(cKeyData_->getName())) {
        *cKeyCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), cKeyData_);
      }
      else if (interest.matchesName(dKeyData_->getName())) {
        *dKeyCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), dKeyData_);
      }
      else
        onTimeout(ptr_lib::make_shared<Interest>(interest));

      return 0;
    }

  private:
    ptr_lib::shared_ptr<Data> contentData_;
    ptr_lib::shared_ptr<Data> cKeyData_;
    ptr_lib::shared_ptr<Data> dKeyData_;

    int* contentCount_;
    int* cKeyCount_;
    int* dKeyCount_;
  };

  TestFace face
    (contentData, cKeyData, dKeyData, &contentCount, &cKeyCount, &dKeyCount);

  // Create the consumer.
  Link ckeyLink;
  ckeyLink.addDelegation(10,  Name("/ckey1"));
  ckeyLink.addDelegation(20,  Name("/ckey2"));
  ckeyLink.addDelegation(100, Name("/ckey13"));
  Link dkeyLink;
  dkeyLink.addDelegation(10,  Name("/dkey1"));
  dkeyLink.addDelegation(20,  Name("/dkey2"));
  dkeyLink.addDelegation(100, Name("/dkey13"));
  Link dataLink;
  dataLink.addDelegation(10,  Name("/data1"));
  dataLink.addDelegation(20,  Name("/data2"));
  dataLink.addDelegation(100, Name("/data13"));
  keyChain->sign(ckeyLink);
  keyChain->sign(dkeyLink);
  keyChain->sign(dataLink);

  Consumer consumer
    (&face, keyChain.get(), groupName, uName,
     ptr_lib::make_shared<Sqlite3ConsumerDb>(databaseFilePath),
     ckeyLink, dkeyLink);
  consumer.addDecryptionKey(uKeyName, fixtureUDKeyBlob);

  int finalCount = 0;
  consumer.consume
    (contentName,
     bind(&TestConsumer::onConsumeComplete, this, _1, _2, &finalCount),
     bind(&TestConsumer::onError, this, _1, _2), dataLink);

  ASSERT_EQ(1, contentCount);
  ASSERT_EQ(1, cKeyCount);
  ASSERT_EQ(1, dKeyCount);
  ASSERT_EQ(1, finalCount);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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