1 /* 2 * Copyright (C) 2020 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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_GZIP_GZIP_UTILS_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_GZIP_GZIP_UTILS_H_ 19 20 #include <memory> 21 22 struct z_stream_s; 23 24 namespace perfetto { 25 namespace trace_processor { 26 27 namespace gzip { 28 29 // Returns whether gzip related functioanlity is supported with the current 30 // build flags. 31 bool IsGzipSupported(); 32 33 } // namespace gzip 34 35 class GzipDecompressor { 36 public: 37 enum class ResultCode { 38 kOk, 39 kEof, 40 kError, 41 kNoProgress, 42 kNeedsMoreInput, 43 }; 44 struct Result { 45 // The return code of the decompression. 46 ResultCode ret; 47 48 // The amount of bytes written to output. 49 // Only valid if |ResultCode::kOk|. 50 size_t bytes_written; 51 }; 52 53 GzipDecompressor(); 54 ~GzipDecompressor(); 55 56 // Sets the input pointer and size of the gzip stream to inflate. 57 void SetInput(const uint8_t* data, size_t size); 58 59 // Decompresses the input previously provided in |SetInput|. 60 Result Decompress(uint8_t* out, size_t out_size); 61 62 // Sets the state of the decompressor to reuse with other gzip streams. 63 void Reset(); 64 65 private: 66 std::unique_ptr<z_stream_s> z_stream_; 67 }; 68 69 } // namespace trace_processor 70 } // namespace perfetto 71 72 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_GZIP_GZIP_UTILS_H_ 73