1# @ajax/mesh-buf
23A growable byte buffer for building strings and messages: append bytes, text, `printf` output and
4little-endian words; the bytes are always NUL-terminated, so a buffer holding text is a C string.
5Allocation failure aborts (`mesh_xmalloc` and friends too): meshd never goes on with half a message.
67```c
8#include "mesh/buf.h"
9mesh_buf b = MESH_BUF_INIT;
10mesh_buf_printf(&b, "ok %u us", 412u);
11char *s = mesh_buf_take(&b); /* free(s) */
12```
1314## Ported from
1516[alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) (Richard Safier, MIT): what Rust's `String`
17and `Vec<u8>` (with `format!` and `extend`) do throughout `crates/mesh-host`. There is no single Rust
18item; every daemon package builds its replies with it.
1920## Tests
2122- `tests/buf.c`: appends, growth, `printf`, little-endian words, take, truncate.
2324## Licence
2526MIT. See the repository's LICENSE.