skip to content
[readonly]
==> README.md <==
1# @ajax/mesh-buf
2
3A 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.
6
7```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```
13
14## Ported from
15
16[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.
19
20## Tests
21
22- `tests/buf.c`: appends, growth, `printf`, little-endian words, take, truncate.
23
24## Licence
25
26MIT. See the repository's LICENSE.