Skip to content

Commit 1d3720a

Browse files
committed
docs: document streaming encode code generation
Document the optional streaming encode entrypoints and the --stream-encode-functions codegen option. Update the architecture overview to mention the generated provider structs and streaming entrypoints.
1 parent 4fb0592 commit 1d3720a

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

ARCHITECTURE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ There are up to 4 files constructed:
175175
- The H file with all the struct definitions (the type file). If both decoding and encoding files are generated for the same CDDL, they can share the same type file.
176176
- An optional cmake file for building the generated code together with the zcbor C libraries.
177177

178+
When `zcbor code` is invoked with `--stream-encode-functions`, CodeRenderer also emits streaming encode entrypoints (`cbor_stream_encode_<type>`) and the associated provider structs used to supply repeated elements and chunked `tstr` values.
179+
178180
CodeRenderer conducts some pruning and deduplication of the list of types and functions received from CodeGenerator.
179181

180182

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ The tests require [Zephyr](https://github.com/zephyrproject-rtos/zephyr) (if you
196196

197197
The generated C code is C++ compatible.
198198

199+
Streaming encode entrypoints
200+
----------------------------
201+
202+
For encode-heavy, low-RAM paths, `zcbor code` can optionally generate streaming encode entrypoints:
203+
204+
- `cbor_stream_encode_<type>(zcbor_stream_write_fn stream_write, void *stream_user_data, const <type> *input, const struct cbor_stream_providers *prov, size_t *bytes_written_out)`
205+
206+
Enable them with `--stream-encode-functions`.
207+
208+
These entrypoints write CBOR via the supplied callback (no output buffer), and can stream:
209+
210+
- repeated fields via iterator callbacks in `struct cbor_stream_providers`
211+
- `bstr` values via chunk callbacks (indefinite-length byte strings)
212+
- `tstr` values via chunk callbacks (indefinite-length text strings)
213+
214+
When streaming entrypoints are enabled, generated encode code uses indefinite-length containers where needed.
215+
199216
Build system
200217
------------
201218

@@ -436,7 +453,8 @@ zcbor code --help
436453

437454
```
438455
usage: zcbor code [-h] -c CDDL [--no-prelude] [-v]
439-
[--default-max-qty DEFAULT_MAX_QTY] [--output-c OUTPUT_C]
456+
[--default-max-qty DEFAULT_MAX_QTY] [--repeated-as-pointers]
457+
[--stream-encode-functions] [--output-c OUTPUT_C]
440458
[--output-h OUTPUT_H] [--output-h-types OUTPUT_H_TYPES]
441459
[--copy-sources] [--output-cmake OUTPUT_CMAKE] -t
442460
ENTRY_TYPES [ENTRY_TYPES ...] [-d] [-e] [--time-header]
@@ -477,6 +495,13 @@ options:
477495
as sometimes the value is needed for internal
478496
computations. If so, the script will raise an
479497
exception.
498+
--repeated-as-pointers
499+
Represent repeated fields (max_qty > 1) as pointer +
500+
count instead of embedding fixed-size arrays in the
501+
generated types.
502+
--stream-encode-functions
503+
Also generate streaming encode entrypoints
504+
(cbor_stream_encode_<type>) for each entry type.
480505
--output-c OUTPUT_C, --oc OUTPUT_C
481506
Path to output C file. If both --decode and --encode
482507
are specified, _decode and _encode will be appended to

0 commit comments

Comments
 (0)