Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao environments: hidden assertions that ran inside the candidate's process now run in a trusted parent that reads observations from a low-UID worker; gold bytes are unchanged. 9 were excluded for scope (ROS2, oversize, security core), 3 are blocked because the source requires an exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6. Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the first 100 landed in 2f32624d. Claude reviewed 74/74 USABLE against current digests, canonical families, no ID or source overlap with main, plain public docs. Only the new task directories are taken; the stale pre-batch-20 copies of concur-release-capsule and resource-temp-link on the batch 21 branch and both branches' progress notes stay as main has them. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
220 lines
6.5 KiB
C++
220 lines
6.5 KiB
C++
#include "eeprom.hpp"
|
|
#include <charconv>
|
|
#include <iomanip>
|
|
#include <istream>
|
|
#include <locale>
|
|
#include <ostream>
|
|
#include <sstream>
|
|
#include <system_error>
|
|
namespace eeprom {
|
|
namespace {
|
|
std::string code_name(Code code) {
|
|
switch (code) {
|
|
case Code::OK: return "OK";
|
|
case Code::RANGE: return "RANGE";
|
|
case Code::EXISTS: return "EXISTS";
|
|
case Code::ABSENT: return "ABSENT";
|
|
case Code::BUSY: return "BUSY";
|
|
case Code::TIMEOUT: return "TIMEOUT";
|
|
case Code::SYNTAX: return "SYNTAX";
|
|
case Code::LIMIT: return "LIMIT";
|
|
}
|
|
return "INVALID(" + std::to_string(static_cast<int>(code)) + ")";
|
|
}
|
|
std::string bytes_text(const std::vector<Number>& values) {
|
|
if (values.empty()) {
|
|
return "-";
|
|
}
|
|
const char* digits = "0123456789abcdef";
|
|
std::string text;
|
|
bool all_bytes = true;
|
|
for (Number value : values) {
|
|
if (value < 0 || value > 255) {
|
|
all_bytes = false;
|
|
}
|
|
}
|
|
if (!all_bytes) {
|
|
text = "[";
|
|
for (std::size_t i = 0; i < values.size(); ++i) {
|
|
if (i != 0) {
|
|
text += ',';
|
|
}
|
|
text += std::to_string(values[i]);
|
|
}
|
|
text += ']';
|
|
return text;
|
|
}
|
|
for (Number value : values) {
|
|
text += digits[value / 16];
|
|
text += digits[value % 16];
|
|
}
|
|
return text;
|
|
}
|
|
void emit(std::ostream& output, const std::string& line) {
|
|
output.write(line.data(), static_cast<std::streamsize>(line.size()));
|
|
output.put('\n');
|
|
}
|
|
bool number(const std::string& text, Number& value) {
|
|
if (text.empty()) {
|
|
return false;
|
|
}
|
|
const char* begin = text.data();
|
|
const char* end = begin + text.size();
|
|
auto parsed = std::from_chars(begin, end, value, 10);
|
|
return parsed.ec == std::errc() && parsed.ptr == end;
|
|
}
|
|
int nibble(char character) {
|
|
if (character >= '0' && character <= '9') {
|
|
return character - '0';
|
|
}
|
|
if (character >= 'a' && character <= 'f') {
|
|
return character - 'a' + 10;
|
|
}
|
|
if (character >= 'A' && character <= 'F') {
|
|
return character - 'A' + 10;
|
|
}
|
|
return -1;
|
|
}
|
|
bool decode(const std::string& text, std::vector<Number>& values) {
|
|
values.clear();
|
|
if (text == "-") {
|
|
return true;
|
|
}
|
|
if (text.empty() || text.size() % 2 != 0 || text.size() > 512) {
|
|
return false;
|
|
}
|
|
for (std::size_t i = 0; i < text.size(); i += 2) {
|
|
int high = nibble(text[i]);
|
|
int low = nibble(text[i + 1]);
|
|
if (high < 0 || low < 0) {
|
|
return false;
|
|
}
|
|
values.push_back(high * 16 + low);
|
|
}
|
|
return true;
|
|
}
|
|
std::vector<std::string> words(const std::string& line) {
|
|
std::vector<std::string> result;
|
|
std::size_t position = 0;
|
|
while (position < line.size()) {
|
|
if (line[position] == ' ' || line[position] == '\t') {
|
|
++position;
|
|
continue;
|
|
}
|
|
std::size_t start = position;
|
|
while (position < line.size() && line[position] != ' ' && line[position] != '\t') {
|
|
++position;
|
|
}
|
|
result.push_back(line.substr(start, position - start));
|
|
}
|
|
return result;
|
|
}
|
|
Reply syntax() {
|
|
return {Code::SYNTAX, 0, {}};
|
|
}
|
|
void dispatch(Bus& bus, const std::vector<std::string>& fields, std::ostream& output) {
|
|
if (fields.empty()) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
const std::string& command = fields[0];
|
|
std::size_t arity = 0;
|
|
if (command == "M") arity = 4;
|
|
else if (command == "U" || command == "P" || command == "I") arity = 2;
|
|
else if (command == "S" || command == "W" || command == "R") arity = 3;
|
|
else if (command == "T") arity = 5;
|
|
if (arity == 0 || fields.size() != arity) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
Number id = 0;
|
|
if (!number(fields[1], id)) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
Number first = 0;
|
|
Number second = 0;
|
|
std::vector<Number> values;
|
|
if (command == "M") {
|
|
if (!number(fields[2], first) || !number(fields[3], second)) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
print_reply(output, bus.mount(id, first, second));
|
|
return;
|
|
}
|
|
if (command == "U") {
|
|
print_reply(output, bus.unmount(id));
|
|
return;
|
|
}
|
|
if (command == "P") {
|
|
print_reply(output, bus.poll(id));
|
|
return;
|
|
}
|
|
if (command == "I") {
|
|
print_snapshot(output, bus.inspect(id));
|
|
return;
|
|
}
|
|
if (command == "S" || command == "R") {
|
|
if (!number(fields[2], first)) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
Reply reply = command == "S" ? bus.seek(id, first) : bus.read(id, first);
|
|
print_reply(output, reply);
|
|
return;
|
|
}
|
|
if (command == "W") {
|
|
if (!decode(fields[2], values)) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
print_reply(output, bus.page(id, values));
|
|
return;
|
|
}
|
|
if (!number(fields[2], first) || !number(fields[3], second) || !decode(fields[4], values)) {
|
|
print_reply(output, syntax());
|
|
return;
|
|
}
|
|
print_reply(output, bus.transfer(id, first, values, second));
|
|
}
|
|
}
|
|
void print_reply(std::ostream& out, const Reply& reply) {
|
|
std::string line = code_name(reply.code);
|
|
line += ' ';
|
|
line += std::to_string(reply.completed);
|
|
line += ' ';
|
|
line += bytes_text(reply.data);
|
|
emit(out, line);
|
|
}
|
|
void print_snapshot(std::ostream& out, const Snapshot& snapshot) {
|
|
std::string line = code_name(snapshot.code);
|
|
line += ' ' + std::to_string(snapshot.cursor);
|
|
line += ' ' + std::to_string(snapshot.busy);
|
|
line += ' ' + std::to_string(snapshot.accepted);
|
|
line += ' ' + std::to_string(snapshot.committed);
|
|
line += ' ' + std::to_string(snapshot.polls);
|
|
line += ' ' + std::to_string(snapshot.pending_start);
|
|
line += ' ' + bytes_text(snapshot.pending);
|
|
line += ' ' + bytes_text(snapshot.bytes);
|
|
emit(out, line);
|
|
}
|
|
int run_cli(Bus& bus, std::istream& input, std::ostream& output) {
|
|
std::string line;
|
|
std::size_t physical = 0;
|
|
while (std::getline(input, line)) {
|
|
++physical;
|
|
if (physical > 4096) {
|
|
print_reply(output, {Code::LIMIT, 0, {}});
|
|
continue;
|
|
}
|
|
if (line.size() > 2048 || line.find('\0') != std::string::npos || line.find('\r') != std::string::npos) {
|
|
print_reply(output, syntax());
|
|
continue;
|
|
}
|
|
dispatch(bus, words(line), output);
|
|
}
|
|
return 0;
|
|
}
|
|
}
|