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


C++ element_const_iterator::blockFromValue方法代码示例

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


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

示例1: readNonNegativeInteger

void
MetaInfo::wireDecode(const Block& wire)
{
  m_wire = wire;
  m_wire.parse();

  // MetaInfo ::= META-INFO-TYPE TLV-LENGTH
  //                ContentType?
  //                FreshnessPeriod?
  //                FinalBlockId?
  //                AppMetaInfo*


  Block::element_const_iterator val = m_wire.elements_begin();

  // ContentType
  if (val != m_wire.elements_end() && val->type() == tlv::ContentType) {
    m_type = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    m_type = TYPE_DEFAULT;
  }

  // FreshnessPeriod
  if (val != m_wire.elements_end() && val->type() == tlv::FreshnessPeriod) {
    m_freshnessPeriod = time::milliseconds(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    m_freshnessPeriod = time::milliseconds::min();
  }

  // FinalBlockId
  if (val != m_wire.elements_end() && val->type() == tlv::FinalBlockId) {
    m_finalBlockId = val->blockFromValue();
    if (m_finalBlockId.type() != tlv::NameComponent)
      {
        /// @todo May or may not throw exception later...
        m_finalBlockId.reset();
      }
    ++val;
  }
  else {
    m_finalBlockId.reset();
  }

  // AppMetaInfo (if any)
  for (; val != m_wire.elements().end(); ++val) {
    m_appMetaInfo.push_back(*val);
  }
}
开发者ID:nnaren1902,项目名称:ndn-cxx,代码行数:52,代码来源:meta-info.cpp

示例2: Error

void
ChatroomInfo::wireDecode(const Block& chatroomWire)
{
  m_wire = chatroomWire;
  m_wire.parse();

  m_participants.clear();

  // ChatroomInfo := CHATROOM-INFO-TYPE TLV-LENGTH
  //                   ChatroomName
  //                   TrustModel
  //                   ChatroomPrefix
  //                   ManagerPrefix
  //                   Participants
  //
  // ChatroomName := CHATROOM-NAME-TYPE TLV-LENGTH
  //                   NameComponent
  //
  // TrustModel := TRUST-MODEL-TYPE TLV-LENGTH
  //                 nonNegativeInteger
  //
  // ChatroomPrefix := CHATROOM-PREFIX-TYPE TLV-LENGTH
  //                     Name
  //
  // ManagerPrefix := MANAGER-PREFIX-TYPE TLV-LENGTH
  //                    Name
  //
  // Participants := PARTICIPANTS-TYPE TLV-LENGTH
  //                   Name+

  if (m_wire.type() != tlv::ChatroomInfo)
    throw Error("Unexpected TLV number when decoding chatroom packet");

  // Chatroom Info
  Block::element_const_iterator i = m_wire.elements_begin();
  if (i == m_wire.elements_end())
    throw Error("Missing Chatroom Name");
  if (i->type() != tlv::ChatroomName)
    throw Error("Expect Chatroom Name but get TLV Type " + std::to_string(i->type()));
  m_chatroomName.wireDecode(i->blockFromValue());
  ++i;

  // Trust Model
  if (i == m_wire.elements_end())
    throw Error("Missing Trust Model");
  if (i->type() != tlv::TrustModel)
    throw Error("Expect Trust Model but get TLV Type " + std::to_string(i->type()));
  m_trustModel =
      static_cast<TrustModel>(readNonNegativeInteger(*i));
  ++i;

  // Chatroom Sync Prefix
  if (i == m_wire.elements_end())
    throw Error("Missing Chatroom Prefix");
  if (i->type() != tlv::ChatroomPrefix)
    throw Error("Expect Chatroom Prefix but get TLV Type " + std::to_string(i->type()));
  m_syncPrefix.wireDecode(i->blockFromValue());
  ++i;

  // Manager Prefix
  if (i == m_wire.elements_end())
    throw Error("Missing Manager Prefix");
  if (i->type() != tlv::ManagerPrefix)
    throw Error("Expect Manager Prefix but get TLV Type " + std::to_string(i->type()));
  m_manager.wireDecode(i->blockFromValue());
  ++i;

  // Participants
  if (i == m_wire.elements_end())
    throw Error("Missing Participant");
  if (i->type() != tlv::Participants)
    throw Error("Expect Participant but get TLV Type " + std::to_string(i->type()));

  Block temp = *i;
  temp.parse();

  Block::element_const_iterator j = temp.elements_begin();

  while (j != temp.elements_end() && j->type() == tlv::Name) {
    m_participants.push_back(Name(*j));
    ++j;
  }
  if (j != temp.elements_end())
    throw Error("Unexpected element");

  if (m_participants.empty())
    throw Error("No participant in the chatroom");

  ++i;

  if (i != m_wire.elements_end()) {
    throw Error("Unexpected element");
  }
}
开发者ID:named-data,项目名称:ChronoChat,代码行数:94,代码来源:chatroom-info.cpp


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