作者: 韩晨旭@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.

38 lines
1014 B

  1. #include <string>
  2. #include "leveldb/env.h"
  3. #include <table/vtable_reader.h>
  4. namespace leveldb {
  5. Status VTableReader::Open(const Options& options, std::string fname) {
  6. options_ = options;
  7. return options_.env->NewRandomAccessFile(fname, &file_);
  8. }
  9. Status VTableReader::Get(const VTableHandle& handle,
  10. VTableRecord* record) const {
  11. auto buf = new char[handle.size];
  12. Slice input;
  13. Status s = file_->Read(handle.offset, handle.size, &input, buf);
  14. if (!s.ok()) {
  15. return s;
  16. }
  17. if (handle.size != static_cast<uint64_t>(input.size())) {
  18. return Status::Corruption("Read input size not equal to record size: " +
  19. std::to_string(input.size()) + ":" +
  20. std::to_string(handle.size));
  21. }
  22. RecordDecoder decoder;
  23. s = decoder.DecodeHeader(&input);
  24. if (!s.ok()) {
  25. return s;
  26. }
  27. s = decoder.DecodeRecord(&input, record);
  28. return s;
  29. }
  30. } // namespace leveldb