forked from RedisLabs/memtier_benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_io.h
64 lines (52 loc) · 1.8 KB
/
file_io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (C) 2011-2017 Redis Labs Ltd.
*
* This file is part of memtier_benchmark.
*
* memtier_benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* memtier_benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with memtier_benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _FILE_IO_H
#define _FILE_IO_H
#include <stdio.h>
#include "item.h"
/** Provides a mechanism to read a CSV-like memcache_dump file and extract memcache
* items from it.
*/
class file_reader {
protected:
const char *m_filename; /** name of file */
FILE* m_file; /** handle of open file */
unsigned int m_line; /** current line being read */
char* read_string(unsigned int len, unsigned int alloc_len, unsigned int* actual_len);
public:
file_reader(const char *filename);
file_reader(const file_reader& from);
~file_reader();
bool open_file(void);
bool is_eof(void);
memcache_item* read_item(void);
};
/** Provides a mechanism to write memcache items into a CSV-like memcache_dump file.
*/
class file_writer {
protected:
const char *m_filename; /** name of file */
FILE *m_file; /** handle of open file */
char* get_quoted_str(char* str, int str_len, int* new_str_len);
public:
file_writer(const char *filename);
~file_writer();
bool open_file(void);
bool write_item(memcache_item *item);
};
#endif /* _FILE_IO_H */