mariadb/newbrt/rbuf.h
Bradley C. Kuszmaul 2fcb4bfaaf Separate rbuf and wbuf so that log.c can use it. Check in a perliminary version of log.c
git-svn-id: file:///svn/tokudb@162 c7de825b-a66e-492c-adef-691d508d4ae1
2007-08-21 23:32:17 +00:00

42 lines
968 B
C

#ifndef RBUF_H
#define RBUF_H
#include <assert.h>
struct rbuf {
unsigned char *buf;
unsigned int size;
unsigned int ndone;
};
static unsigned int rbuf_char (struct rbuf *r) {
assert(r->ndone<r->size);
return r->buf[r->ndone++];
}
static unsigned int rbuf_int (struct rbuf *r) {
unsigned char c0 = rbuf_char(r);
unsigned char c1 = rbuf_char(r);
unsigned char c2 = rbuf_char(r);
unsigned char c3 = rbuf_char(r);
return ((c0<<24)|
(c1<<16)|
(c2<<8)|
(c3<<0));
}
/* Return a pointer into the middle of the buffer. */
static void rbuf_bytes (struct rbuf *r, bytevec *bytes, unsigned int *n_bytes)
{
*n_bytes = rbuf_int(r);
*bytes = &r->buf[r->ndone];
r->ndone+=*n_bytes;
assert(r->ndone<=r->size);
}
static diskoff rbuf_diskoff (struct rbuf *r) {
unsigned i0 = rbuf_int(r);
unsigned i1 = rbuf_int(r);
return ((unsigned long long)(i0)<<32) | ((unsigned long long)(i1));
}
#endif