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(span<const uint8_t> bytes)
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());
85 StatusDatasetContext::end()
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;
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 noexcept
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.