]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/cdump/cdump_internal.h
cdump: features which weren't in genparser
[ccan-lca-2011.git] / ccan / cdump / cdump_internal.h
1 #ifndef CCAN_CDUMP_INTERNAL
2 #define CCAN_CDUMP_INTERNAL
3 #include <stdbool.h>
4 #include <stdlib.h>
5
6 /*
7   automatic marshalling/unmarshalling system for C structures
8 */
9
10 /* Always printed even if it's zero (for enums). */
11 #define CDUMP_FLAG_ALWAYS 1
12
13 struct cdump_enum {
14         const char *name;
15         unsigned value;
16 };
17
18 struct cdump_string;
19
20 typedef bool (*cdump_bundle_fn)(struct cdump_string *, const void *ptr, unsigned indent);
21 typedef bool (*cdump_unbundle_fn)(const void *ctx, void *ptr, const char *str);
22
23 /* genstruct.pl generates arrays of these */
24 struct cdump_desc {
25         /* Name of the member. */
26         const char *name;
27         /* Number of levels of pointers. */
28         size_t ptr_count;
29         /* Size of the underlying type. */
30         size_t size;
31         /* Offset within the struct. */
32         size_t offset;
33         /* Non-zero if it's a fixed-length array. */
34         size_t array_len;
35         /* Set to field name or literal number, from CDUMP_LEN. */
36         const char *dynamic_len;
37         /* CDUMP_FLAG_ALWAYS */
38         unsigned flags;
39         /* Function to dump this type. */
40         cdump_bundle_fn bundle;
41         /* Function to restore this type. */
42         cdump_unbundle_fn unbundle;
43 };
44
45 /* For writing your own dump types. */
46 bool cdump_addstr(struct cdump_string *p, const char *fmt, ...);
47
48 bool cdump_bundle_enum(const struct cdump_enum *einfo,
49                        struct cdump_string *p,
50                        const void *ptr,
51                        unsigned indent);
52 bool cdump_unbundle_enum(const struct cdump_enum *einfo,
53                          void *ptr, const char *str);
54
55 bool cdump_bundle_struct(const struct cdump_desc *pinfo,
56                          struct cdump_string *p,
57                          const void *ptr,
58                          unsigned indent);
59 bool cdump_unbundle_struct(const void *ctx,
60                            const struct cdump_desc *info,
61                            void *data, const char *s);
62
63 /* for convenience supply some standard dumpers and parsers here */
64 bool cdump_bundle_char(struct cdump_string *p, const void *ptr, unsigned ind);
65 bool cdump_bundle_int(struct cdump_string *p, const void *ptr, unsigned ind);
66 bool cdump_bundle_unsigned(struct cdump_string *p, const void *ptr, unsigned);
67 bool cdump_bundle_time_t(struct cdump_string *p, const void *ptr, unsigned ind);
68 bool cdump_bundle_double(struct cdump_string *p, const void *ptr, unsigned ind);
69 bool cdump_bundle_float(struct cdump_string *p, const void *ptr, unsigned ind);
70 bool cdump_bundle_size_t(struct cdump_string *p, const void *ptr, unsigned ind);
71
72 bool cdump_unbundle_char(const void *ctx, void *ptr, const char *str);
73 bool cdump_unbundle_int(const void *ctx, void *ptr, const char *str);
74 bool cdump_unbundle_unsigned(const void *ctx, void *ptr, const char *str);
75 bool cdump_unbundle_time_t(const void *ctx, void *ptr, const char *str);
76 bool cdump_unbundle_double(const void *ctx, void *ptr, const char *str);
77 bool cdump_unbundle_float(const void *ctx, void *ptr, const char *str);
78 bool cdump_unbundle_size_t(const void *ctx, void *ptr, const char *str);
79
80 #define cdump_bundle_unsigned_char cdump_bundle_char
81 #define cdump_unbundle_unsigned_char cdump_unbundle_char
82 #define cdump_bundle_unsigned_int cdump_bundle_int
83 #define cdump_unbundle_unsigned_int cdump_unbundle_int
84
85 #endif /* CCAN_CDUMP_INTERNAL */