Go to the documentation of this file.
19 #ifndef GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
20 #define GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
31 #include <type_traits>
33 #include "absl/log/absl_check.h"
34 #include "absl/strings/cord.h"
43 class ProtoBufferWriterPeer;
63 : block_size_(block_size),
64 total_size_(total_size),
67 ABSL_CHECK(!byte_buffer->
Valid());
70 byte_buffer->set_buffer(bp);
82 bool Next(
void** data,
int* size)
override {
84 ABSL_CHECK_LT(byte_count_, total_size_);
90 size_t remain =
static_cast<size_t>(total_size_ - byte_count_);
93 slice_ = backup_slice_;
101 size_t allocate_length =
102 remain >
static_cast<size_t>(block_size_) ? block_size_ : remain;
128 if (count == 0)
return;
137 backup_slice_ = slice_;
147 have_backup_ = backup_slice_.
refcount !=
nullptr;
148 byte_count_ -= count;
152 int64_t
ByteCount()
const override {
return byte_count_; }
154 #ifdef GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
161 virtual bool WriteCord(
const absl::Cord& cord)
162 #if GOOGLE_PROTOBUF_VERSION >= 4022000
170 for (absl::string_view chunk : cord.Chunks()) {
172 if (chunk.size() < 512) {
181 absl::Cord* subcord =
new absl::Cord(cord.Subcord(cur, chunk.size()));
183 const_cast<uint8_t*
>(
184 reinterpret_cast<const uint8_t*
>(chunk.data())),
185 chunk.size(), [](
void* p) { delete static_cast<absl::Cord*>(p); },
194 #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
207 const int block_size_;
208 const int total_size_;
220 #endif // GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
GPRAPI grpc_slice grpc_slice_new_with_user_data(void *p, size_t len, void(*destroy)(void *), void *user_data)
Equivalent to grpc_slice_new, but with a separate pointer that is passed to the destroy function.
This is a specialization of the protobuf class ZeroCopyOutputStream.
Definition: proto_buffer_writer.h:55
struct grpc_slice_refcount * refcount
Definition: slice_type.h:63
bool Next(void **data, int *size) override
Give the proto library the next buffer of bytes and its size.
Definition: proto_buffer_writer.h:82
#define GRPC_SLICE_START_PTR(slice)
Definition: slice_type.h:98
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
::google::protobuf::io::ZeroCopyOutputStream ZeroCopyOutputStream
Definition: config_protobuf.h:114
struct grpc_byte_buffer::grpc_byte_buffer_data::grpc_compressed_buffer raw
GPRAPI grpc_slice grpc_slice_malloc(size_t length)
Equivalent to grpc_slice_new(malloc(len), len, free), but saves one malloc() call.
GPRAPI size_t grpc_slice_buffer_add_indexed(grpc_slice_buffer *sb, grpc_slice slice)
add an element to a slice buffer - takes ownership of the slice and returns the index of the slice.
GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len)
Create a slice by copying a buffer.
ProtoBufferWriter(ByteBuffer *byte_buffer, int block_size, int total_size)
Constructor for this derived class.
Definition: proto_buffer_writer.h:62
Definition: grpc_types.h:41
A sequence of bytes.
Definition: byte_buffer.h:59
GPRAPI void grpc_slice_buffer_pop(grpc_slice_buffer *sb)
pop the last buffer, but don't unref it
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice_type.h:62
GPRAPI void grpc_slice_buffer_add(grpc_slice_buffer *sb, grpc_slice slice)
Add an element to a slice buffer - takes ownership of the slice.
const int kProtoBufferWriterMaxBufferLength
Definition: proto_buffer_writer.h:46
grpc_slice_buffer * slice_buffer()
Definition: proto_buffer_writer.h:201
union grpc_byte_buffer::grpc_byte_buffer_data data
int64_t ByteCount() const override
Returns the total number of bytes written since this object was created.
Definition: proto_buffer_writer.h:152
~ProtoBufferWriter() override
Definition: proto_buffer_writer.h:74
GPRAPI grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split)
Splits s into two: modifies s to be s[0:split], and returns a new slice, sharing a refcount with s,...
#define GRPC_SLICE_SET_LENGTH(slice, newlen)
Definition: slice_type.h:104
grpc_slice_buffer slice_buffer
Definition: grpc_types.h:50
GPRAPI void grpc_slice_unref(grpc_slice s)
Decrement the ref count of s.
bool Valid() const
Is this ByteBuffer valid?
Definition: byte_buffer.h:158
#define GRPC_SLICE_LENGTH(slice)
Definition: slice_type.h:101
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice_type.h:80
void BackUp(int count) override
Backup by count bytes because Next returned more bytes than needed (only used in the last buffer).
Definition: proto_buffer_writer.h:122
void set_byte_count(int64_t byte_count)
Definition: proto_buffer_writer.h:202
friend class internal::ProtoBufferWriterPeer
Definition: proto_buffer_writer.h:206
#define GRPC_SLICE_INLINED_SIZE
Definition: slice_type.h:46
GRPCAPI grpc_byte_buffer * grpc_raw_byte_buffer_create(grpc_slice *slices, size_t nslices)
Returns a RAW byte buffer instance over the given slices (up to nslices).