Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:12:02

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
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 // Must be included last.
0017 #include "google/protobuf/port_def.inc"
0018 
0019 namespace google {
0020 namespace protobuf {
0021 namespace io {
0022 namespace zc_sink_internal {
0023 
0024 // Internal helper class, for turning a ZeroCopyOutputStream into a sink.
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 }  // namespace zc_sink_internal
0052 }  // namespace io
0053 }  // namespace protobuf
0054 }  // namespace google
0055 
0056 #include "google/protobuf/port_undef.inc"
0057 #endif  // GOOGLE_PROTOBUF_UTIL_ZERO_COPY_SINK_H__