DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
strbuf.h File Reference

Bounded no-heap string builder that fails closed on overflow (one shared copy). More...

#include <stddef.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  DetSb
 Bump-append target; ok latches false once an append would overflow cap. More...
 

Functions

void det_sb_put (DetSb *b, const char *s)
 Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.
 
void det_sb_xml (DetSb *b, const char *s)
 Append s XML-escaped (& < > "); a NULL s appends nothing.
 
size_t det_sb_finish (DetSb *b)
 NUL-terminate and return the built length, or 0 if the build overflowed.
 

Detailed Description

Bounded no-heap string builder that fails closed on overflow (one shared copy).

The same little Buf appender was open-coded inside the anonymous namespace of ~5 codecs (utmc, sep2, openadr, atc, exc_decoder). It bump-appends into a caller-owned char[] and latches ok to false the first time something would not fit, so every later append is a no-op and callers test one flag at the end. These header-only inline helpers are the single home for it, mirroring hex.h / numparse.h - no <stdlib.h>, no heap, and zero link cost when unused. Per-codec numeric/JSON formatters stay local; only the verbatim pieces (struct + raw append + XML escape + terminate) live here.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file strbuf.h.

Function Documentation

◆ det_sb_put()

void det_sb_put ( DetSb b,
const char *  s 
)
inline

Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.

Definition at line 36 of file strbuf.h.

References DetSb::cap, DetSb::len, DetSb::ok, and DetSb::p.

Referenced by det_sb_xml().

◆ det_sb_xml()

void det_sb_xml ( DetSb b,
const char *  s 
)
inline

Append s XML-escaped (& < > "); a NULL s appends nothing.

Definition at line 51 of file strbuf.h.

References DetSb::cap, det_sb_put(), DetSb::len, DetSb::ok, and DetSb::p.

◆ det_sb_finish()

size_t det_sb_finish ( DetSb b)
inline

NUL-terminate and return the built length, or 0 if the build overflowed.

Definition at line 90 of file strbuf.h.

References DetSb::len, DetSb::ok, and DetSb::p.