summaryrefslogtreecommitdiffstats
path: root/components/leveldb/util.cc
blob: cffee8d08ddf3d299552a9711ac48a6b082e06cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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/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::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());
}

}  // namespace leveldb