18 #include "scanner/util/common.h" 19 #include "storehouse/storage_backend.h" 26 inline void s_write(storehouse::WriteFile* file,
const u8* buffer,
28 storehouse::StoreResult result;
29 EXP_BACKOFF(file->append(size, buffer), result);
30 exit_on_error(result);
34 inline void s_write(storehouse::WriteFile* file,
const T& value) {
35 s_write(file, reinterpret_cast<const u8*>(&value),
sizeof(T));
39 inline void s_write(storehouse::WriteFile* file,
const std::string& s) {
40 s_write(file, reinterpret_cast<const u8*>(s.c_str()), s.size() + 1);
43 inline void s_read(storehouse::RandomReadFile* file, u8* buffer,
size_t size,
45 VLOG(2) <<
"Reading " << file->path() <<
" (size " << size <<
", pos " << pos
47 storehouse::StoreResult result;
49 EXP_BACKOFF(file->read(pos, size, buffer, size_read), result);
50 if (result != storehouse::StoreResult::EndOfFile) {
51 exit_on_error(result);
53 assert(size_read == size);
58 inline T s_read(storehouse::RandomReadFile* file, u64& pos) {
60 s_read(file, reinterpret_cast<u8*>(&var),
sizeof(T), pos);
65 inline std::string s_read(storehouse::RandomReadFile* file, u64& pos) {
70 const size_t buf_size = 256;
73 storehouse::StoreResult result;
75 EXP_BACKOFF(file->read(pos, buf_size, buf, size_read), result);
76 if (result != storehouse::StoreResult::EndOfFile) {
77 exit_on_error(result);
78 assert(size_read == buf_size);
82 while (buf_pos < buf_size) {
83 if (buf[buf_pos] ==
'\0')
break;
87 if (buf_pos < buf_size && buf[buf_pos] ==
'\0')
break;
91 pos += var.size() + 1;
Definition: database.cpp:36