size_t Interest::encode03(EncodingImpl<TAG>& encoder) const { size_t totalLength = 0; // Encode as NDN Packet Format v0.3 // Interest ::= INTEREST-TYPE TLV-LENGTH // Name // CanBePrefix? // MustBeFresh? // ForwardingHint? // Nonce? // InterestLifetime? // HopLimit? // ApplicationParameters? // (reverse encoding) // ApplicationParameters if (hasApplicationParameters()) { totalLength += encoder.prependBlock(getApplicationParameters()); } // HopLimit: not yet supported // InterestLifetime if (getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { totalLength += prependNonNegativeIntegerBlock(encoder, tlv::InterestLifetime, static_cast<uint64_t>(getInterestLifetime().count())); } // Nonce uint32_t nonce = getNonce(); // if nonce was unset, getNonce generates a random nonce totalLength += encoder.prependByteArrayBlock(tlv::Nonce, reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce)); // ForwardingHint if (!getForwardingHint().empty()) { totalLength += getForwardingHint().wireEncode(encoder); } // MustBeFresh if (getMustBeFresh()) { totalLength += prependEmptyBlock(encoder, tlv::MustBeFresh); } // CanBePrefix if (getCanBePrefix()) { totalLength += prependEmptyBlock(encoder, tlv::CanBePrefix); } // Name totalLength += getName().wireEncode(encoder); totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::Interest); return totalLength; }
size_t Exclude::wireEncode(EncodingImpl<TAG>& encoder) const { if (m_exclude.empty()) { throw Error("Exclude filter cannot be empty"); } size_t totalLength = 0; // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+ // Any ::= ANY-TYPE TLV-LENGTH(=0) for (const auto& item : m_exclude) { if (item.second) { totalLength += prependEmptyBlock(encoder, tlv::Any); } if (!item.first.empty() || !item.second) { totalLength += item.first.wireEncode(encoder); } } totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::Exclude); return totalLength; }
size_t Exclude::wireEncode(EncodingImpl<TAG>& encoder) const { if (m_entries.empty()) { BOOST_THROW_EXCEPTION(Error("cannot encode empty Exclude selector")); } size_t totalLength = 0; // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (GenericNameComponent (Any)?)+ // Any ::= ANY-TYPE TLV-LENGTH(=0) for (const Entry& entry : m_entries) { if (entry.second) { totalLength += prependEmptyBlock(encoder, tlv::Any); } if (!entry.first.isNegInf) { totalLength += entry.first.component.wireEncode(encoder); } } totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::Exclude); return totalLength; }
size_t prependBooleanBlock(EncodingImpl<TAG>& encoder, uint32_t type) { return prependEmptyBlock(encoder, type); }