amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

99 lines
2.7 KiB
C++

#include "packet.hpp"
#include <sstream>
namespace packet {
bool number(const std::string& token, std::uint32_t maximum, std::uint32_t& value) {
if (token.empty()) {
return false;
}
std::uint32_t current = 0;
for (char character : token) {
if (character < '0' || character > '9') {
return false;
}
unsigned digit = static_cast<unsigned>(character - '0');
if (current > maximum / 10) {
return false;
}
if (current == maximum / 10 && digit > maximum % 10) {
return false;
}
current = current * 10 + digit;
}
value = current;
return true;
}
static 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& token, std::string& bytes) {
bytes.clear();
if (token == "-") {
return true;
}
if (token.empty() || token.size() > 128 || token.size() % 2 != 0) {
return false;
}
std::string result;
result.reserve(token.size() / 2);
for (std::size_t index = 0; index < token.size(); index += 2) {
int high = nibble(token[index]);
int low = nibble(token[index + 1]);
if (high < 0 || low < 0) {
return false;
}
result.push_back(static_cast<char>(high * 16 + low));
}
bytes.swap(result);
return true;
}
std::string encode(const std::string& bytes) {
if (bytes.empty()) {
return "-";
}
const char* alphabet = "0123456789abcdef";
std::string result;
result.reserve(bytes.size() * 2);
for (unsigned char byte : bytes) {
result.push_back(alphabet[byte >> 4]);
result.push_back(alphabet[byte & 15]);
}
return result;
}
std::uint32_t checksum(const Packet& packet) {
std::uint32_t result = 2166136261u;
auto feed = [&result](unsigned byte) {
result ^= byte;
result *= 16777619u;
};
for (unsigned shift = 0; shift != 32; shift += 8) {
feed((packet.id >> shift) & 255);
}
feed(packet.priority);
for (unsigned shift = 0; shift != 32; shift += 8) {
feed((packet.deadline >> shift) & 255);
}
for (unsigned char byte : packet.data) {
feed(byte);
}
return result;
}
std::vector<std::string> words(const std::string& line) {
std::istringstream input(line);
std::vector<std::string> tokens;
std::string token;
while (input >> token) {
tokens.push_back(token);
}
return tokens;
}
}