@@ -12,10 +12,39 @@ typedef struct descriptor
12
12
A basic descriptor should have a structure with TLV like above.
13
13
A descriptor is a list node. As descriptors can be chained in a table.
14
14
15
- Deine sevaral MACROs as helpers to expand the struct, parse the ts sections,
15
+ Define sevaral MACROs as helpers to expand the struct, parse the ts sections,
16
16
dump the result and free the list.
17
+ For example, this expands definitions of a struct:
17
18
```
18
- __m(type, member, bits)
19
- __m1(type, member)
20
- __mplast(type, member)
19
+ #define __m(type, name, bits) type name : bits; /* define the struct member with bits width */
20
+ #define __m1(type, name) type name; /* define the struct member, which consume a type width */
21
21
```
22
+ And this define how to parse the struct member:
23
+ ```
24
+ #define __m(type, name, bits) \
25
+ dr->name = TS_READ_BITS_##type(buf + bytes_off, bits, bits_off); \
26
+ bits_off += bits; \
27
+ if (bits_off == sizeof(type) * 8) { \
28
+ bits_off = 0; \
29
+ bytes_off += sizeof(type); \
30
+ }
31
+
32
+ #define __m1(type, name) \
33
+ if (bytes_off < len) { \
34
+ dr->name = TS_READ_##type(buf + bytes_off); \
35
+ bytes_off += sizeof(type); }
36
+ ```
37
+ We should implement macros for free and dump too.
38
+ Every macro should be well defined for the four helper types.
39
+ see ``` include/descriptor.h ```
40
+
41
+ Also, not every sub-structrue of a descriptor is defined as above. A simple TLV is not enough,
42
+ macro define could be too compilated.
43
+ If we do have many descriptors share the same pattern, we can do things like below
44
+ ```
45
+ define __mplast_custom_sub(type, name, parser_cb, dump_cb, free_cb)
46
+ ```
47
+ we can add all parse, dump and free functions as callback here.
48
+
49
+ If we don't have many structures share the same pattern, just write functions for it.
50
+ And add initialization for descriptors in ``` init_descriptor_parsers ``` function.
0 commit comments