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
5#ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_
6#define STORAGE_LEVELDB_DB_LOG_WRITER_H_
7
8#include <stdint.h>
9#include "db/log_format.h"
10#include "leveldb/slice.h"
11#include "leveldb/status.h"
12
13namespace leveldb {
14
15class WritableFile;
16
17namespace log {
18
19class Writer {
20 public:
21  // Create a writer that will append data to "*dest".
22  // "*dest" must be initially empty.
23  // "*dest" must remain live while this Writer is in use.
24  explicit Writer(WritableFile* dest);
25  ~Writer();
26
27  Status AddRecord(const Slice& slice);
28
29 private:
30  WritableFile* dest_;
31  int block_offset_;       // Current offset in block
32
33  // crc32c values for all supported record types.  These are
34  // pre-computed to reduce the overhead of computing the crc of the
35  // record type stored in the header.
36  uint32_t type_crc_[kMaxRecordType + 1];
37
38  Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length);
39
40  // No copying allowed
41  Writer(const Writer&);
42  void operator=(const Writer&);
43};
44
45}  // namespace log
46}  // namespace leveldb
47
48#endif  // STORAGE_LEVELDB_DB_LOG_WRITER_H_
49