1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "include/convertor_mock.h"
17
18 namespace OHOS::DistributedKv {
ToLocalDBKey(const Key & key) const19 std::vector<uint8_t> Convertor::ToLocalDBKey(const Key &key) const
20 {
21 if (BConvertor::convertor == nullptr) {
22 std::vector<uint8_t> vec;
23 return vec;
24 }
25 return BConvertor::convertor->ToLocalDBKey(key);
26 }
27
ToWholeDBKey(const Key & key) const28 std::vector<uint8_t> Convertor::ToWholeDBKey(const Key &key) const
29 {
30 if (BConvertor::convertor == nullptr) {
31 std::vector<uint8_t> vc;
32 return vc;
33 }
34 return BConvertor::convertor->ToWholeDBKey(key);
35 }
36
ToKey(DBKey && key,std::string & deviceId) const37 Key Convertor::ToKey(DBKey &&key, std::string &deviceId) const
38 {
39 return std::move(key);
40 }
41
GetPrefix(const Key & prefix) const42 std::vector<uint8_t> Convertor::GetPrefix(const Key &prefix) const
43 {
44 if (BConvertor::convertor == nullptr) {
45 std::vector<uint8_t> dbKey;
46 return dbKey;
47 }
48 return BConvertor::convertor->GetPrefix(prefix);
49 }
50
GetPrefix(const DataQuery & query) const51 std::vector<uint8_t> Convertor::GetPrefix(const DataQuery &query) const
52 {
53 if (BConvertor::convertor == nullptr) {
54 std::vector<uint8_t> vec;
55 return vec;
56 }
57 return BConvertor::convertor->GetPrefix(query);
58 }
59
GetDBQuery(const DataQuery & query) const60 Convertor::DBQuery Convertor::GetDBQuery(const DataQuery &query) const
61 {
62 if (BConvertor::convertor == nullptr) {
63 DBQuery dbQuery = *(query.query_);
64 return dbQuery;
65 }
66 return BConvertor::convertor->GetDBQuery(query);
67 }
68
GetRealKey(const std::string & key,const DataQuery & query) const69 std::string Convertor::GetRealKey(const std::string &key, const DataQuery &query) const
70 {
71 if (BConvertor::convertor == nullptr) {
72 return "";
73 }
74 return BConvertor::convertor->GetRealKey(key, query);
75 }
76
TrimKey(const Key & prefix) const77 std::vector<uint8_t> Convertor::TrimKey(const Key &prefix) const
78 {
79 if (BConvertor::convertor == nullptr) {
80 std::vector<uint8_t> vc;
81 return vc;
82 }
83 return BConvertor::convertor->TrimKey(prefix);
84 }
85 } // namespace OHOS::DistributedKv