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