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.
7 #include "leveldb/status.h"
11 const char* Status::CopyState(const char* state) {
13 memcpy(&size, state, sizeof(size));
14 char* result = new char[size + 5];
15 memcpy(result, state, size + 5);
19 Status::Status(Code code, const Slice& msg, const Slice& msg2) {
21 const uint32_t len1 = msg.size();
22 const uint32_t len2 = msg2.size();
23 const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
24 char* result = new char[size + 5];
25 memcpy(result, &size, sizeof(size));
26 result[4] = static_cast<char>(code);
27 memcpy(result + 5, msg.data(), len1);
29 result[5 + len1] = ':';
30 result[6 + len1] = ' ';
31 memcpy(result + 7 + len1, msg2.data(), len2);
36 std::string Status::ToString() const {
50 type = "Corruption: ";
53 type = "Not implemented: ";
55 case kInvalidArgument:
56 type = "Invalid argument: ";
62 snprintf(tmp, sizeof(tmp), "Unknown code(%d): ",
63 static_cast<int>(code()));
67 std::string result(type);
69 memcpy(&length, state_, sizeof(length));
70 result.append(state_ + 5, length);
75 } // namespace leveldb