summaryrefslogtreecommitdiff
path: root/src/rio.h
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-05-13 17:31:00 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-05-13 17:31:00 +0200
commit2e4b0e7727743cf03d25da0f535ecc02aad82d1f (patch)
tree83f5f5a143abccc328c5c9feb67b03d6118e0536 /src/rio.h
parent70bc5f7724364e93c63865c02d517bc0164274d9 (diff)
downloadredis-2e4b0e7727743cf03d25da0f535ecc02aad82d1f.tar.gz
Abstract file/buffer I/O to support in-memory serialization
Diffstat (limited to 'src/rio.h')
-rw-r--r--src/rio.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/rio.h b/src/rio.h
new file mode 100644
index 000000000..fe863cb52
--- /dev/null
+++ b/src/rio.h
@@ -0,0 +1,39 @@
+#ifndef __REDIS_RIO_H
+#define __REDIS_RIO_H
+
+#include <stdio.h>
+#include "sds.h"
+
+struct _rio {
+ /* Backend functions. Both read and write should return 0 for short reads
+ * or writes, identical to the return values of fread/fwrite. */
+ size_t (*read)(struct _rio *, void *buf, size_t len);
+ size_t (*write)(struct _rio *, const void *buf, size_t len);
+ off_t (*tell)(struct _rio *);
+
+ /* Backend-specific vars. */
+ union {
+ struct {
+ sds ptr;
+ off_t pos;
+ } buffer;
+ struct {
+ FILE *fp;
+ } file;
+ } io;
+};
+
+typedef struct _rio rio;
+
+#define rioWrite(rio,buf,len) ((rio)->write((rio),(buf),(len)))
+#define rioRead(rio,buf,len) ((rio)->read((rio),(buf),(len)))
+
+rio rioInitWithFile(FILE *fp);
+rio rioInitWithBuffer(sds s);
+
+size_t rioWriteBulkCount(rio *r, char prefix, int count);
+size_t rioWriteBulkString(rio *r, const char *buf, size_t len);
+size_t rioWriteBulkLongLong(rio *r, long long l);
+size_t rioWriteBulkDouble(rio *r, double d);
+
+#endif