Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Side by Side Diff: components/leveldb/public/cpp/util.cc

Issue 1861903002: mojo leveldb: Add an iteration interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW
« no previous file with comments | « components/leveldb/public/cpp/util.h ('k') | components/leveldb/public/interfaces/leveldb.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698