From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
#include "capture.hpp"
|
|
|
|
namespace capture {
|
|
Status book_reset(Book* book)
|
|
{
|
|
if (book == nullptr) {
|
|
return Status::invalid;
|
|
}
|
|
for (Entry& entry : book->entries) {
|
|
entry = Entry{};
|
|
}
|
|
book->accepted = 0;
|
|
return Status::ok;
|
|
}
|
|
|
|
Status book_capture(Book* book, std::uint32_t channel,
|
|
std::int64_t sec, std::int64_t nsec,
|
|
const std::vector<std::uint8_t>& payload)
|
|
{
|
|
if (book == nullptr || channel >= channel_count) {
|
|
return Status::invalid;
|
|
}
|
|
if (payload.size() > payload_limit) {
|
|
return Status::capacity;
|
|
}
|
|
Stamp normalized;
|
|
Status status = normalize(sec, nsec, &normalized);
|
|
if (status != Status::ok) {
|
|
return status;
|
|
}
|
|
if (book->accepted == capture_limit) {
|
|
return Status::capacity;
|
|
}
|
|
Entry replacement;
|
|
replacement.present = true;
|
|
replacement.stamp = book->entries[channel].present ? book->entries[channel].stamp : normalized;
|
|
replacement.sequence = book->accepted + 1;
|
|
replacement.payload = payload;
|
|
book->entries[channel] = replacement;
|
|
++book->accepted;
|
|
return Status::ok;
|
|
}
|
|
|
|
Status book_snapshot(const Book* book, std::uint32_t channel, Entry* out)
|
|
{
|
|
if (book == nullptr || out == nullptr || channel >= channel_count) {
|
|
return Status::invalid;
|
|
}
|
|
const Entry& selected = book->entries[channel];
|
|
if (!selected.present) {
|
|
return Status::missing;
|
|
}
|
|
*out = selected;
|
|
return Status::ok;
|
|
}
|
|
|
|
Status book_clear(Book* book, std::uint32_t channel)
|
|
{
|
|
if (book == nullptr || channel >= channel_count) {
|
|
return Status::invalid;
|
|
}
|
|
book->entries[channel] = Entry{};
|
|
return Status::ok;
|
|
}
|
|
}
|