19 #ifndef GRPCXX_IMPL_CODEGEN_PROTO_UTILS_H
20 #define GRPCXX_IMPL_CODEGEN_PROTO_UTILS_H
22 #include <type_traits>
38 class GrpcBufferWriterPeer;
46 : block_size_(block_size), byte_count_(0), have_backup_(false) {
48 slice_buffer_ = &(*bp)->data.raw.slice_buffer;
57 bool Next(
void** data,
int* size)
override {
59 slice_ = backup_slice_;
74 if (count == block_size_) {
75 backup_slice_ = slice_;
85 have_backup_ = backup_slice_.
refcount != NULL;
93 const int block_size_;
105 : byte_count_(0), backup_count_(0), status_() {
109 "Couldn't initialize byte buffer reader");
116 bool Next(
const void** data,
int* size)
override {
120 if (backup_count_ > 0) {
124 *size = (int)backup_count_;
142 void BackUp(
int count)
override { backup_count_ = count; }
144 bool Skip(
int count)
override {
147 while (
Next(&data, &size)) {
160 return byte_count_ - backup_count_;
165 int64_t backup_count_;
175 grpc::protobuf::Message, T>::value>::type> {
180 int byte_size = msg.ByteSize();
192 return msg.SerializeToZeroCopyStream(&writer)
200 if (buffer ==
nullptr) {
210 decoder.SetTotalBytesLimit(INT_MAX, INT_MAX);
211 if (!msg->ParseFromCodedStream(&decoder)) {
214 if (!decoder.ConsumedEntireMessage()) {
225 #endif // GRPCXX_IMPL_CODEGEN_PROTO_UTILS_H
virtual void grpc_slice_buffer_pop(grpc_slice_buffer *sb)=0
virtual grpc_slice grpc_slice_malloc(size_t length)=0
Definition: proto_utils.h:101
~GrpcBufferWriter() override
Definition: proto_utils.h:51
virtual void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader)=0
grpc::protobuf::int64 ByteCount() const override
Definition: proto_utils.h:159
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:126
const int kGrpcBufferWriterMaxBufferLength
Definition: proto_utils.h:40
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1]. ...
Definition: slice.h:76
~GrpcBufferReader() override
Definition: proto_utils.h:112
bool Next(const void **data, int *size) override
Definition: proto_utils.h:116
Definition: grpc_types.h:41
#define GRPC_SLICE_START_PTR(slice)
Definition: slice.h:112
bool Skip(int count) override
Definition: proto_utils.h:144
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice.h:94
#define GRPC_SLICE_END_PTR(slice)
Definition: slice.h:121
void BackUp(int count) override
Definition: proto_utils.h:142
static Status Deserialize(grpc_byte_buffer *buffer, grpc::protobuf::Message *msg)
Definition: proto_utils.h:198
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)=0
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:49
::google::protobuf::io::ZeroCopyInputStream ZeroCopyInputStream
Definition: config_protobuf.h:86
static Status Serialize(const grpc::protobuf::Message &msg, grpc_byte_buffer **bp, bool *own_buffer)
Definition: proto_utils.h:177
struct grpc_slice_refcount * refcount
Definition: slice.h:77
void BackUp(int count) override
Definition: proto_utils.h:72
CoreCodegenInterface * g_core_codegen_interface
Definition: call.h:49
virtual grpc_byte_buffer * grpc_raw_byte_buffer_create(grpc_slice *slice, size_t nslices)=0
GrpcBufferWriter(grpc_byte_buffer **bp, int block_size)
Definition: proto_utils.h:45
Definition: proto_utils.h:42
friend class GrpcBufferWriterPeer
Definition: proto_utils.h:92
::google::protobuf::int64 int64
Definition: config_protobuf.h:71
virtual grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split)=0
grpc::protobuf::int64 ByteCount() const override
Definition: proto_utils.h:89
virtual void grpc_slice_unref(grpc_slice slice)=0
bool Next(void **data, int *size) override
Definition: proto_utils.h:57
virtual void grpc_slice_buffer_add(grpc_slice_buffer *sb, grpc_slice slice)=0
bool ok() const
Is the status OK?
Definition: status.h:64
Did it work? If it didn't, why?
Definition: status.h:30
virtual const Status & ok()=0
virtual int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, grpc_slice *slice)=0
::google::protobuf::io::ZeroCopyOutputStream ZeroCopyOutputStream
Definition: config_protobuf.h:85
#define GRPC_SLICE_LENGTH(slice)
Definition: slice.h:115
GrpcBufferReader(grpc_byte_buffer *buffer)
Definition: proto_utils.h:104
Definition: byte_buffer_reader.h:28
virtual int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, grpc_byte_buffer *buffer) GRPC_MUST_USE_RESULT=0
Internal errors.
Definition: status_code_enum.h:119
Status status() const
Definition: proto_utils.h:140
::google::protobuf::Message Message
Definition: config_protobuf.h:70
::google::protobuf::io::CodedInputStream CodedInputStream
Definition: config_protobuf.h:87