Commit b8be3dc
committed
feat(body): Compile-time body_template — nesting, arrays, dual wire format
Add note::experimental::body_template: a compile-time body builder that bakes a request body's structure into a static byte pool at compile time and substitutes only the runtime values at the call site — no SAX lexer and no per-field virtual dispatch on the emit path.
Four user-facing surfaces, all lowering to one segment-walker (compiled_body):
1. body_template<L>() + .with(...) template literal + positional values
2. jsonb<L>(values...) one-call sugar over (1)
3. jsonb_body{ "k"_k = v, ... } init-list with UDL keys
4. jsonb_builder().add("k"_k, v)... fluent builder
Surface 0 — note::body([&]{ b.add(...); }) — stays as the runtime-flexible fallback when squeezing flash isn't worth it.
Slots: int32 ($N), double ($Nf), bool ($Nb), string ($Ns), nested object ($No) and array ($Na). jsonb_body and jsonb_array compose as field values and array elements to any depth; nested values carry their own emit_to() so the outer schema bakes only the key.
Wire-format-agnostic surface: the NOTE_JSONB build flag selects whether the baked pool and per-slot runtime bytes are JSONB opcodes (length-tagged binary) or JSON text. The split lives entirely in detail::wire (paired emit + size helpers so the static array is sized exactly); everything above it is shared. operator BodyValue() works in both modes via the builder's begin_raw_value splice.
Tests run the whole suite twice (default JSON text + -DNOTE_JSONB=1), with independent literal-string checks pinning the exact JSON text. Five compile-fail tests lock the slot type contracts, including object/array slots requiring a jsonb_body/jsonb_array argument.1 parent e874ed6 commit b8be3dc
8 files changed
Lines changed: 2021 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
0 commit comments