Go to the documentation of this file.
19 #ifndef GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
20 #define GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
22 #include <type_traits>
24 #include "absl/log/absl_check.h"
25 #include "absl/strings/cord.h"
44 class ProtoBufferWriterPeer;
64 : block_size_(block_size),
65 total_size_(total_size),
68 ABSL_CHECK(!byte_buffer->
Valid());
71 byte_buffer->set_buffer(bp);
83 bool Next(
void** data,
int* size)
override {
85 ABSL_CHECK_LT(byte_count_, total_size_);
91 size_t remain =
static_cast<size_t>(total_size_ - byte_count_);
94 slice_ = backup_slice_;
102 size_t allocate_length =
103 remain >
static_cast<size_t>(block_size_) ? block_size_ : remain;
129 if (count == 0)
return;
138 backup_slice_ = slice_;
148 have_backup_ = backup_slice_.
refcount !=
nullptr;
149 byte_count_ -= count;
153 int64_t
ByteCount()
const override {
return byte_count_; }
155 #ifdef GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
162 virtual bool WriteCord(
const absl::Cord& cord)
163 #if GOOGLE_PROTOBUF_VERSION >= 4022000
171 for (absl::string_view chunk : cord.Chunks()) {
173 if (chunk.size() < 512) {
182 absl::Cord* subcord =
new absl::Cord(cord.Subcord(cur, chunk.size()));
184 const_cast<uint8_t*
>(
185 reinterpret_cast<const uint8_t*
>(chunk.data())),
186 chunk.size(), [](
void* p) { delete static_cast<absl::Cord*>(p); },
195 #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
208 const int block_size_;
209 const int total_size_;
221 #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:56
struct grpc_slice_refcount * refcount
Definition: slice_type.h:64
bool Next(void **data, int *size) override
Give the proto library the next buffer of bytes and its size.
Definition: proto_buffer_writer.h:83
#define GRPC_SLICE_START_PTR(slice)
Definition: slice_type.h:99
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:113
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:63
Definition: grpc_types.h:42
A sequence of bytes.
Definition: byte_buffer.h:60
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:63
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:47
grpc_slice_buffer * slice_buffer()
Definition: proto_buffer_writer.h:202
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:153
~ProtoBufferWriter() override
Definition: proto_buffer_writer.h:75
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:105
grpc_slice_buffer slice_buffer
Definition: grpc_types.h:51
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:159
#define GRPC_SLICE_LENGTH(slice)
Definition: slice_type.h:102
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice_type.h:81
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:123
void set_byte_count(int64_t byte_count)
Definition: proto_buffer_writer.h:203
friend class internal::ProtoBufferWriterPeer
Definition: proto_buffer_writer.h:207
#define GRPC_SLICE_INLINED_SIZE
Definition: slice_type.h:47
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).