31 : m_interest(interest)
32 , m_dataSender(
std::
move(dataSender))
33 , m_nackSender(
std::
move(nackSender))
36 m_buffer.reserve(MAX_PAYLOAD_LENGTH);
42 if (m_state != State::INITIAL) {
43 NDN_THROW(std::logic_error(
"cannot call setPrefix() after append/end/reject"));
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"));
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 while (!bytes.empty()) {
73 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo++),
78 auto chunk = bytes.first(std::min(bytes.size(), MAX_PAYLOAD_LENGTH - m_buffer.size()));
79 m_buffer.insert(m_buffer.end(), chunk.begin(), chunk.end());
80 bytes = bytes.subspan(chunk.size());
87 if (m_state == State::FINALIZED) {
88 NDN_THROW(std::logic_error(
"cannot call end() on a finalized context"));
91 m_state = State::FINALIZED;
94 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo),
101 if (m_state != State::INITIAL) {
102 NDN_THROW(std::logic_error(
"cannot call reject() after append/end"));
105 m_state = State::FINALIZED;
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
Rejects the request.
Copyright (c) 2011-2015 Regents of the University of California.
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Represents an Interest packet.
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...
std::function< void(const ControlResponse &)> NackSender
bool isSegment() const
Check if the component is a segment number per NDN naming conventions.
void end()
Finalizes the response successfully after appending zero or more blocks.
Represents an absolute name.
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
void append(span< const uint8_t > bytes)
Appends a sequence of bytes to the response.
const Name & getName() const noexcept
StatusDatasetContext & setPrefix(const Name &prefix)
Changes the prefix of the response Data packets.
const size_t MAX_PAYLOAD_LENGTH
bool isVersion() const
Check if the component is a version per NDN naming conventions.
Provides a context for generating the response to a StatusDataset request.
StatusDatasetContext(const Interest &interest, DataSender dataSender, NackSender nackSender)
const size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.