blob: 9b9cd0e12ba4f32ef5995fff89e3ae27ae283972 [file] [log] [blame]
Yabin Cuice2385d2024-07-10 15:58:38 -07001/*
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
20namespace simpleperf {
21
22class 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
39class 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 Cui09136222024-07-16 10:30:21 -070046
47 bool HasOutputData() { return !GetOutputData().empty(); }
Yabin Cuice2385d2024-07-10 15:58:38 -070048};
49
50std::unique_ptr<Compressor> CreateZstdCompressor(size_t compression_level = 3);
51std::unique_ptr<Decompressor> CreateZstdDecompressor();
52
53} // namespace simpleperf