28 StatusDatasetContext::StatusDatasetContext(
const Interest& interest,
29 DataSender dataSender, NackSender nackSender)
30 : m_interest(interest)
31 , m_dataSender(std::move(dataSender))
32 , m_nackSender(std::move(nackSender))
39 StatusDatasetContext::setPrefix(
const Name& prefix)
41 if (m_state != State::INITIAL) {
42 NDN_THROW(std::logic_error(
"cannot call setPrefix() after append/end/reject"));
45 if (!m_interest.getName().isPrefixOf(prefix)) {
46 NDN_THROW(std::invalid_argument(
"prefix must start with the Interest's name"));
50 NDN_THROW(std::invalid_argument(
"prefix must not contain a segment component"));
54 if (!m_prefix.at(-1).isVersion()) {
62 StatusDatasetContext::append(span<const uint8_t> bytes)
64 if (m_state == State::FINALIZED) {
65 NDN_THROW(std::logic_error(
"cannot call append() on a finalized context"));
68 m_state = State::RESPONDED;
70 while (!bytes.empty()) {
72 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo++),
77 auto chunk = bytes.first(std::min(bytes.size(),
MAX_PAYLOAD_LENGTH - m_buffer.size()));
78 m_buffer.insert(m_buffer.end(), chunk.begin(), chunk.end());
79 bytes = bytes.subspan(chunk.size());
84 StatusDatasetContext::end()
86 if (m_state == State::FINALIZED) {
87 NDN_THROW(std::logic_error(
"cannot call end() on a finalized context"));
90 m_state = State::FINALIZED;
93 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo),
100 if (m_state != State::INITIAL) {
101 NDN_THROW(std::logic_error(
"cannot call reject() after append/end"));
104 m_state = State::FINALIZED;
Represents an Interest packet.
const Name & getName() const noexcept
Get the Interest name.
Represents an absolute name.
Name & appendVersion(const std::optional< uint64_t > &version=std::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.
constexpr size_t MAX_PAYLOAD_LENGTH
constexpr size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.