本文整理汇总了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);
}
}
示例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");
}
}