leveldb
Classes | Public Member Functions | Private Attributes | Friends | List of all members
leveldb::WriteBatch Class Reference

#include <write_batch.h>

Classes

class  Handler
 

Public Member Functions

 WriteBatch ()
 
 ~WriteBatch ()
 
void Put (const Slice &key, const Slice &value)
 
void Delete (const Slice &key)
 
void Clear ()
 
Status Iterate (Handler *handler) const
 

Private Attributes

std::string rep_
 

Friends

class WriteBatchInternal
 

Detailed Description

Definition at line 31 of file write_batch.h.

Constructor & Destructor Documentation

§ WriteBatch()

leveldb::WriteBatch::WriteBatch ( )

Definition at line 29 of file write_batch.cc.

29  {
30  Clear();
31 }
Here is the call graph for this function:

§ ~WriteBatch()

leveldb::WriteBatch::~WriteBatch ( )

Definition at line 33 of file write_batch.cc.

33 { }

Member Function Documentation

§ Clear()

void leveldb::WriteBatch::Clear ( )

Definition at line 37 of file write_batch.cc.

37  {
38  rep_.clear();
39  rep_.resize(kHeader);
40 }
std::string rep_
Definition: write_batch.h:57
static const size_t kHeader
Definition: write_batch.cc:27
Here is the caller graph for this function:

§ Delete()

void leveldb::WriteBatch::Delete ( const Slice key)

Definition at line 105 of file write_batch.cc.

105  {
107  rep_.push_back(static_cast<char>(kTypeDeletion));
109 }
void PutLengthPrefixedSlice(std::string *dst, const Slice &value)
Definition: coding.cc:98
std::string rep_
Definition: write_batch.h:57
static void SetCount(WriteBatch *batch, int n)
Definition: write_batch.cc:86
static int Count(const WriteBatch *batch)
Definition: write_batch.cc:82
Here is the call graph for this function:
Here is the caller graph for this function:

§ Iterate()

Status leveldb::WriteBatch::Iterate ( Handler handler) const

Definition at line 42 of file write_batch.cc.

42  {
43  Slice input(rep_);
44  if (input.size() < kHeader) {
45  return Status::Corruption("malformed WriteBatch (too small)");
46  }
47 
48  input.remove_prefix(kHeader);
49  Slice key, value;
50  int found = 0;
51  while (!input.empty()) {
52  found++;
53  char tag = input[0];
54  input.remove_prefix(1);
55  switch (tag) {
56  case kTypeValue:
57  if (GetLengthPrefixedSlice(&input, &key) &&
58  GetLengthPrefixedSlice(&input, &value)) {
59  handler->Put(key, value);
60  } else {
61  return Status::Corruption("bad WriteBatch Put");
62  }
63  break;
64  case kTypeDeletion:
65  if (GetLengthPrefixedSlice(&input, &key)) {
66  handler->Delete(key);
67  } else {
68  return Status::Corruption("bad WriteBatch Delete");
69  }
70  break;
71  default:
72  return Status::Corruption("unknown WriteBatch tag");
73  }
74  }
75  if (found != WriteBatchInternal::Count(this)) {
76  return Status::Corruption("WriteBatch has wrong count");
77  } else {
78  return Status::OK();
79  }
80 }
static Slice GetLengthPrefixedSlice(const char *data)
Definition: memtable.cc:14
static Status Corruption(const Slice &msg, const Slice &msg2=Slice())
Definition: status.h:38
static Status OK()
Definition: status.h:32
std::string rep_
Definition: write_batch.h:57
static int Count(const WriteBatch *batch)
Definition: write_batch.cc:82
static const size_t kHeader
Definition: write_batch.cc:27
Here is the call graph for this function:
Here is the caller graph for this function:

§ Put()

void leveldb::WriteBatch::Put ( const Slice key,
const Slice value 
)

Definition at line 98 of file write_batch.cc.

98  {
100  rep_.push_back(static_cast<char>(kTypeValue));
102  PutLengthPrefixedSlice(&rep_, value);
103 }
void PutLengthPrefixedSlice(std::string *dst, const Slice &value)
Definition: coding.cc:98
std::string rep_
Definition: write_batch.h:57
static void SetCount(WriteBatch *batch, int n)
Definition: write_batch.cc:86
static int Count(const WriteBatch *batch)
Definition: write_batch.cc:82
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

§ WriteBatchInternal

friend class WriteBatchInternal
friend

Definition at line 55 of file write_batch.h.

Member Data Documentation

§ rep_

std::string leveldb::WriteBatch::rep_
private

Definition at line 57 of file write_batch.h.


The documentation for this class was generated from the following files: