1 #ifndef CCAN_CDUMP_INTERNAL
2 #define CCAN_CDUMP_INTERNAL
7 automatic marshalling/unmarshalling system for C structures
10 /* Always printed even if it's zero (for enums). */
11 #define CDUMP_FLAG_ALWAYS 1
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);
23 /* genstruct.pl generates arrays of these */
25 /* Name of the member. */
27 /* Number of levels of pointers. */
29 /* Size of the underlying type. */
31 /* Offset within the struct. */
33 /* Non-zero if it's a fixed-length array. */
35 /* Set to field name or literal number, from CDUMP_LEN. */
36 const char *dynamic_len;
37 /* CDUMP_FLAG_ALWAYS */
39 /* Function to dump this type. */
40 cdump_bundle_fn bundle;
41 /* Function to restore this type. */
42 cdump_unbundle_fn unbundle;
45 /* For writing your own dump types. */
46 bool cdump_addstr(struct cdump_string *p, const char *fmt, ...);
48 bool cdump_bundle_enum(const struct cdump_enum *einfo,
49 struct cdump_string *p,
52 bool cdump_unbundle_enum(const struct cdump_enum *einfo,
53 void *ptr, const char *str);
55 bool cdump_bundle_struct(const struct cdump_desc *pinfo,
56 struct cdump_string *p,
59 bool cdump_unbundle_struct(const void *ctx,
60 const struct cdump_desc *info,
61 void *data, const char *s);
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);
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);
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
85 #endif /* CCAN_CDUMP_INTERNAL */