]> git.saurik.com Git - redis.git/blame - src/rio.h
Abstract file/buffer I/O to support in-memory serialization
[redis.git] / src / rio.h
CommitLineData
2e4b0e77
PN
1#ifndef __REDIS_RIO_H
2#define __REDIS_RIO_H
3
4#include <stdio.h>
5#include "sds.h"
6
7struct _rio {
8 /* Backend functions. Both read and write should return 0 for short reads
9 * or writes, identical to the return values of fread/fwrite. */
10 size_t (*read)(struct _rio *, void *buf, size_t len);
11 size_t (*write)(struct _rio *, const void *buf, size_t len);
12 off_t (*tell)(struct _rio *);
13
14 /* Backend-specific vars. */
15 union {
16 struct {
17 sds ptr;
18 off_t pos;
19 } buffer;
20 struct {
21 FILE *fp;
22 } file;
23 } io;
24};
25
26typedef struct _rio rio;
27
28#define rioWrite(rio,buf,len) ((rio)->write((rio),(buf),(len)))
29#define rioRead(rio,buf,len) ((rio)->read((rio),(buf),(len)))
30
31rio rioInitWithFile(FILE *fp);
32rio rioInitWithBuffer(sds s);
33
34size_t rioWriteBulkCount(rio *r, char prefix, int count);
35size_t rioWriteBulkString(rio *r, const char *buf, size_t len);
36size_t rioWriteBulkLongLong(rio *r, long long l);
37size_t rioWriteBulkDouble(rio *r, double d);
38
39#endif