summaryrefslogtreecommitdiffstats
path: root/blob.h
blob: ad242a8d37645270d651e2872b00c101b9b1a7c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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