# Device configuration decimal gateway, contract v1 C01. This software model has no device, threads, clocks, filesystem, or network dependency. Build with `make`; `./gateway < examples/demo.txt` runs the public observation tool. GCC and make are sufficient. The candidate files provide the C11 API in `include/decimal.h`; internal implementation and unused array tails may change. Maximum tested operation count is 50000; counters fit uint32_t. No real hardware claim is made. C02. `df_number(data,length,width,minimum,maximum,out)` accepts only ASCII bytes 0x30..0x39 and returns their base-ten value, including any leading zeros. width is 1..9 and 0 <= minimum <= maximum <= 999999999. Valid caller pointers are supplied; a zero-length data span need not be dereferenced. Error precedence is length zero -> EMPTY(1), length greater than width -> LENGTH(2), any nondigit -> CHAR(3), numerical value outside inclusive bounds -> RANGE(4). Every error leaves `*out` unchanged. ASCII '0'..'9' correspond to values 0..9. No sign, whitespace, locale digit, NUL, or prefix is part of a field. C03. `df_init` sets current configuration to seq=0,rate=25,window=8,channel=2; accepted=0,rejected=0,last=OK(0), and an empty history. Field bounds are seq width4 0..9999; rate width4 1..2000; window width3 1..128; channel width2 0..15. A configuration also requires rate*window <=64000. `df_validate` reports RANGE for field bounds, otherwise BUDGET(9) for this product, otherwise OK. It does not change its input. C04. `df_apply` accepts a nonempty byte span of at most128 bytes containing one or more `key=value` fields separated by single semicolons, with no surrounding whitespace, trailing separator, or newline. Keys are exact ASCII `seq`, `rate`, `window`, `channel`. Fields can be in any order. seq and at least one setting are required; omitted settings retain their current values. Scan fields left-to-right: missing/empty key, missing `=`, extra `=` or an empty field -> SYNTAX(5); unknown key -> KEY(6); duplicate key -> DUP(7); then use C02/C03 for the value. Thus an empty value is EMPTY, and an unknown key with empty value is KEY. The value span itself may contain any byte; nondigits are CHAR unless LENGTH takes priority. An empty whole frame is EMPTY; a whole frame longer than128 is LENGTH. When all fields are scanned, missing seq or missing setting -> SYNTAX, seq unequal to (current.seq+1)%10000 -> SEQUENCE(8), then validate the proposed complete configuration per C03. C05. A successful `df_apply` atomically publishes all fields, increments accepted once, appends the new complete configuration to history, and sets last=OK. Every failure increments rejected once and sets last to its error; current configuration, accepted, and history are unchanged. `df_reject` performs this same failure accounting for a supplied nonzero status. There is no speculative externally visible update. C06. History contains the most recent16 successful configurations, including repeated settings at new seq. `df_history(state,age,out)` returns age0=newest through oldest; absent age returns HISTORY(11) and leaves the supplied output unchanged. `df_history_size` is the count. Rejected frames do not consume a slot. State may use a different internal representation if this API holds. C07. `df_encode(config,out,capacity,written)` produces exactly `seq=dddd;rate=dddd;window=ddd;channel=dd`, using zero-padded decimal fields at the widths from C03. It first validates C03. Capacity includes a final NUL, which is written on success; `*written` excludes it. An invalid configuration gives its validation error; insufficient capacity gives CAPACITY(12). Either error leaves the entire output buffer and `*written` unchanged. Valid configurations of any seq can be encoded, without checking transaction sequencing. C08. `df_stream_init` clears pending length, discarding flag and byte/frame counters. `df_feed(stream,state,data,length)` consumes any byte chunks; LF(0x0A) is the sole frame terminator and is not passed to `df_apply`. Any other byte, including CR, is frame content. A complete frame of at most128 bytes is applied; an LF after an empty frame therefore rejects EMPTY. At the129th content byte enter discarding mode, keep the first128 bytes and pending length128, ignore content until LF, then reject OVERFLOW(10) exactly once and reset pending/discarding. Every LF increments frame count. The return value counts completed frames in this call. All content and LF bytes increment byte count. Partial chunks do not change configuration/status/accounting until a terminator. A later good frame after a rejected/overflow frame is independent. Every completed frame clears pending length and discarding flag. C09. `df_finish` leaves an empty/non-discarding stream alone and returns0. Otherwise it rejects OVERFLOW if discarding, SYNTAX if an unterminated partial frame, increments frame count, resets pending/discarding and returns1. It does not add any bytes. `df_pending` returns pending length and `df_discarding` returns0 or1. C10. Status numeric values are OK0 EMPTY1 LENGTH2 CHAR3 RANGE4 SYNTAX5 KEY6 DUP7 SEQUENCE8 BUDGET9 OVERFLOW10 HISTORY11 CAPACITY12. `df_status_name` returns respectively `ok`, `empty`, `length`, `char`, `range`, `syntax`, `key`, `duplicate`, `sequence`, `budget`, `overflow`, `history`, `capacity`; other integers return `unknown`. C11. `tools/observe.c` is a public raw observer. Input consists of LF-terminated commands with tokens separated by ASCII space, TAB or CR: R resets both states; D width minimum maximum seed hexspan observes number; A hexspan applies; F hexspan feeds; T finishes; Q queries state; H age queries history seeded with all fields777; E capacity observes encoding with80-byte output filled0xA5 and written seeded777; V seq rate window channel validates a configuration; N status observes its name. A hexspan is even-length hexadecimal, `-` means empty. Inputs are bounded to4096 decoded bytes per command and capacity0..80. Q/A/F/T output current seq,rate,window,channel,accepted,rejected,last,history-size,pending,discarding,stream-bytes,stream-frames; A/F/T prefix status/completed count. D/H output status followed by output value(s); E prints status,written then all80 output bytes as numbers. V prints status and unchanged input fields. N prints name. The observer performs no expected-value assertions. C12. The stdout observation protocol uses LF-terminated rows with exactly the documented token count and order. Integer tokens are ASCII decimal, permitting leading plus, leading zeros, negative zero and arbitrary leading-zero count; horizontal separators are space/TAB/CR. Signed negative values are allowed only where the observed C type permits them. Number spelling is not semantic; status-name tokens follow C10. No additional stdout rows. Stderr may contain arbitrary diagnostic bytes of arbitrary size, without affecting otherwise correct results. C13. `df_changed_mask(before,after)` supports downstream configuration planning: return the bitwise OR of1 for seq differing,2 for rate,4 for window,8 for channel. Both configurations are arbitrary uint32_t field values; the function only compares and never changes inputs. Observer command `M` takes eight unsigned decimal arguments (before seq/rate/window/channel then after) and prints this mask. C14. Observer `B seq rate window channel capacity` encodes the supplied arbitrary uint32_t configuration instead of current state; output and seeded buffers follow E in C11. Capacity is0..80. This observes validation-before-capacity and unchanged bytes/written on invalid configurations, as specified in C07.