You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`Makefile` — builds `build/out/libcfgpack.a`, test binaries, and tools.
101
103
102
104
## Building
@@ -130,21 +132,22 @@ Output:
130
132
```
131
133
Running tests...
132
134
133
-
basic: 4/4 passed
134
-
core_edge: 11/11 passed
135
-
decompress: 8/8 passed
136
-
io_edge: 16/16 passed
137
-
json_edge: 8/8 passed
138
-
json_remap: 10/10 passed
139
-
measure: 15/15 passed
140
-
msgpack: 16/16 passed
135
+
basic: 4/4 passed
136
+
core_edge: 11/11 passed
137
+
decompress: 8/8 passed
138
+
io_edge: 16/16 passed
139
+
io_littlefs: 8/8 passed
140
+
json_edge: 8/8 passed
141
+
json_remap: 10/10 passed
142
+
measure: 15/15 passed
143
+
msgpack: 16/16 passed
141
144
msgpack_schema: 17/17 passed
142
-
null_args: 40/40 passed
143
-
parser_bounds: 23/23 passed
144
-
parser: 3/3 passed
145
-
runtime: 24/24 passed
145
+
null_args: 40/40 passed
146
+
parser_bounds: 23/23 passed
147
+
parser: 3/3 passed
148
+
runtime: 24/24 passed
146
149
147
-
TOTAL: 195/195 passed
150
+
TOTAL: 203/203 passed
148
151
```
149
152
150
153
### Fuzz Testing
@@ -178,7 +181,7 @@ See [Fuzz Testing](docs/source/fuzz-testing.md) for detailed documentation on th
178
181
179
182
## Examples
180
183
181
-
Five complete examples are provided in the `examples/` directory:
184
+
Six complete examples are provided in the `examples/` directory:
182
185
183
186
### allocate-once
184
187
@@ -196,6 +199,14 @@ Basic data logger demonstrating schema parsing, typed convenience functions, and
196
199
cd examples/datalogger && make run
197
200
```
198
201
202
+
### flash_config
203
+
204
+
Industrial sensor node demonstrating LittleFS flash storage with LZ4-compressed msgpack binary schemas and a v1 → v2 schema migration. Uses a RAM-backed LittleFS block device for desktop testing. Shows the composable I/O pattern: manual LFS read + `cfgpack_pagein_remap()` for cross-version migration, and `cfgpack_pageout_lfs()` / `cfgpack_pagein_lfs()` for same-version round-trips. Covers all five migration scenarios: keep, widen, move, remove, and add.
205
+
206
+
```bash
207
+
cd examples/flash_config && make run
208
+
```
209
+
199
210
### fleet_gateway
200
211
201
212
Fleet management gateway demonstrating LZ4-compressed msgpack binary schemas (pre-compiled from `.map` files via `cfgpack-schema-pack` and compressed with `cfgpack-compress lz4`) and a three-version migration chain (v1 -> v2 -> v3). Shows runtime LZ4 decompression of schema data before parsing, and uses `cfgpack_schema_measure_msgpack()` for right-sized heap allocation with no static buffer guessing. Covers all five migration scenarios: keep, widen, move, remove, and add.
Unlike the compression flags, this is NOT on by default in `CFLAGS`. Applications that need LittleFS must explicitly pass `-DCFGPACK_LITTLEFS` and link `src/io_littlefs.c` along with the vendored LittleFS sources (`third_party/littlefs/lfs.c`, `third_party/littlefs/lfs_util.c`). This flag is also passed to Doxygen as a `PREDEFINED` macro.
124
+
119
125
### Compile-Time Limits
120
126
121
127
Defined in `include/cfgpack/config.h` and overridable before including cfgpack headers:
Notably, `src/io_file.c` is **excluded** from the core library because it depends on `<stdio.h>`. It is compiled separately with hosted flags and linked into tests and tools as needed. This preserves the embedded-friendly, zero-stdio core.
147
153
154
+
Similarly, `src/io_littlefs.c` is **excluded** from the core library because it depends on LittleFS. It is compiled separately with `-DCFGPACK_LITTLEFS` and linked into applications, tests, and examples that use LittleFS storage.
155
+
148
156
The archiver creates the library with `ar rcs`.
149
157
150
158
---
@@ -195,14 +203,15 @@ Each test binary links against: the core static library, `io_file.o`, the encode
195
203
196
204
### Test Binaries
197
205
198
-
14 test files producing 13 test binaries (test.c is shared infrastructure, not a standalone binary):
206
+
15 test files producing 14 test binaries (test.c is shared infrastructure, not a standalone binary):
Heatshrink is an LZSS-based compression library designed for embedded systems with very low memory overhead. The decoder is compiled into the core library when `CFGPACK_HEATSHRINK` is defined. The encoder is used by tests (to generate compressed test data) and the `cfgpack-compress` tool.
484
493
485
-
Both libraries are included via `-Ithird_party/lz4` and `-Ithird_party/heatshrink` in `CPPFLAGS`.
494
+
### LittleFS
495
+
496
+
```
497
+
third_party/littlefs/
498
+
lfs.c
499
+
lfs.h
500
+
lfs_util.c
501
+
lfs_util.h
502
+
LICENSE.md
503
+
```
504
+
505
+
LittleFS is a little fail-safe filesystem designed for microcontrollers. The LittleFS sources are compiled directly into applications that use the cfgpack LittleFS wrappers (they are not part of the core `libcfgpack.a`).
506
+
507
+
All three libraries are included via `-Ithird_party/lz4`, `-Ithird_party/heatshrink`, and `-Ithird_party/littlefs` in `CPPFLAGS`.
These functions use LittleFS operations and are provided for embedded systems with flash storage. The caller owns the `lfs_t` instance and must mount/unmount it externally. To use these, compile with `-DCFGPACK_LITTLEFS` and link `src/io_littlefs.c` and the LittleFS sources with your project.
580
+
581
+
The scratch buffer serves double duty: the first `lfs->cfg->cache_size` bytes are used as the LittleFS file cache (via `lfs_file_opencfg`), and the remainder holds the serialized data. This avoids `lfs_malloc`, making the wrappers compatible with `LFS_NO_MALLOC` builds. See [LittleFS Storage Wrappers](littlefs.md) for the full scratch buffer layout and usage guide.
582
+
583
+
```c
584
+
#include "cfgpack/io_littlefs.h"
585
+
586
+
/* Encode to a LittleFS file using caller scratch buffer (no heap).
587
+
* scratch must be >= cfg->cache_size + encoded size. */
Copy file name to clipboardExpand all lines: docs/source/compression.md
+22-5Lines changed: 22 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ Where `<algorithm>` is either `lz4` or `heatshrink`.
75
75
[0..3] 4-byte little-endian original size
76
76
[4..N] LZ4-compressed data
77
77
```
78
-
This header is required because LZ4 decompression needs to know the output buffer size. The `examples/fleet_gateway/` example demonstrates reading this format at runtime.
78
+
This header is required because LZ4 decompression needs to know the output buffer size. The `examples/fleet_gateway/` example demonstrates reading this format at runtime. The `examples/flash_config/` example demonstrates the same pipeline with LittleFS flash storage.
79
79
80
80
-**Heatshrink**: The output file contains raw compressed data only (no header). Heatshrink is a streaming decoder and does not require the original size up front.
81
81
@@ -108,15 +108,32 @@ The output binary can be parsed on-device with `cfgpack_schema_measure_msgpack()
108
108
109
109
## Third-Party Libraries
110
110
111
-
LZ4 and heatshrink sources are vendored in `third_party/` for self-contained builds:
111
+
LZ4, heatshrink, and LittleFS sources are vendored in `third_party/` for self-contained builds:
112
+
113
+
### LZ4
112
114
113
115
```
114
-
third_party/
115
-
lz4/
116
+
third_party/lz4/
116
117
lz4.h, lz4.c # BSD-2-Clause license
117
-
heatshrink/
118
+
```
119
+
120
+
### Heatshrink
121
+
122
+
```
123
+
third_party/heatshrink/
118
124
heatshrink_config.h # window=8, lookahead=4
119
125
heatshrink_decoder.h/c # Used by library
120
126
heatshrink_encoder.h/c # Used by compression tool and tests
121
127
# ISC license
122
128
```
129
+
130
+
### LittleFS
131
+
132
+
```
133
+
third_party/littlefs/
134
+
lfs.h, lfs.c # Core filesystem implementation
135
+
lfs_util.h, lfs_util.c # Utility functions
136
+
LICENSE.md # BSD-3-Clause license
137
+
```
138
+
139
+
LittleFS is a little fail-safe filesystem designed for microcontrollers. Unlike LZ4 and heatshrink, it is not compiled into the core library — it is linked directly by applications that use the LittleFS wrappers (`-DCFGPACK_LITTLEFS`). See [LittleFS Storage Wrappers](littlefs.md) for details.
0 commit comments