]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/cdump/cdump.h
cdump: first cut of translation of Tridge's genstruct junkcode.
[ccan-lca-2011.git] / ccan / cdump / cdump.h
1 #ifndef CCAN_CDUMP_H
2 #define CCAN_CDUMP_H
3 #include <stdbool.h>
4
5 #ifndef CDUMP_PARSING
6 /**
7  * CDUMP_SAVED - prefix for a structure or enum to be parsed by cdump_parse.
8  *
9  * A structure or enum tagged with this will be parsed by cdump_parse;
10  * others are ignored.  Note that the parser is very primitive, so
11  * your definitions should be formatted simply.
12  *
13  * Example:
14  *      CDUMP_SAVED struct foo {
15  *              int x;
16  *      };
17  */
18 #define CDUMP_SAVED
19
20 /**
21  * CDUMP_LEN - annotation for a pointer parsed by cdump_parse.
22  * @member: the structure memeber which defines the length.
23  *
24  * This marks a pointer as having a known length, either a constant or
25  * another structure member.
26  *
27  * Example:
28  *      CDUMP_SAVED struct bar {
29  *              int len;
30  *              char *p CDUMP_LEN(len);
31  *      };
32  */
33 #define CDUMP_LEN(x)
34
35 /**
36  * CDUMP_ZEROTERM - annotation for a pointer parsed by cdump_parse.
37  *
38  * This marks a pointer as being an array terminated by a zero entry, such
39  * as a C string.
40  *
41  * Example:
42  *      CDUMP_SAVED struct baz {
43  *              char *p CDUMP_ZEROTERM;
44  *      };
45  */
46 #define CDUMP_ZEROTERM
47 #endif
48
49 struct cdump_desc;
50
51 /**
52  * cdump_bundle - linearize a given datastructure
53  * @ctx: the context to tallocate the returned string off.
54  * @info: a cdump_desc definition created by cdump_parse()
55  * @data: a pointer to the struct described by @info.
56  *
57  * This tallocates a string which is a description of the talloc
58  * pointer @data and everything it references.
59  */
60 char *cdump_bundle(const void *ctx,
61                    const struct cdump_desc *info, const void *data);
62
63 /**
64  * cdump_unbundle - extract a datastructure from a linearized description
65  * @ctx: the context to tallocate the returned datastructure off.
66  * @info: a cdump_desc definition created by cdump_parse()
67  * @data: a pointer to the structute to unbundle.
68  * @str: the string created by cdump_bundle().
69  *
70  * Returns false on failure.  Fields not mentioned in @str are zero-filled.
71  */
72 bool cdump_unbundle(const void *ctx,
73                     const struct cdump_desc *info,
74                     void *data, const char *str);
75
76 #endif /* CCAN_CDUMP_H */