leveldb source read -status

In reading the log file, you will find the use of Statusthis class, you can use it to get state function returns, such as:

Status s = Function();
if (!s.ok()) return false;
return true

Seriously today to learn about the relevant implementation.

1. Private

  1. state_, A pointer points to a character constant. If it is successful state_is null, otherwise, he is an array, index is 0 to 3 message length, a status code 4, 5 after the message itself.

  2. Return status is enumerated in the Status class, these states are enumerable private variables Code, has defined success, did not find an error, it does not support, legal parameters, IO error six cases.

  3. function code, and the fourth state by state_ return value is a value which enumerable

  4. The constructor with no arguments. This is a very important function, because the public function mainly use this function returns the status and type.

Status::Status(Code code, const Slice& msg, const Slice& msg2) 

Primarily using a memcpymemory copy, the msg in bytes copied to the returned results, the specific process is as follows:

  1. CopyStateFunction, the state of deep copy, which opened up a new memory.

You can see here also use memcpy function, I checked the official documents , there is a comment:

std :: memcpy is supposed to be the fastest memory to memory copy routine. It is usually more than copying data to scan its std :: strcpy, or must be prevented to process overlapping input std :: memmove more efficient.

2. public

2.1 the big three

  1. Constructor
  2. Destructor
  3. The copy constructor - is a parameter passing const
  4. Mutator - mass participation is const
  5. The copy constructor - pass non-const reference
  6. Assignment Constructor - pass non-const reference

2.2 is not a certain kind of state

We have said before, a total of 6 enumerable state, so there are six public member function that returns a Boolean type is to determine the state is not OK or wrong and so on. The main use of what we said before Codefunction.

2.3 and certain status information return package

The constructor function is six, using what we said before with parameters.

2.4 to String

State to turn into a string, easy to print.

Published 120 original articles · won praise 35 · views 170 000 +

Guess you like

Origin blog.csdn.net/u012328476/article/details/104499725