summaryrefslogtreecommitdiffstats
path: root/blob.h
diff options
context:
space:
mode:
Diffstat (limited to 'blob.h')
-rw-r--r--blob.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/blob.h b/blob.h
new file mode 100644
index 0000000..ad242a8
--- /dev/null
+++ b/blob.h
@@ -0,0 +1,34 @@
+#ifndef BLOB_H
+#define BLOB_H
+
+#include <string.h>
+
+typedef struct blob {
+ char *ptr;
+ unsigned int len;
+} blob_t;
+
+#define blob_dyn(ptr,len) (blob_t){(void*)(ptr), (len)}
+#define blob_buf(buf) (blob_t){(void*)(buf), sizeof(buf)}
+#define blob_str(str) (blob_t){(char*)(str), strlen(str)}
+
+extern const blob_t BLOB_NULL;;
+
+static inline int blob_is_null(blob_t b)
+{
+ return b.ptr == NULL;
+}
+
+char *blob_cstr_dup(blob_t b);
+blob_t blob_dup(blob_t b);
+int blob_cmp(blob_t a, blob_t b);
+blob_t blob_pushed(blob_t buffer, blob_t left);
+void blob_push(blob_t *b, blob_t d);
+void blob_push_int_str(blob_t *b, int val);
+void blob_push_hexdump(blob_t *to, blob_t binary);
+blob_t blob_pull(blob_t *b, int len);
+void blob_pull_skip(blob_t *b, int len);
+int blob_pull_matching(blob_t *b, blob_t e);
+
+
+#endif