Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 70 lines (56 sloc) 2.086 kb
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
1 #ifndef __REDIS_RIO_H
2 #define __REDIS_RIO_H
3
4 #include <stdio.h>
736b7c3 @antirez Add checksum computation to rio.c
authored
5 #include <stdint.h>
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
6 #include "sds.h"
7
8 struct _rio {
4c04629 @antirez comment on top of the _rio structure modified for correctness as actu…
authored
9 /* Backend functions.
10 * Since this functions do not tolerate short writes or reads the return
11 * value is simplified to: zero on error, non zero on complete success. */
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
12 size_t (*read)(struct _rio *, void *buf, size_t len);
13 size_t (*write)(struct _rio *, const void *buf, size_t len);
14 off_t (*tell)(struct _rio *);
736b7c3 @antirez Add checksum computation to rio.c
authored
15 /* The update_cksum method if not NULL is used to compute the checksum of all the
16 * data that was read or written so far. The method should be designed so that
17 * can be called with the current checksum, and the buf and len fields pointing
18 * to the new block of data to add to the checksum computation. */
8491f1d @antirez Fixed compilation of new rio.c changes (typos and so forth.)
authored
19 void (*update_cksum)(struct _rio *, const void *buf, size_t len);
736b7c3 @antirez Add checksum computation to rio.c
authored
20
21 /* The current checksum */
22 uint64_t cksum;
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
23
24 /* Backend-specific vars. */
25 union {
26 struct {
27 sds ptr;
28 off_t pos;
29 } buffer;
30 struct {
31 FILE *fp;
32 } file;
33 } io;
34 };
35
36 typedef struct _rio rio;
37
736b7c3 @antirez Add checksum computation to rio.c
authored
38 /* The following functions are our interface with the stream. They'll call the
39 * actual implementation of read / write / tell, and will update the checksum
40 * if needed. */
41
c44ab51 @antirez Make inline functions rioRead/Write/Tell static. This fixes issue #447.
authored
42 static inline size_t rioWrite(rio *r, const void *buf, size_t len) {
8491f1d @antirez Fixed compilation of new rio.c changes (typos and so forth.)
authored
43 if (r->update_cksum) r->update_cksum(r,buf,len);
736b7c3 @antirez Add checksum computation to rio.c
authored
44 return r->write(r,buf,len);
45 }
46
c44ab51 @antirez Make inline functions rioRead/Write/Tell static. This fixes issue #447.
authored
47 static inline size_t rioRead(rio *r, void *buf, size_t len) {
736b7c3 @antirez Add checksum computation to rio.c
authored
48 if (r->read(r,buf,len) == 1) {
8491f1d @antirez Fixed compilation of new rio.c changes (typos and so forth.)
authored
49 if (r->update_cksum) r->update_cksum(r,buf,len);
736b7c3 @antirez Add checksum computation to rio.c
authored
50 return 1;
51 }
52 return 0;
53 }
54
c44ab51 @antirez Make inline functions rioRead/Write/Tell static. This fixes issue #447.
authored
55 static inline off_t rioTell(rio *r) {
736b7c3 @antirez Add checksum computation to rio.c
authored
56 return r->tell(r);
57 }
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
58
f96a8a8 @antirez rioInitWithFile nad rioInitWithBuffer functions now take a rio struct…
authored
59 void rioInitWithFile(rio *r, FILE *fp);
60 void rioInitWithBuffer(rio *r, sds s);
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
61
62 size_t rioWriteBulkCount(rio *r, char prefix, int count);
63 size_t rioWriteBulkString(rio *r, const char *buf, size_t len);
64 size_t rioWriteBulkLongLong(rio *r, long long l);
65 size_t rioWriteBulkDouble(rio *r, double d);
66
736b7c3 @antirez Add checksum computation to rio.c
authored
67 void rioGenericUpdateChecksum(rio *r, const void *buf, size_t len);
68
2e4b0e7 @pietern Abstract file/buffer I/O to support in-memory serialization
pietern authored
69 #endif
Something went wrong with that request. Please try again.