29 StatusDatasetContext::StatusDatasetContext(
const Interest& interest,
30 DataSender dataSender, NackSender nackSender)
31 : m_interest(interest)
32 , m_dataSender(std::move(dataSender))
33 , m_nackSender(std::move(nackSender))
40 StatusDatasetContext::setPrefix(
const Name& prefix)
42 if (m_state != State::INITIAL) {
43 NDN_THROW(std::logic_error(
"cannot call setPrefix() after append/end/reject"));
46 if (!m_interest.getName().isPrefixOf(prefix)) {
47 NDN_THROW(std::invalid_argument(
"prefix must start with the Interest's name"));
51 NDN_THROW(std::invalid_argument(
"prefix must not contain a segment component"));
55 if (!m_prefix.at(-1).isVersion()) {
63 StatusDatasetContext::append(
const Block& block)
65 if (m_state == State::FINALIZED) {
66 NDN_THROW(std::logic_error(
"cannot call append() on a finalized context"));
69 m_state = State::RESPONDED;
71 auto cur = block.
begin();
72 while (cur != block.
end()) {
73 auto nBytesToAppend = std::min<std::ptrdiff_t>(std::distance(cur, block.
end()),
75 auto next = std::next(cur, nBytesToAppend);
76 m_buffer.insert(m_buffer.end(), cur, next);
79 if (cur != block.
end()) {
81 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo++),
90 StatusDatasetContext::end()
92 if (m_state == State::FINALIZED) {
93 NDN_THROW(std::logic_error(
"cannot call end() on a finalized context"));
96 m_state = State::FINALIZED;
97 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo),
105 if (m_state != State::INITIAL) {
106 NDN_THROW(std::logic_error(
"cannot call reject() after append/end"));
109 m_state = State::FINALIZED;
Represents a TLV element of the NDN packet format.
Buffer::const_iterator begin() const
Get begin iterator of encoded wire.
Buffer::const_iterator end() const
Get end iterator of encoded wire.
Represents an Interest packet.
const Name & getName() const noexcept
Represents an absolute name.
Name & appendVersion(const optional< uint64_t > &version=nullopt)
Append a version component.
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking.
bool isSegment() const
Check if the component is a segment number per NDN naming conventions.
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
const size_t MAX_PAYLOAD_LENGTH
const size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.