作者: 韩晨旭@ArcueidType(Arcueid) 10225101440 李畅@wesley 10225102463 设计文档为PLAN.md,md版本报告为README.md,pdf版本报告为Report.pdf
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1014 B

#include <string>
#include "leveldb/env.h"
#include <table/vtable_reader.h>
namespace leveldb {
Status VTableReader::Open(const Options& options, std::string fname) {
options_ = options;
return options_.env->NewRandomAccessFile(fname, &file_);
}
Status VTableReader::Get(const VTableHandle& handle,
VTableRecord* record) const {
auto buf = new char[handle.size];
Slice input;
Status s = file_->Read(handle.offset, handle.size, &input, buf);
if (!s.ok()) {
return s;
}
if (handle.size != static_cast<uint64_t>(input.size())) {
return Status::Corruption("Read input size not equal to record size: " +
std::to_string(input.size()) + ":" +
std::to_string(handle.size));
}
RecordDecoder decoder;
s = decoder.DecodeHeader(&input);
if (!s.ok()) {
return s;
}
s = decoder.DecodeRecord(&input, record);
return s;
}
} // namespace leveldb