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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/leveldb/public/cpp/util.h ('k') | components/leveldb/public/interfaces/leveldb.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/leveldb/public/cpp/util.cc
diff --git a/components/leveldb/public/cpp/util.cc b/components/leveldb/public/cpp/util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3d60ea2e971d1e404333626883c8d04ea3b7c6d2
--- /dev/null
+++ b/components/leveldb/public/cpp/util.cc
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/leveldb/public/cpp/util.h"
+
+#include "third_party/leveldatabase/src/include/leveldb/status.h"
+
+namespace leveldb {
+
+DatabaseError LeveldbStatusToError(const leveldb::Status& s) {
+ if (s.ok())
+ return DatabaseError::OK;
+ if (s.IsNotFound())
+ return DatabaseError::NOT_FOUND;
+ if (s.IsCorruption())
+ return DatabaseError::CORRUPTION;
+ if (s.IsNotSupportedError())
+ return DatabaseError::NOT_SUPPORTED;
+ if (s.IsIOError())
+ return DatabaseError::IO_ERROR;
+ return DatabaseError::INVALID_ARGUMENT;
+}
+
+leveldb::Status DatabaseErrorToStatus(DatabaseError e,
+ const Slice& msg,
+ const Slice& msg2) {
+ switch (e) {
+ case DatabaseError::OK:
+ return leveldb::Status::OK();
+ case DatabaseError::NOT_FOUND:
+ return leveldb::Status::NotFound(msg, msg2);
+ case DatabaseError::CORRUPTION:
+ return leveldb::Status::Corruption(msg, msg2);
+ case DatabaseError::NOT_SUPPORTED:
+ return leveldb::Status::NotSupported(msg, msg2);
+ case DatabaseError::INVALID_ARGUMENT:
+ return leveldb::Status::InvalidArgument(msg, msg2);
+ case DatabaseError::IO_ERROR:
+ return leveldb::Status::IOError(msg, msg2);
+ }
+
+ // This will never be reached, but we still have configurations which don't
+ // do switch enum checking.
+ return leveldb::Status::InvalidArgument(msg, msg2);
+}
+
+leveldb::Slice GetSliceFor(const mojo::Array<uint8_t>& key) {
+ if (key.size() == 0)
+ return leveldb::Slice();
+ return leveldb::Slice(reinterpret_cast<const char*>(&key.front()),
+ key.size());
+}
+
+mojo::Array<uint8_t> GetArrayFor(const leveldb::Slice& s) {
+ if (s.size() == 0)
+ return mojo::Array<uint8_t>();
+ return mojo::Array<uint8_t>(std::vector<uint8_t>(
+ reinterpret_cast<const uint8_t*>(s.data()),
+ reinterpret_cast<const uint8_t*>(s.data() + s.size())));
+}
+
+} // namespace leveldb
« 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