本文整理汇总了C++中block::element_const_iterator::type方法的典型用法代码示例。如果您正苦于以下问题:C++ element_const_iterator::type方法的具体用法?C++ element_const_iterator::type怎么用?C++ element_const_iterator::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类block::element_const_iterator
的用法示例。
在下文中一共展示了element_const_iterator::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Error
void
StrategyChoice::wireDecode(const Block& block)
{
if (block.type() != tlv::nfd::StrategyChoice) {
throw Error("expecting StrategyChoice block");
}
m_wire = block;
m_wire.parse();
Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == tlv::Name) {
m_name.wireDecode(*val);
++val;
}
else {
throw Error("missing required Name field");
}
if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
val->parse();
if (val->elements().empty()) {
throw Error("expecting Strategy/Name");
}
else {
m_strategy.wireDecode(*val->elements_begin());
}
++val;
}
else {
throw Error("missing required Strategy field");
}
}
示例2: while
void
Schedule::wireDecode(const Block& wire)
{
if (wire.type() != tlv::Schedule)
BOOST_THROW_EXCEPTION(tlv::Error("Unexpected TLV type when decoding RepetitiveInterval"));
m_wire = wire;
m_wire.parse();
if (m_wire.elements_size() != 2)
BOOST_THROW_EXCEPTION(tlv::Error("RepetitiveInterval tlv does not have two sub-TLVs"));
Block::element_const_iterator it = m_wire.elements_begin();
if (it != m_wire.elements_end() && it->type() == tlv::WhiteIntervalList) {
it->parse();
Block::element_const_iterator tempIt = it->elements_begin();
while (tempIt != it->elements_end() && tempIt->type() == tlv::RepetitiveInterval) {
m_whiteIntervalList.insert(RepetitiveInterval(*tempIt));
tempIt++;
}
it++;
}
if (it != m_wire.elements_end() && it->type() == tlv::BlackIntervalList) {
it->parse();
Block::element_const_iterator tempIt = it->elements_begin();
while (tempIt != it->elements_end() && tempIt->type() == tlv::RepetitiveInterval) {
m_blackIntervalList.insert(RepetitiveInterval(*tempIt));
tempIt++;
}
it++;
}
}
示例3: Error
void
EndorseExtension::wireDecode(const Block& endorseWire)
{
m_wire = endorseWire;
m_wire.parse();
// EndorseExtension := ENDORSE-EXTENSION-TYPE TLV-LENGTH
// EntryData+
//
// EntryData := ENTRYDATA-TYPE TLV-LENGTH
// String
//
if (m_wire.type() != tlv::EndorseExtension)
throw Error("Unexpected TLV number when decoding endorse extension packet");
// EntryData
Block::element_const_iterator i = m_wire.elements_begin();
if (i == m_wire.elements_end())
throw Error("Missing Entry Data");
if (i->type() != tlv::EntryData)
throw Error("Expect Entry Data but get TLV Type " + std::to_string(i->type()));
while (i != m_wire.elements_end() && i->type() == tlv::EntryData) {
m_entries.push_back(std::string(reinterpret_cast<const char* >(i->value()),
i->value_size()));
++i;
}
if (i != m_wire.elements_end()) {
throw Error("Unexpected element");
}
}
示例4: parser
void
decodeFibEntryBlock(const Data& data)
{
Block payload = data.getContent();
m_buffer.appendByteArray(payload.value(), payload.value_size());
BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment());
if (data.getFinalBlockId() != data.getName()[-1])
{
return;
}
// wrap the FIB Entry blocks in a single Content TLV for easy parsing
m_buffer.prependVarNumber(m_buffer.size());
m_buffer.prependVarNumber(ndn::Tlv::Content);
ndn::Block parser(m_buffer.buf(), m_buffer.size());
parser.parse();
BOOST_REQUIRE_EQUAL(parser.elements_size(), m_referenceEntries.size());
for (Block::element_const_iterator i = parser.elements_begin();
i != parser.elements_end();
++i)
{
if (i->type() != ndn::tlv::nfd::FibEntry)
{
BOOST_FAIL("expected fib entry, got type #" << i->type());
}
validateFibEntry(*i);
}
m_finished = true;
}
示例5: Error
void
DefaultParam::wireDecode(const Block& wire)
{
if (!wire.hasWire()) {
throw Error("The supplied block does not contain wire format");
}
m_wire = wire;
m_wire.parse();
if (m_wire.type() != tlv::pib::DefaultParam)
throw Error("Unexpected TLV type when decoding DefaultParam");
Block::element_const_iterator it = m_wire.elements_begin();
// the first block must be PibType
if (it != m_wire.elements_end() && it->type() == tlv::pib::Type) {
m_targetType = static_cast<pib::Type>(readNonNegativeInteger(*it));
it++;
}
else
throw Error("DefaultParam requires the first sub-TLV to be PibType");
// the second block must be PibType
if (it != m_wire.elements_end() && it->type() == tlv::pib::Type) {
m_originType = static_cast<pib::Type>(readNonNegativeInteger(*it));
it++;
}
else
throw Error("DefaultParam requires the second sub-TLV to be PibType");
switch (m_originType) {
case TYPE_ID:
case TYPE_KEY:
case TYPE_CERT:
{
if (it != m_wire.elements_end()) {
// the third block, if exists, must be Name
m_originName.wireDecode(*it);
return;
}
else {
throw Error("DefaultParam requires the third sub-TLV to be Name");
}
}
case TYPE_USER:
return;
default:
throw Error("DefaultParam::wireDecode: unsupported PibType: " +
boost::lexical_cast<std::string>(m_originType));
}
}
示例6: 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);
}
}
示例7: Error
void
Exclude::wireDecode(const Block& wire)
{
clear();
if (wire.type() != tlv::Exclude)
throw tlv::Error("Unexpected TLV type when decoding Exclude");
m_wire = wire;
m_wire.parse();
if (m_wire.elements_size() == 0) {
throw Error("Exclude element cannot be empty");
}
// Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+
// Any ::= ANY-TYPE TLV-LENGTH(=0)
Block::element_const_iterator i = m_wire.elements_begin();
if (i->type() == tlv::Any)
{
appendExclude(name::Component(), true);
++i;
}
while (i != m_wire.elements_end())
{
if (i->type() != tlv::NameComponent)
throw Error("Incorrect format of Exclude filter");
name::Component excludedComponent(i->value(), i->value_size());
++i;
if (i != m_wire.elements_end())
{
if (i->type() == tlv::Any)
{
appendExclude(excludedComponent, true);
++i;
}
else
{
appendExclude(excludedComponent, false);
}
}
else
{
appendExclude(excludedComponent, false);
}
}
}
示例8: clear
void
Exclude::wireDecode(const Block& wire)
{
clear();
if (wire.type() != tlv::Exclude)
BOOST_THROW_EXCEPTION(tlv::Error("Unexpected TLV type when decoding Exclude"));
m_wire = wire;
m_wire.parse();
if (m_wire.elements_size() == 0) {
BOOST_THROW_EXCEPTION(Error("Exclude element cannot be empty"));
}
// Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+
// Any ::= ANY-TYPE TLV-LENGTH(=0)
Block::element_const_iterator i = m_wire.elements_begin();
if (i->type() == tlv::Any) {
appendExclude(name::Component(), true);
++i;
}
while (i != m_wire.elements_end()) {
name::Component excludedComponent;
try {
excludedComponent = name::Component(*i);
}
catch (const name::Component::Error&) {
BOOST_THROW_EXCEPTION(Error("Incorrect format of Exclude filter"));
}
++i;
if (i != m_wire.elements_end()) {
if (i->type() == tlv::Any) {
appendExclude(excludedComponent, true);
++i;
}
else {
appendExclude(excludedComponent, false);
}
}
else {
appendExclude(excludedComponent, false);
}
}
}
示例9: wireDecode
void
wireDecode(const Block& block)
{
if (block.type() != statusCollector::tlv::ScriptPacket)
{
std::stringstream error;
error << "Expected ScriptPacket block, but block is of different type: #" << block.type();
std::cerr << error.str() << std::endl;
}
m_block = block;
m_block.parse();
Block::element_const_iterator val = m_block.elements_begin();
Block::element_const_iterator oldVal;
while (val != m_block.elements_end())
{
oldVal = val;
if (val != m_block.elements_end() && val->type() == ndn::statusCollector::tlv::ScriptData)
{
m_data.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
++val;
}
if(oldVal == val)
{
std::cout << "ERROR!!: About to exit" << std::endl;
exit(1);
}
}
}
示例10: clear
void
Exclude::wireDecode(const Block& wire)
{
clear();
if (wire.type() != tlv::Exclude)
BOOST_THROW_EXCEPTION(tlv::Error("Unexpected TLV type when decoding Exclude"));
m_wire = wire;
m_wire.parse();
if (m_wire.elements_size() == 0) {
BOOST_THROW_EXCEPTION(Error("Exclude element cannot be empty"));
}
// Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (GenericNameComponent (Any)?)+
// Any ::= ANY-TYPE TLV-LENGTH(=0)
Block::element_const_iterator i = m_wire.elements_begin();
if (i->type() == tlv::Any) {
this->appendEntry(true, true);
++i;
}
while (i != m_wire.elements_end()) {
name::Component component;
try {
component = name::Component(*i);
}
catch (const name::Component::Error&) {
BOOST_THROW_EXCEPTION(Error("Incorrect format of Exclude filter"));
}
if (!component.isGeneric() && !component.isImplicitSha256Digest()) {
BOOST_THROW_EXCEPTION(Error("Excluded component must be generic or ImplicitSha256Digest"));
}
++i;
if (i != m_wire.elements_end() && i->type() == tlv::Any) {
this->appendEntry(component, true);
++i;
}
else {
this->appendEntry(component, false);
}
}
}
示例11: prefix
void
validateFibEntry(const Block& entry)
{
entry.parse();
Block::element_const_iterator i = entry.elements_begin();
BOOST_REQUIRE(i != entry.elements_end());
BOOST_REQUIRE(i->type() == ndn::Tlv::Name);
Name prefix(*i);
++i;
std::set<shared_ptr<fib::Entry> >::const_iterator referenceIter =
std::find_if(m_referenceEntries.begin(), m_referenceEntries.end(),
bind(&FibEnumerationPublisherFixture::entryHasPrefix,
this, _1, prefix));
BOOST_REQUIRE(referenceIter != m_referenceEntries.end());
const shared_ptr<fib::Entry>& reference = *referenceIter;
BOOST_REQUIRE_EQUAL(prefix, reference->getPrefix());
// 0 or more next hop records
size_t nRecords = 0;
const fib::NextHopList& referenceNextHops = reference->getNextHops();
for (; i != entry.elements_end(); ++i)
{
const ndn::Block& nextHopRecord = *i;
BOOST_REQUIRE(nextHopRecord.type() == ndn::tlv::nfd::NextHopRecord);
nextHopRecord.parse();
Block::element_const_iterator j = nextHopRecord.elements_begin();
FaceId faceId =
checkedReadNonNegativeIntegerType(j,
entry.elements_end(),
ndn::tlv::nfd::FaceId);
uint64_t cost =
checkedReadNonNegativeIntegerType(j,
entry.elements_end(),
ndn::tlv::nfd::Cost);
BOOST_REQUIRE(hasNextHopWithCost(referenceNextHops, faceId, cost));
BOOST_REQUIRE(j == nextHopRecord.elements_end());
nRecords++;
}
BOOST_REQUIRE_EQUAL(nRecords, referenceNextHops.size());
BOOST_REQUIRE(i == entry.elements_end());
m_referenceEntries.erase(referenceIter);
}
示例12: name
void
Manifest::decode()
{
Block content = getContent();
content.parse();
// Manifest ::= CONTENT-TLV TLV-LENGTH
// Catalogue?
// Name*
// KeyValuePair*
for ( Block::element_const_iterator val = content.elements_begin();
val != content.elements_end(); ++val)
{
if (val->type() == tlv::ManifestCatalogue)
{
val->parse();
for ( Block::element_const_iterator catalogueNameElem = val->elements_begin();
catalogueNameElem != val->elements_end(); ++catalogueNameElem)
{
if (catalogueNameElem->type() == tlv::Name)
{
Name name(*catalogueNameElem);
m_catalogueNames.push_back(name);
}
}
}
else if (val->type() == tlv::KeyValuePair)
{
std::string str((char*)val->value(), val->value_size());
size_t index = str.find_first_of('=');
if (index == std::string::npos || index == 0 || (index == str.size() - 1))
continue;
std::string key = str.substr(0, index);
std::string value = str.substr(index + 1, str.size() - index - 1);
addKeyValuePair(key, value);
}
}
}
示例13: if
void
NextHopRecord::wireDecode(const Block& wire)
{
m_faceId = std::numeric_limits<uint64_t>::max();
m_cost = 0;
m_wire = wire;
if (m_wire.type() != tlv::nfd::NextHopRecord) {
std::stringstream error;
error << "Requested decoding of NextHopRecord, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
Block::element_const_iterator val = m_wire.elements_begin();
if (val == m_wire.elements_end()) {
BOOST_THROW_EXCEPTION(Error("Unexpected end of NextHopRecord"));
}
else if (val->type() != tlv::nfd::FaceId) {
std::stringstream error;
error << "Expected FaceId, but Block is of a different type: #"
<< val->type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_faceId = readNonNegativeInteger(*val);
++val;
if (val == m_wire.elements_end()) {
BOOST_THROW_EXCEPTION(Error("Unexpected end of NextHopRecord"));
}
else if (val->type() != tlv::nfd::Cost) {
std::stringstream error;
error << "Expected Cost, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_cost = readNonNegativeInteger(*val);
}
示例14: Error
void
RibEntry::wireDecode(const Block& wire)
{
m_prefix.clear();
m_routes.clear();
m_wire = wire;
if (m_wire.type() != tlv::nfd::RibEntry) {
std::stringstream error;
error << "Expected RibEntry Block, but Block is of a different type: #"
<< m_wire.type();
throw Error(error.str());
}
m_wire.parse();
Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == tlv::Name) {
m_prefix.wireDecode(*val);
++val;
}
else {
throw Error("Missing required Name field");
}
for (; val != m_wire.elements_end(); ++val) {
if (val->type() == tlv::nfd::Route) {
m_routes.push_back(Route(*val));
}
else {
std::stringstream error;
error << "Expected Route Block, but Block is of a different type: #"
<< m_wire.type();
throw Error(error.str());
}
}
}
示例15: parser
static void
decodeRibEntryBlock(const Data& data, const Name& referenceName, const FaceEntry& referenceFace)
{
ndn::EncodingBuffer buffer;
Block payload = data.getContent();
buffer.appendByteArray(payload.value(), payload.value_size());
buffer.prependVarNumber(buffer.size());
buffer.prependVarNumber(ndn::Tlv::Content);
ndn::Block parser(buffer.buf(), buffer.size());
parser.parse();
Block::element_const_iterator i = parser.elements_begin();
if (i->type() != ndn::tlv::nfd::RibEntry) {
BOOST_FAIL("expected RibEntry, got type #" << i->type());
}
else {
validateRibEntry(*i, referenceName, referenceFace);
}
}