Yabin Cui | ce2385d | 2024-07-10 15:58:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2024 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <memory> |
| 18 | #include <string_view> |
| 19 | |
| 20 | namespace simpleperf { |
| 21 | |
| 22 | class Compressor { |
| 23 | public: |
| 24 | virtual ~Compressor(); |
| 25 | |
| 26 | virtual bool AddInputData(const char* data, size_t size) = 0; |
| 27 | virtual bool FlushOutputData() = 0; |
| 28 | virtual std::string_view GetOutputData() = 0; |
| 29 | virtual void ConsumeOutputData(size_t size) = 0; |
| 30 | |
| 31 | uint64_t TotalInputSize() const { return total_input_size_; } |
| 32 | uint64_t TotalOutputSize() const { return total_output_size_; } |
| 33 | |
| 34 | protected: |
| 35 | uint64_t total_input_size_ = 0; |
| 36 | uint64_t total_output_size_ = 0; |
| 37 | }; |
| 38 | |
| 39 | class Decompressor { |
| 40 | public: |
| 41 | virtual ~Decompressor(); |
| 42 | |
| 43 | virtual bool AddInputData(const char* data, size_t size) = 0; |
| 44 | virtual std::string_view GetOutputData() = 0; |
| 45 | virtual void ConsumeOutputData(size_t size) = 0; |
Yabin Cui | 0913622 | 2024-07-16 10:30:21 -0700 | [diff] [blame] | 46 | |
| 47 | bool HasOutputData() { return !GetOutputData().empty(); } |
Yabin Cui | ce2385d | 2024-07-10 15:58:38 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | std::unique_ptr<Compressor> CreateZstdCompressor(size_t compression_level = 3); |
| 51 | std::unique_ptr<Decompressor> CreateZstdDecompressor(); |
| 52 | |
| 53 | } // namespace simpleperf |