1 /* 2 * Copyright (c) 2021 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 DATA_COMPRESSION_H 16 #define DATA_COMPRESSION_H 17 18 #include <vector> 19 #include <set> 20 #include <map> 21 22 #include "types_export.h" 23 24 namespace DistributedDB { 25 class DataCompression { 26 public: 27 static DataCompression *GetInstance(CompressAlgorithm algo); 28 static void GetCompressionAlgo(std::set<CompressAlgorithm> &algorithmSet); 29 static int TransferCompressionAlgo(uint32_t compressAlgoType, CompressAlgorithm &algoType); 30 31 virtual int Compress(const std::vector<uint8_t> &srcData, std::vector<uint8_t> &destData) const = 0; 32 virtual int Uncompress(const std::vector<uint8_t> &srcData, std::vector<uint8_t> &destData, uint32_t destLen) 33 const = 0; 34 35 protected: 36 DataCompression() = default; 37 virtual ~DataCompression() = default; 38 DataCompression(const DataCompression& compression) = delete; 39 DataCompression& operator= (const DataCompression& compression) = delete; 40 41 static void Register(CompressAlgorithm algo, DataCompression *compression); 42 43 private: 44 static std::map<CompressAlgorithm, DataCompression *> &GetCompressionAlgos(); 45 static std::map<uint32_t, CompressAlgorithm> &GetTransMap(); 46 }; 47 } // namespace DistributedDB 48 #endif // DATA_COMPRESSION_H