]> git.saurik.com Git - redis.git/blob - src/rio.h
Merge pull request #209 from woowenjie/unstable
[redis.git] / src / rio.h
1 #ifndef __REDIS_RIO_H
2 #define __REDIS_RIO_H
3
4 #include <stdio.h>
5 #include "sds.h"
6
7 struct _rio {
8 /* Backend functions.
9 * Since this functions do not tolerate short writes or reads the return
10 * value is simplified to: zero on error, non zero on complete success. */
11 size_t (*read)(struct _rio *, void *buf, size_t len);
12 size_t (*write)(struct _rio *, const void *buf, size_t len);
13 off_t (*tell)(struct _rio *);
14
15 /* Backend-specific vars. */
16 union {
17 struct {
18 sds ptr;
19 off_t pos;
20 } buffer;
21 struct {
22 FILE *fp;
23 } file;
24 } io;
25 };
26
27 typedef struct _rio rio;
28
29 #define rioWrite(rio,buf,len) ((rio)->write((rio),(buf),(len)))
30 #define rioRead(rio,buf,len) ((rio)->read((rio),(buf),(len)))
31
32 void rioInitWithFile(rio *r, FILE *fp);
33 void rioInitWithBuffer(rio *r, sds s);
34
35 size_t rioWriteBulkCount(rio *r, char prefix, int count);
36 size_t rioWriteBulkString(rio *r, const char *buf, size_t len);
37 size_t rioWriteBulkLongLong(rio *r, long long l);
38 size_t rioWriteBulkDouble(rio *r, double d);
39
40 #endif