作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

55 righe
1.5 KiB

  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_
  5. #define STORAGE_LEVELDB_DB_LOG_WRITER_H_
  6. #include <stdint.h>
  7. #include "db/log_format.h"
  8. #include "leveldb/slice.h"
  9. #include "leveldb/status.h"
  10. namespace leveldb {
  11. class WritableFile;
  12. namespace log {
  13. class Writer {
  14. public:
  15. // Create a writer that will append data to "*dest".
  16. // "*dest" must be initially empty.
  17. // "*dest" must remain live while this Writer is in use.
  18. explicit Writer(WritableFile* dest);
  19. // Create a writer that will append data to "*dest".
  20. // "*dest" must have initial length "dest_length".
  21. // "*dest" must remain live while this Writer is in use.
  22. Writer(WritableFile* dest, uint64_t dest_length);
  23. ~Writer();
  24. Status AddRecord(const Slice& slice);
  25. private:
  26. WritableFile* dest_;
  27. int block_offset_; // Current offset in block
  28. // crc32c values for all supported record types. These are
  29. // pre-computed to reduce the overhead of computing the crc of the
  30. // record type stored in the header.
  31. uint32_t type_crc_[kMaxRecordType + 1];
  32. Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length);
  33. // No copying allowed
  34. Writer(const Writer&);
  35. void operator=(const Writer&);
  36. };
  37. } // namespace log
  38. } // namespace leveldb
  39. #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_