]>
git.saurik.com Git - redis.git/blob - src/rio.h
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. */
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
*);
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. */
19 void (*update_cksum
)(struct _rio
*, const void *buf
, size_t len
);
21 /* The current checksum */
24 /* Backend-specific vars. */
36 typedef struct _rio rio
;
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
42 inline size_t rioWrite(rio
*r
, const void *buf
, size_t len
) {
43 if (r
->update_cksum
) r
->update_cksum(r
,buf
,len
);
44 return r
->write(r
,buf
,len
);
47 inline size_t rioRead(rio
*r
, void *buf
, size_t len
) {
48 if (r
->read(r
,buf
,len
) == 1) {
49 if (r
->update_cksum
) r
->update_cksum(r
,buf
,len
);
55 inline off_t
rioTell(rio
*r
) {
59 void rioInitWithFile(rio
*r
, FILE *fp
);
60 void rioInitWithBuffer(rio
*r
, sds s
);
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
);
67 void rioGenericUpdateChecksum(rio
*r
, const void *buf
, size_t len
);