1 /* 2 * Copyright (c) 2022 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 #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_KEY_CONVERTOR_H 16 #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_KEY_CONVERTOR_H 17 #include <vector> 18 #include "data_query.h" 19 #include "query.h" 20 #include "types.h" 21 #include "types_export.h" 22 namespace OHOS::DistributedKv { 23 class Convertor { 24 public: 25 using DBKey = DistributedDB::Key; 26 using DBQuery = DistributedDB::Query; 27 virtual std::vector<uint8_t> ToLocalDBKey(const Key &key) const; 28 virtual std::vector<uint8_t> ToWholeDBKey(const Key &key) const; 29 virtual Key ToKey(DBKey &&key, std::string &deviceId) const; 30 virtual std::vector<uint8_t> GetPrefix(const Key &prefix) const; 31 virtual std::vector<uint8_t> GetPrefix(const DataQuery &query) const; 32 DBQuery GetDBQuery(const DataQuery &query) const; 33 34 protected: 35 virtual std::string GetRealKey(const std::string &key, const DataQuery &query) const; 36 std::vector<uint8_t> TrimKey(const Key &prefix) const; 37 38 private: 39 static constexpr size_t MAX_KEY_LENGTH = 1024; 40 }; 41 } // namespace OHOS::DistributedKv 42 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_KEY_CONVERTOR_H 43