]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/cdump/cdump.h
Add slides images.
[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
48 /**
49  * CDUMP_IGNORE - annotation for telling cdump_parse to ignore a member.
50  *
51  * This means it won't be bundled (and thus doesn't need to be understood) so
52  * on unbundling it will be all zero.
53  *
54  * Example:
55  *      CDUMP_SAVED struct baz {
56  *              char *p CDUMP_IGNORE;
57  *      };
58  */
59 #define CDUMP_IGNORE
60 #endif /* CDUMP_PARSING */
61
62 struct cdump_desc;
63
64 /**
65  * cdump_bundle - linearize a given datastructure
66  * @ctx: the context to tallocate the returned string off.
67  * @info: a cdump_desc definition created by cdump_parse()
68  * @data: a pointer to the struct described by @info.
69  *
70  * This tallocates a string which is a description of the talloc
71  * pointer @data and everything it references.
72  */
73 char *cdump_bundle(const void *ctx,
74                    const struct cdump_desc *info, const void *data);
75
76 /**
77  * cdump_unbundle - extract a datastructure from a linearized description
78  * @ctx: the context to tallocate the returned datastructure off.
79  * @info: a cdump_desc definition created by cdump_parse()
80  * @data: a pointer to the structute to unbundle.
81  * @str: the string created by cdump_bundle().
82  *
83  * Returns false on failure.  Fields not mentioned in @str are zero-filled.
84  */
85 bool cdump_unbundle(const void *ctx,
86                     const struct cdump_desc *info,
87                     void *data, const char *str);
88
89 #endif /* CCAN_CDUMP_H */