]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/cdump/cdump.h
cdump: first cut of translation of Tridge's genstruct junkcode.
[ccan-lca-2011.git] / ccan / cdump / cdump.h
diff --git a/ccan/cdump/cdump.h b/ccan/cdump/cdump.h
new file mode 100644 (file)
index 0000000..70def69
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef CCAN_CDUMP_H
+#define CCAN_CDUMP_H
+#include <stdbool.h>
+
+#ifndef CDUMP_PARSING
+/**
+ * CDUMP_SAVED - prefix for a structure or enum to be parsed by cdump_parse.
+ *
+ * A structure or enum tagged with this will be parsed by cdump_parse;
+ * others are ignored.  Note that the parser is very primitive, so
+ * your definitions should be formatted simply.
+ *
+ * Example:
+ *     CDUMP_SAVED struct foo {
+ *             int x;
+ *     };
+ */
+#define CDUMP_SAVED
+
+/**
+ * CDUMP_LEN - annotation for a pointer parsed by cdump_parse.
+ * @member: the structure memeber which defines the length.
+ *
+ * This marks a pointer as having a known length, either a constant or
+ * another structure member.
+ *
+ * Example:
+ *     CDUMP_SAVED struct bar {
+ *             int len;
+ *             char *p CDUMP_LEN(len);
+ *     };
+ */
+#define CDUMP_LEN(x)
+
+/**
+ * CDUMP_ZEROTERM - annotation for a pointer parsed by cdump_parse.
+ *
+ * This marks a pointer as being an array terminated by a zero entry, such
+ * as a C string.
+ *
+ * Example:
+ *     CDUMP_SAVED struct baz {
+ *             char *p CDUMP_ZEROTERM;
+ *     };
+ */
+#define CDUMP_ZEROTERM
+#endif
+
+struct cdump_desc;
+
+/**
+ * cdump_bundle - linearize a given datastructure
+ * @ctx: the context to tallocate the returned string off.
+ * @info: a cdump_desc definition created by cdump_parse()
+ * @data: a pointer to the struct described by @info.
+ *
+ * This tallocates a string which is a description of the talloc
+ * pointer @data and everything it references.
+ */
+char *cdump_bundle(const void *ctx,
+                  const struct cdump_desc *info, const void *data);
+
+/**
+ * cdump_unbundle - extract a datastructure from a linearized description
+ * @ctx: the context to tallocate the returned datastructure off.
+ * @info: a cdump_desc definition created by cdump_parse()
+ * @data: a pointer to the structute to unbundle.
+ * @str: the string created by cdump_bundle().
+ *
+ * Returns false on failure.  Fields not mentioned in @str are zero-filled.
+ */
+bool cdump_unbundle(const void *ctx,
+                   const struct cdump_desc *info,
+                   void *data, const char *str);
+
+#endif /* CCAN_CDUMP_H */