| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium 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. |
| 4 |
| 5 #include "components/leveldb/public/cpp/util.h" |
| 6 |
| 7 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 8 |
| 9 namespace leveldb { |
| 10 |
| 11 DatabaseError LeveldbStatusToError(const leveldb::Status& s) { |
| 12 if (s.ok()) |
| 13 return DatabaseError::OK; |
| 14 if (s.IsNotFound()) |
| 15 return DatabaseError::NOT_FOUND; |
| 16 if (s.IsCorruption()) |
| 17 return DatabaseError::CORRUPTION; |
| 18 if (s.IsNotSupportedError()) |
| 19 return DatabaseError::NOT_SUPPORTED; |
| 20 if (s.IsIOError()) |
| 21 return DatabaseError::IO_ERROR; |
| 22 return DatabaseError::INVALID_ARGUMENT; |
| 23 } |
| 24 |
| 25 leveldb::Status DatabaseErrorToStatus(DatabaseError e, |
| 26 const Slice& msg, |
| 27 const Slice& msg2) { |
| 28 switch (e) { |
| 29 case DatabaseError::OK: |
| 30 return leveldb::Status::OK(); |
| 31 case DatabaseError::NOT_FOUND: |
| 32 return leveldb::Status::NotFound(msg, msg2); |
| 33 case DatabaseError::CORRUPTION: |
| 34 return leveldb::Status::Corruption(msg, msg2); |
| 35 case DatabaseError::NOT_SUPPORTED: |
| 36 return leveldb::Status::NotSupported(msg, msg2); |
| 37 case DatabaseError::INVALID_ARGUMENT: |
| 38 return leveldb::Status::InvalidArgument(msg, msg2); |
| 39 case DatabaseError::IO_ERROR: |
| 40 return leveldb::Status::IOError(msg, msg2); |
| 41 } |
| 42 |
| 43 // This will never be reached, but we still have configurations which don't |
| 44 // do switch enum checking. |
| 45 return leveldb::Status::InvalidArgument(msg, msg2); |
| 46 } |
| 47 |
| 48 leveldb::Slice GetSliceFor(const mojo::Array<uint8_t>& key) { |
| 49 if (key.size() == 0) |
| 50 return leveldb::Slice(); |
| 51 return leveldb::Slice(reinterpret_cast<const char*>(&key.front()), |
| 52 key.size()); |
| 53 } |
| 54 |
| 55 mojo::Array<uint8_t> GetArrayFor(const leveldb::Slice& s) { |
| 56 if (s.size() == 0) |
| 57 return mojo::Array<uint8_t>(); |
| 58 return mojo::Array<uint8_t>(std::vector<uint8_t>( |
| 59 reinterpret_cast<const uint8_t*>(s.data()), |
| 60 reinterpret_cast<const uint8_t*>(s.data() + s.size()))); |
| 61 } |
| 62 |
| 63 } // namespace leveldb |
| OLD | NEW |