size_t Interest::wireEncode(EncodingImpl<TAG>& block) const { size_t totalLength = 0; // Interest ::= INTEREST-TYPE TLV-LENGTH // Name // Selectors? // Nonce // Scope? // InterestLifetime? // Link? // SelectedDelegation? // (reverse encoding) if (hasLink()) { if (hasSelectedDelegation()) { totalLength += prependNonNegativeIntegerBlock(block, tlv::SelectedDelegation, m_selectedDelegationIndex); } totalLength += prependBlock(block, m_link); } else { BOOST_ASSERT(!hasSelectedDelegation()); } // InterestLifetime if (getInterestLifetime() >= time::milliseconds::zero() && getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { totalLength += prependNonNegativeIntegerBlock(block, tlv::InterestLifetime, getInterestLifetime().count()); } // Scope if (getScope() >= 0) { totalLength += prependNonNegativeIntegerBlock(block, tlv::Scope, getScope()); } // Nonce getNonce(); // to ensure that Nonce is properly set totalLength += block.prependBlock(m_nonce); // Selectors if (hasSelectors()) { totalLength += getSelectors().wireEncode(block); } // Name totalLength += getName().wireEncode(block); totalLength += block.prependVarNumber(totalLength); totalLength += block.prependVarNumber(tlv::Interest); return totalLength; }
size_t MetaInfo::wireEncode(EncodingImpl<T>& blk) const { // MetaInfo ::= META-INFO-TYPE TLV-LENGTH // ContentType? // FreshnessPeriod? // FinalBlockId? // AppMetaInfo* size_t totalLength = 0; for (std::list<Block>::const_reverse_iterator appMetaInfoItem = m_appMetaInfo.rbegin(); appMetaInfoItem != m_appMetaInfo.rend(); ++appMetaInfoItem) { totalLength += prependBlock(blk, *appMetaInfoItem); } // FinalBlockId if (!m_finalBlockId.empty()) { totalLength += prependNestedBlock(blk, tlv::FinalBlockId, m_finalBlockId); } // FreshnessPeriod if (m_freshnessPeriod >= time::milliseconds::zero()) { totalLength += prependNonNegativeIntegerBlock(blk, tlv::FreshnessPeriod, m_freshnessPeriod.count()); } // ContentType if (m_type != TYPE_DEFAULT) { totalLength += prependNonNegativeIntegerBlock(blk, tlv::ContentType, m_type); } totalLength += blk.prependVarNumber(totalLength); totalLength += blk.prependVarNumber(tlv::MetaInfo); return totalLength; }
size_t Manifest::wireEncode(EncodingImpl<T>& blk) const { // Manifest ::= CONTENT-TLV TLV-LENGTH // Catalogue? // Name* // KeyValuePair* size_t totalLength = 0; size_t catalogueLength = 0; for (std::map<std::string, std::string>::const_reverse_iterator it = m_keyValuePairs.rbegin(); it != m_keyValuePairs.rend(); ++it) { std::string keyValue = it->first + "=" + it->second; totalLength += blk.prependByteArray(reinterpret_cast<const uint8_t*>(keyValue.c_str()), keyValue.size()); totalLength += blk.prependVarNumber(keyValue.size()); totalLength += blk.prependVarNumber(tlv::KeyValuePair); } for (std::list<Name>::const_reverse_iterator it = m_catalogueNames.rbegin(); it != m_catalogueNames.rend(); ++it) { size_t blockSize = prependBlock(blk, it->wireEncode()); totalLength += blockSize; catalogueLength += blockSize; } if (catalogueLength > 0) { totalLength += blk.prependVarNumber(catalogueLength); totalLength += blk.prependVarNumber(tlv::ManifestCatalogue); } //totalLength += blk.prependVarNumber(totalLength); //totalLength += blk.prependVarNumber(tlv::Content); return totalLength; }