4 * Binary blob handling.
6 * Copyright (c) 2002 Dug Song <dugsong@monkey.org>
8 * $Id: blob.h,v 1.2 2002/04/05 03:06:44 dugsong Exp $
15 u_char
*base
; /* start of data */
16 int off
; /* offset into data */
17 int end
; /* end of data */
18 int size
; /* size of allocation */
22 blob_t
*blob_new(void);
24 int blob_read(blob_t
*b
, void *buf
, int len
);
25 int blob_write(blob_t
*b
, const void *buf
, int len
);
27 int blob_seek(blob_t
*b
, int off
, int whence
);
28 #define blob_skip(b, l) blob_seek(b, l, SEEK_CUR)
29 #define blob_rewind(b) blob_seek(b, 0, SEEK_SET)
31 #define blob_offset(b) ((b)->off)
32 #define blob_left(b) ((b)->end - (b)->off)
34 int blob_index(blob_t
*b
, const void *buf
, int len
);
35 int blob_rindex(blob_t
*b
, const void *buf
, int len
);
37 int blob_pack(blob_t
*b
, const char *fmt
, ...);
38 int blob_unpack(blob_t
*b
, const char *fmt
, ...);
40 int blob_insert(blob_t
*b
, const void *buf
, int len
);
41 int blob_delete(blob_t
*b
, void *buf
, int len
);
43 int blob_print(blob_t
*b
, char *style
, int len
);
45 blob_t
*blob_free(blob_t
*b
);
47 int blob_register_alloc(size_t size
, void *(*bmalloc
)(size_t),
48 void (*bfree
)(void *), void *(*brealloc
)(void *, size_t));
50 typedef int (*blob_fmt_cb
)(int pack
, int len
, blob_t
*b
, va_list *arg
);
52 int blob_register_pack(char c
, blob_fmt_cb fmt_cb
);
56 #endif /* DNET_BLOB_H */