• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# lws_struct
2
3## Overview
4
5lws_struct provides a lightweight method for serializing and deserializing C
6structs to and from JSON, and to and from sqlite3.
7
8![lws_struct overview](../doc-assets/lws_struct-overview.svg)
9
10 - you provide a metadata array describing struct members one-time, then call
11   generic apis to serialize and deserialize
12
13 - supports flat structs, single child struct pointers, and unbounded arrays /
14   linked-lists of child objects automatically using [lws_dll2 linked-lists](./README.lws_dll.md)
15
16 - supports boolean and C types char, int, long, long long in explicitly signed
17   and unsigned forms
18
19 - supports both char * type string members where the unbounded content is
20   separate and pointed to, and fixed length char array[] type members where
21   the content is part of the struct
22
23 - huge linear strings are supported by storing to a temp lwsac of chained chunks,
24   which is written into a single linear chunk in the main lwsac once the
25   total string length is known
26
27 - deserialization allocates into an [lwsac](../lib/misc/lwsac/README.md), so everything is inside as few
28   heap allocations as possible while still able to expand to handle arbitrary
29   array or strins sizes
30
31 - when deserialized structs are finished with, a single call to free the
32   lwsac frees the whole thing without having to walk it
33
34 - stateful serializaton and deserialization allows as-you-get packets incremental
35   parsing and production of chunks of as-you-can-send incremental serialization
36   output cleanly
37
38## Examples
39