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 #ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__
0018 #define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__
0019
0020 #include <iosfwd>
0021 #include <string>
0022
0023 #include "google/protobuf/stubs/common.h"
0024 #include "google/protobuf/io/zero_copy_stream.h"
0025 #include "google/protobuf/io/zero_copy_stream_impl_lite.h"
0026
0027
0028 #include "google/protobuf/port_def.inc"
0029
0030 namespace google {
0031 namespace protobuf {
0032 namespace io {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 class PROTOBUF_EXPORT FileInputStream final : public ZeroCopyInputStream {
0043 public:
0044
0045
0046
0047
0048 explicit FileInputStream(int file_descriptor, int block_size = -1);
0049 FileInputStream(const FileInputStream&) = delete;
0050 FileInputStream& operator=(const FileInputStream&) = delete;
0051
0052
0053
0054
0055 bool Close();
0056
0057
0058
0059
0060
0061
0062 void SetCloseOnDelete(bool value) { copying_input_.SetCloseOnDelete(value); }
0063
0064
0065
0066
0067
0068 int GetErrno() const { return copying_input_.GetErrno(); }
0069
0070
0071 bool Next(const void** data, int* size) override;
0072 void BackUp(int count) override;
0073 bool Skip(int count) override;
0074 int64_t ByteCount() const override;
0075
0076 private:
0077 class PROTOBUF_EXPORT CopyingFileInputStream final
0078 : public CopyingInputStream {
0079 public:
0080 CopyingFileInputStream(int file_descriptor);
0081 CopyingFileInputStream(const CopyingFileInputStream&) = delete;
0082 CopyingFileInputStream& operator=(const CopyingFileInputStream&) = delete;
0083 ~CopyingFileInputStream() override;
0084
0085 bool Close();
0086 void SetCloseOnDelete(bool value) { close_on_delete_ = value; }
0087 int GetErrno() const { return errno_; }
0088
0089
0090 int Read(void* buffer, int size) override;
0091 int Skip(int count) override;
0092
0093 private:
0094
0095 const int file_;
0096 bool close_on_delete_;
0097 bool is_closed_;
0098
0099
0100 int errno_;
0101
0102
0103
0104 bool previous_seek_failed_;
0105 };
0106
0107 CopyingFileInputStream copying_input_;
0108 CopyingInputStreamAdaptor impl_;
0109 };
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 class PROTOBUF_EXPORT FileOutputStream final
0121 : public CopyingOutputStreamAdaptor {
0122 public:
0123
0124
0125
0126
0127 explicit FileOutputStream(int file_descriptor, int block_size = -1);
0128 FileOutputStream(const FileOutputStream&) = delete;
0129 FileOutputStream& operator=(const FileOutputStream&) = delete;
0130
0131 ~FileOutputStream() override;
0132
0133
0134
0135
0136 bool Close();
0137
0138
0139
0140
0141
0142
0143 void SetCloseOnDelete(bool value) { copying_output_.SetCloseOnDelete(value); }
0144
0145
0146
0147
0148
0149 int GetErrno() const { return copying_output_.GetErrno(); }
0150
0151 private:
0152 class PROTOBUF_EXPORT CopyingFileOutputStream final
0153 : public CopyingOutputStream {
0154 public:
0155 CopyingFileOutputStream(int file_descriptor);
0156 CopyingFileOutputStream(const CopyingFileOutputStream&) = delete;
0157 CopyingFileOutputStream& operator=(const CopyingFileOutputStream&) = delete;
0158 ~CopyingFileOutputStream() override;
0159
0160 bool Close();
0161 void SetCloseOnDelete(bool value) { close_on_delete_ = value; }
0162 int GetErrno() const { return errno_; }
0163
0164
0165 bool Write(const void* buffer, int size) override;
0166
0167 private:
0168
0169 const int file_;
0170 bool close_on_delete_;
0171 bool is_closed_;
0172
0173
0174 int errno_;
0175 };
0176
0177 CopyingFileOutputStream copying_output_;
0178 };
0179
0180
0181
0182
0183
0184
0185
0186 class PROTOBUF_EXPORT IstreamInputStream final : public ZeroCopyInputStream {
0187 public:
0188
0189
0190
0191
0192 explicit IstreamInputStream(std::istream* stream, int block_size = -1);
0193 IstreamInputStream(const IstreamInputStream&) = delete;
0194 IstreamInputStream& operator=(const IstreamInputStream&) = delete;
0195
0196
0197 bool Next(const void** data, int* size) override;
0198 void BackUp(int count) override;
0199 bool Skip(int count) override;
0200 int64_t ByteCount() const override;
0201
0202 private:
0203 class PROTOBUF_EXPORT CopyingIstreamInputStream final
0204 : public CopyingInputStream {
0205 public:
0206 CopyingIstreamInputStream(std::istream* input);
0207 CopyingIstreamInputStream(const CopyingIstreamInputStream&) = delete;
0208 CopyingIstreamInputStream& operator=(const CopyingIstreamInputStream&) =
0209 delete;
0210 ~CopyingIstreamInputStream() override;
0211
0212
0213 int Read(void* buffer, int size) override;
0214
0215
0216 private:
0217
0218 std::istream* input_;
0219 };
0220
0221 CopyingIstreamInputStream copying_input_;
0222 CopyingInputStreamAdaptor impl_;
0223 };
0224
0225
0226
0227
0228
0229
0230
0231 class PROTOBUF_EXPORT OstreamOutputStream final : public ZeroCopyOutputStream {
0232 public:
0233
0234
0235
0236
0237 explicit OstreamOutputStream(std::ostream* stream, int block_size = -1);
0238 OstreamOutputStream(const OstreamOutputStream&) = delete;
0239 OstreamOutputStream& operator=(const OstreamOutputStream&) = delete;
0240 ~OstreamOutputStream() override;
0241
0242
0243 bool Next(void** data, int* size) override;
0244 void BackUp(int count) override;
0245 int64_t ByteCount() const override;
0246
0247 private:
0248 class PROTOBUF_EXPORT CopyingOstreamOutputStream final
0249 : public CopyingOutputStream {
0250 public:
0251 CopyingOstreamOutputStream(std::ostream* output);
0252 CopyingOstreamOutputStream(const CopyingOstreamOutputStream&) = delete;
0253 CopyingOstreamOutputStream& operator=(const CopyingOstreamOutputStream&) =
0254 delete;
0255 ~CopyingOstreamOutputStream() override;
0256
0257
0258 bool Write(const void* buffer, int size) override;
0259
0260 private:
0261
0262 std::ostream* output_;
0263 };
0264
0265 CopyingOstreamOutputStream copying_output_;
0266 CopyingOutputStreamAdaptor impl_;
0267 };
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278 class PROTOBUF_EXPORT ConcatenatingInputStream final
0279 : public ZeroCopyInputStream {
0280 public:
0281
0282
0283 ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count);
0284 ConcatenatingInputStream(const ConcatenatingInputStream&) = delete;
0285 ConcatenatingInputStream& operator=(const ConcatenatingInputStream&) = delete;
0286 ~ConcatenatingInputStream() override = default;
0287
0288
0289 bool Next(const void** data, int* size) override;
0290 void BackUp(int count) override;
0291 bool Skip(int count) override;
0292 int64_t ByteCount() const override;
0293
0294
0295 private:
0296
0297
0298 ZeroCopyInputStream* const* streams_;
0299 int stream_count_;
0300 int64_t bytes_retired_;
0301 };
0302
0303
0304
0305 }
0306 }
0307 }
0308
0309 #include "google/protobuf/port_undef.inc"
0310
0311 #endif