File indexing completed on 2025-01-31 10:12:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__
0021 #define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__
0022
0023 #include "google/protobuf/stubs/common.h"
0024 #include "google/protobuf/io/zero_copy_stream.h"
0025 #include "google/protobuf/port.h"
0026 #include <zlib.h>
0027
0028
0029 #include "google/protobuf/port_def.inc"
0030
0031 namespace google {
0032 namespace protobuf {
0033 namespace io {
0034
0035
0036 class PROTOBUF_EXPORT GzipInputStream final : public ZeroCopyInputStream {
0037 public:
0038
0039 enum Format {
0040
0041 AUTO = 0,
0042
0043
0044 GZIP = 1,
0045
0046
0047 ZLIB = 2,
0048 };
0049
0050
0051 explicit GzipInputStream(ZeroCopyInputStream* sub_stream,
0052 Format format = AUTO, int buffer_size = -1);
0053 GzipInputStream(const GzipInputStream&) = delete;
0054 GzipInputStream& operator=(const GzipInputStream&) = delete;
0055 ~GzipInputStream() override;
0056
0057
0058 inline const char* ZlibErrorMessage() const { return zcontext_.msg; }
0059 inline int ZlibErrorCode() const { return zerror_; }
0060
0061
0062 bool Next(const void** data, int* size) override;
0063 void BackUp(int count) override;
0064 bool Skip(int count) override;
0065 int64_t ByteCount() const override;
0066
0067 private:
0068 Format format_;
0069
0070 ZeroCopyInputStream* sub_stream_;
0071
0072 z_stream zcontext_;
0073 int zerror_;
0074
0075 void* output_buffer_;
0076 void* output_position_;
0077 size_t output_buffer_length_;
0078 int64_t byte_count_;
0079
0080 int Inflate(int flush);
0081 void DoNextOutput(const void** data, int* size);
0082 };
0083
0084 class PROTOBUF_EXPORT GzipOutputStream final : public ZeroCopyOutputStream {
0085 public:
0086
0087 enum Format {
0088
0089 GZIP = 1,
0090
0091
0092 ZLIB = 2,
0093 };
0094
0095 struct PROTOBUF_EXPORT Options {
0096
0097 Format format;
0098
0099
0100 int buffer_size;
0101
0102
0103
0104 int compression_level;
0105
0106
0107
0108
0109 int compression_strategy;
0110
0111 Options();
0112 };
0113
0114
0115 explicit GzipOutputStream(ZeroCopyOutputStream* sub_stream);
0116
0117
0118 GzipOutputStream(ZeroCopyOutputStream* sub_stream, const Options& options);
0119 GzipOutputStream(const GzipOutputStream&) = delete;
0120 GzipOutputStream& operator=(const GzipOutputStream&) = delete;
0121
0122 ~GzipOutputStream() override;
0123
0124
0125 inline const char* ZlibErrorMessage() const { return zcontext_.msg; }
0126 inline int ZlibErrorCode() const { return zerror_; }
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 bool Flush();
0141
0142
0143
0144
0145
0146 bool Close();
0147
0148
0149 bool Next(void** data, int* size) override;
0150 void BackUp(int count) override;
0151 int64_t ByteCount() const override;
0152
0153 private:
0154 ZeroCopyOutputStream* sub_stream_;
0155
0156 void* sub_data_;
0157 int sub_data_size_;
0158
0159 z_stream zcontext_;
0160 int zerror_;
0161 void* input_buffer_;
0162 size_t input_buffer_length_;
0163
0164
0165 void Init(ZeroCopyOutputStream* sub_stream, const Options& options);
0166
0167
0168
0169
0170 int Deflate(int flush);
0171 };
0172
0173 }
0174 }
0175 }
0176
0177 #include "google/protobuf/port_undef.inc"
0178
0179 #endif