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++; } }
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"); } }
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); } } }
void ControlParameters::wireDecode(const Block& block) { if (block.type() != tlv::nfd::ControlParameters) { throw Error("expecting TLV-TYPE ControlParameters"); } m_wire = block; m_wire.parse(); Block::element_const_iterator val; val = m_wire.find(tlv::Name); m_hasFields[CONTROL_PARAMETER_NAME] = val != m_wire.elements_end(); if (this->hasName()) { m_name.wireDecode(*val); } val = m_wire.find(tlv::nfd::FaceId); m_hasFields[CONTROL_PARAMETER_FACE_ID] = val != m_wire.elements_end(); if (this->hasFaceId()) { m_faceId = static_cast<uint64_t>(readNonNegativeInteger(*val)); } val = m_wire.find(tlv::nfd::Uri); m_hasFields[CONTROL_PARAMETER_URI] = val != m_wire.elements_end(); if (this->hasUri()) { m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size()); } val = m_wire.find(tlv::nfd::LocalControlFeature); m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = val != m_wire.elements_end(); if (this->hasLocalControlFeature()) { m_localControlFeature = static_cast<LocalControlFeature>(readNonNegativeInteger(*val)); } val = m_wire.find(tlv::nfd::Origin); m_hasFields[CONTROL_PARAMETER_ORIGIN] = val != m_wire.elements_end(); if (this->hasOrigin()) { m_origin = static_cast<uint64_t>(readNonNegativeInteger(*val)); } val = m_wire.find(tlv::nfd::Cost); m_hasFields[CONTROL_PARAMETER_COST] = val != m_wire.elements_end(); if (this->hasCost()) { m_cost = static_cast<uint64_t>(readNonNegativeInteger(*val)); } val = m_wire.find(tlv::nfd::Flags); m_hasFields[CONTROL_PARAMETER_FLAGS] = val != m_wire.elements_end(); if (this->hasFlags()) { m_flags = static_cast<uint64_t>(readNonNegativeInteger(*val)); } val = m_wire.find(tlv::nfd::Strategy); m_hasFields[CONTROL_PARAMETER_STRATEGY] = val != m_wire.elements_end(); if (this->hasStrategy()) { val->parse(); if (val->elements().empty()) { throw Error("expecting Strategy/Name"); } else { m_strategy.wireDecode(*val->elements_begin()); } } val = m_wire.find(tlv::nfd::ExpirationPeriod); m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = val != m_wire.elements_end(); if (this->hasExpirationPeriod()) { m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val)); } }