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

127 lines
3.0 KiB
C

#include "stream.h"
#include "wire.h"
#include "store.h"
#include <string.h>
static void drop_front(stream_decoder *decoder, size_t count)
{
if (count >= decoder->length) {
decoder->length = 0;
return;
}
memmove(decoder->bytes, decoder->bytes + count, decoder->length - count);
decoder->length -= count;
}
static void seek_magic(stream_decoder *decoder)
{
size_t index = 0;
while (index < decoder->length && decoder->bytes[index] != WIRE_MAGIC) {
++index;
}
if (index) {
decoder->discarded += index;
drop_front(decoder, index);
}
}
static void process_ready(stream_decoder *decoder)
{
for (;;) {
size_t total;
int slot, result;
seek_magic(decoder);
if (decoder->length < 3) {
return;
}
if (decoder->bytes[1] >= STORE_SLOTS ||
decoder->bytes[2] > STORE_CAPACITY) {
++decoder->rejected;
++decoder->discarded;
drop_front(decoder, 1);
continue;
}
total = (size_t)decoder->bytes[2] + 5;
if (decoder->length < total) {
return;
}
result = wire_unpack(decoder->bytes, total, &slot);
if (result == WIRE_OK) {
++decoder->accepted;
decoder->last_slot = slot;
drop_front(decoder, total);
} else {
++decoder->rejected;
++decoder->discarded;
drop_front(decoder, 1);
}
}
}
void stream_init(stream_decoder *decoder)
{
if (decoder == NULL) {
return;
}
decoder->length = 0;
decoder->accepted = 0;
decoder->rejected = 0;
decoder->discarded = 0;
decoder->last_slot = -1;
}
int stream_feed(stream_decoder *decoder, const unsigned char *input, size_t length)
{
size_t index;
if (decoder == NULL || (length && input == NULL)) {
return STREAM_OVERFLOW;
}
for (index = 0; index < length; ++index) {
if (decoder->length == STREAM_BUFFER) {
process_ready(decoder);
if (decoder->length == STREAM_BUFFER) {
return STREAM_OVERFLOW;
}
}
decoder->bytes[decoder->length++] = input[index];
process_ready(decoder);
}
return STREAM_OK;
}
int stream_flush(stream_decoder *decoder)
{
if (decoder == NULL) {
return STREAM_OVERFLOW;
}
process_ready(decoder);
decoder->discarded += decoder->length;
decoder->length = 0;
return STREAM_OK;
}
size_t stream_pending(const stream_decoder *decoder)
{
return decoder ? decoder->length : 0;
}
unsigned long stream_accepted(const stream_decoder *decoder)
{
return decoder ? decoder->accepted : 0;
}
unsigned long stream_rejected(const stream_decoder *decoder)
{
return decoder ? decoder->rejected : 0;
}
unsigned long stream_discarded(const stream_decoder *decoder)
{
return decoder ? decoder->discarded : 0;
}
int stream_last_slot(const stream_decoder *decoder)
{
return decoder ? decoder->last_slot : -1;
}