Skip to content

Commit b8be3dc

Browse files
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

cmake/note-cpp-sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ set(NOTE_CPP_THIRD_PARTY_HEADERS
9696
# Tests that compile under both regular and NOTE_MINIMAL builds.
9797
set(NOTE_CPP_TEST_SOURCES_COMMON
9898
test_buffer_backend.cpp
99+
test_body_template.cpp
99100
test_cobs.cpp
100101
test_jsonb.cpp
101102
test_flag_set.cpp

0 commit comments

Comments
 (0)