Text out, without printf and without a heap.
Any time you would reach for snprintf and prefer not to link a formatter, or cannot afford one.
The writers hold no state. Each one takes the position it should write at and returns the position after what it wrote. So the cursor is the caller's at, and nothing carries over between calls. A writer with no room returns cap, which every later writer also returns. An overflow propagates to finish without a flag and finish reports it as a length of zero.
There is no format string anywhere. Nothing parses d at runtime, and so nothing can disagree with the argument you passed.
Each table takes its own argument struct.
| job | table and struct | entries |
|---|---|---|
| raw text | verba_textus, VerbaTextusCfg | put, put_n, put_clip |
| escaping | verba_textus, VerbaTextusCfg | xml, json |
| one character | verba_littera, VerbaLitteraCfg | ch |
| numbers | verba_numerus, VerbaNumerusCfg | uint, u32, u32w, u64, u64_clip, hex, i64 |
| floating point | verba_fractio, VerbaFractioCfg | g, fixed, sign_bit, is_inf, is_nan |
| finishing | verba_finis, VerbaFinisCfg | finish, ok |
put_n takes the length with the text, in .text_len. A literal costs no scan: pass sizeof "literal" - 1u. put measures what it gets.
verba_scribo/verba_linea.h retains the buffer, the cursor and an optional flush together in a VerbaLinea, and its mmgr_line_* entries take that line and the value as plain arguments. The header includes mmgr.h alone and defines no table, and therefore a C++ translation unit calls them as they are.
Every write leaves the buffer terminated, at the cost of one store on every call. A written line whose buffer holds no terminator shows corruption from something other than the line. A line with no flush behaves as snprintf does. A write that does not fit retains what fits, terminated in the last byte, and leaves the line full, and finish reports zero.
mmgr_line_put, mmgr_line_put_n and mmgr_line_put_max answer the bytes of the text the line took. A caller that sees fewer than the text holds goes on from text + taken. It uses the same buffer, with at set to zero once something reads those bytes. A line with a flush passes what it holds to the flush as it fills and goes on. So a text of any length passes through a buffer of any size. A flush answers 1 where it took the bytes and 0 where it refused, which leaves the line full.
mmgr_line_put reads its text a room at a time and never past the terminator, and so it needs no bound on the text's length.
| job | entries |
|---|---|
| raw text | mmgr_line_put, mmgr_line_put_n, mmgr_line_put_max, mmgr_line_ch |
| columns | mmgr_line_put_columns, mmgr_line_decimal_columns |
| numbers | mmgr_line_decimal, mmgr_line_decimal_signed, mmgr_line_hex |
| making | mmgr_line_over |
| finishing | mmgr_line_flush, mmgr_line_finish, mmgr_line_ok |
Overflow propagates, and so check once at the end. A writer with no room returns cap and every later writer returns cap too, and so the writes after an overflow are safe no-ops and finish reports zero. See How failure is reported.
xml and json escape, they do not quote. You supply the quotes around them.
put_clip truncates deliberately. It is for a field with a max width, and it is not the same as running out of room.
A float goes out by exact bit work, not by printf. It goes through Fractio: IEEE-754 fields.
A declarative layout. The format is data and not a string.
A record with a fixed shape emitted many times: a log line, a telemetry frame, a fixed-width table. Describe the layout once as an array and fill values in.
Two arrays. The spec says what the record looks like and holds no data. The values come on their own, and build takes them in order.
A literal is a MMGR_FK_LIT field that carries its own text and length, and so it costs no scan. Every other spec entry is a bare type that takes no argument. There is a one-word macro for some of them, MMGR_STR, MMGR_U32, MMGR_U64, MMGR_I64, MMGR_CH, MMGR_JSON, MMGR_XML, MMGR_END (src/numeros_scribo/numeros_scribo.h:60-85), and the rest use the brace form above. MMGR_FK_HEX, MMGR_FK_DEC, MMGR_FK_OCT, MMGR_FK_G and MMGR_FK_FIX have no such macro.
Four entries: build writes a record from a spec, emit writes values with no spec at all, and append and emit_append add to a record already in the buffer.
A program parses a format string at runtime, and nothing checks it against the arguments. Here the spec is a const array in flash, the type is an enum, and every value carries its own type tag. build compares the two and refuses the record if they disagree.
MMGR_END terminates the spec. Without it, the walk runs off the end of the array.
A type mismatch returns 0 and empties the buffer. So do too few values, or too many. The record is complete or absent; there is no partial record.
emit takes no spec. Each value carries its own type and width, and so it is the entry to use when the layout changes.
A thin, portable surface over a DMA controller: open a channel, submit a transfer, poll or take a callback, close it.
There is no handle. The channel number identifies the transfer, and so nothing needs storage between open and close. open and tx_submit return false when the channel is busy or out of range.
A completion callback is optional: point PraetCfg::on_complete at a PraetCallbackCfg, and the module calls it with a mmgr_praet_event that describes what finished.
The functions that actually touch a controller are EMBED_WEAK. A board support file overrides one with a definition of a symbol of the same name. There is no registration, no function pointer table, and no init order to get right.
Without an override they are present and refuse every request. So memoriam_praetereo compiles, and its tests link on a host with no DMA controller at all.
A submitted buffer must stay valid until the transfer completes [BORROWS]. The module does not copy it and cannot tell when the controller finishes: poll and the completion callback report. Everywhere else in MMgr a lifetime ends at a mark you control; here it ends when the hardware says so.
This module does not handle cache coherency. On a part with a data cache and a DMA engine that does not snoop it, the clean and invalidate are the board file's job.
The module reads the schedule's knobs only when the gate is on, and an unset one stops the build. PRAET_CHANNELS and the rest arrive through MMGR_PRAET_KNOBS. See Every compile-time knob.
praet_hw_progress is a fifth hook, with a weak default in praet_ordo.c that reports no movement. A port that leaves it in place still gets the watchdog. A running channel that nothing reports on gets the stalled mark once its keepalive window passes.