19 #ifndef GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_WRITER_H 20 #define GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_WRITER_H 22 #include <type_traits> 41 class ProtoBufferWriterPeer;
61 : block_size_(block_size),
62 total_size_(total_size),
68 g_core_codegen_interface->grpc_raw_byte_buffer_create(NULL, 0);
69 byte_buffer->set_buffer(bp);
70 slice_buffer_ = &bp->data.raw.slice_buffer;
75 g_core_codegen_interface->grpc_slice_unref(backup_slice_);
81 bool Next(
void** data,
int* size)
override {
89 size_t remain = total_size_ - byte_count_;
92 slice_ = backup_slice_;
100 size_t allocate_length =
101 remain >
static_cast<size_t>(block_size_) ? block_size_ : remain;
102 slice_ = g_core_codegen_interface->grpc_slice_malloc(
111 g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_);
124 g_core_codegen_interface->grpc_slice_buffer_pop(slice_buffer_);
126 backup_slice_ = slice_;
128 backup_slice_ = g_core_codegen_interface->grpc_slice_split_tail(
130 g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_);
136 have_backup_ = backup_slice_.refcount != NULL;
137 byte_count_ -= count;
153 friend class internal::ProtoBufferWriterPeer;
154 const int block_size_;
155 const int total_size_;
167 #endif // GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_WRITER_H grpc_slice_buffer * slice_buffer()
Definition: proto_buffer_writer.h:148
#define GRPC_SLICE_SET_LENGTH(slice, newlen)
Definition: slice.h:122
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:138
This is a specialization of the protobuf class ZeroCopyOutputStream.
Definition: proto_buffer_writer.h:53
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1]. ...
Definition: slice.h:80
Definition: grpc_types.h:40
~ProtoBufferWriter()
Definition: proto_buffer_writer.h:73
#define GRPC_SLICE_START_PTR(slice)
Definition: slice.h:116
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice.h:98
const int kProtoBufferWriterMaxBufferLength
Definition: proto_buffer_writer.h:44
bool Valid() const
Is this ByteBuffer valid?
Definition: byte_buffer.h:133
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:118
ProtoBufferWriter(ByteBuffer *byte_buffer, int block_size, int total_size)
Constructor for this derived class.
Definition: proto_buffer_writer.h:60
#define GRPC_SLICE_INLINED_SIZE
Definition: slice.h:68
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
CoreCodegenInterface * g_core_codegen_interface
Definition: call.h:46
::google::protobuf::int64 int64
Definition: config_protobuf.h:73
bool Next(void **data, int *size) override
Give the proto library the next buffer of bytes and its size.
Definition: proto_buffer_writer.h:81
grpc::protobuf::int64 ByteCount() const override
Returns the total number of bytes written since this object was created.
Definition: proto_buffer_writer.h:141
::google::protobuf::io::ZeroCopyOutputStream ZeroCopyOutputStream
Definition: config_protobuf.h:87
#define GRPC_SLICE_LENGTH(slice)
Definition: slice.h:119
A sequence of bytes.
Definition: byte_buffer.h:53
void set_byte_count(int64_t byte_count)
Definition: proto_buffer_writer.h:149