File indexing completed on 2025-01-31 10:12:02
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_UTIL_ZERO_COPY_SINK_H__
0009 #define GOOGLE_PROTOBUF_UTIL_ZERO_COPY_SINK_H__
0010
0011 #include <cstddef>
0012
0013 #include "google/protobuf/io/zero_copy_stream.h"
0014 #include "google/protobuf/port.h"
0015
0016
0017 #include "google/protobuf/port_def.inc"
0018
0019 namespace google {
0020 namespace protobuf {
0021 namespace io {
0022 namespace zc_sink_internal {
0023
0024
0025 class PROTOBUF_EXPORT ZeroCopyStreamByteSink {
0026 public:
0027 explicit ZeroCopyStreamByteSink(io::ZeroCopyOutputStream* stream)
0028 : stream_(stream) {}
0029 ZeroCopyStreamByteSink(const ZeroCopyStreamByteSink&) = delete;
0030 ZeroCopyStreamByteSink& operator=(const ZeroCopyStreamByteSink&) = delete;
0031
0032 ~ZeroCopyStreamByteSink() {
0033 if (buffer_size_ > 0) {
0034 stream_->BackUp(buffer_size_);
0035 }
0036 }
0037
0038 void Append(const char* bytes, size_t len);
0039 void Write(absl::string_view str) { Append(str.data(), str.size()); }
0040
0041 size_t bytes_written() { return bytes_written_; }
0042 bool failed() { return failed_; }
0043
0044 private:
0045 io::ZeroCopyOutputStream* stream_;
0046 void* buffer_ = nullptr;
0047 size_t buffer_size_ = 0;
0048 size_t bytes_written_ = 0;
0049 bool failed_ = false;
0050 };
0051 }
0052 }
0053 }
0054 }
0055
0056 #include "google/protobuf/port_undef.inc"
0057 #endif