19 #ifndef GRPCPP_IMPL_CODEGEN_PROTO_UTILS_H 20 #define GRPCPP_IMPL_CODEGEN_PROTO_UTILS_H 22 #include <type_traits> 38 class GrpcBufferWriterPeer;
49 *bp = g_core_codegen_interface->grpc_raw_byte_buffer_create(NULL, 0);
59 bool Next(
void** data,
int* size)
override {
72 size_t allocate_length =
74 slice_ = g_core_codegen_interface->grpc_slice_malloc(
88 g_core_codegen_interface->grpc_slice_buffer_pop(
slice_buffer_);
92 backup_slice_ = g_core_codegen_interface->grpc_slice_split_tail(
121 if (!g_core_codegen_interface->grpc_byte_buffer_reader_init(&reader_,
124 "Couldn't initialize byte buffer reader");
128 g_core_codegen_interface->grpc_byte_buffer_reader_destroy(&reader_);
131 bool Next(
const void** data,
int* size)
override {
135 if (backup_count_ > 0) {
139 *size = (int)backup_count_;
143 if (!g_core_codegen_interface->grpc_byte_buffer_reader_next(&reader_,
147 g_core_codegen_interface->grpc_slice_unref(
slice_);
157 void BackUp(
int count)
override { backup_count_ = count; }
159 bool Skip(
int count)
override {
162 while (
Next(&data, &size)) {
187 template <
class BufferWriter,
class T>
191 std::is_base_of<protobuf::io::ZeroCopyOutputStream, BufferWriter>::value,
192 "BufferWriter must be a subclass of io::ZeroCopyOutputStream");
194 int byte_size = msg.ByteSize();
196 grpc_slice slice = g_core_codegen_interface->grpc_slice_malloc(byte_size);
200 *bp = g_core_codegen_interface->grpc_raw_byte_buffer_create(&slice, 1);
201 g_core_codegen_interface->grpc_slice_unref(slice);
203 return g_core_codegen_interface->ok();
205 BufferWriter writer(bp, kGrpcBufferWriterMaxBufferLength, byte_size);
206 return msg.SerializeToZeroCopyStream(&writer)
207 ? g_core_codegen_interface->ok()
212 template <
class BufferReader,
class T>
216 std::is_base_of<protobuf::io::ZeroCopyInputStream, BufferReader>::value,
217 "BufferReader must be a subclass of io::ZeroCopyInputStream");
218 if (buffer ==
nullptr) {
221 Status result = g_core_codegen_interface->
ok();
223 BufferReader reader(buffer);
224 if (!reader.status().ok()) {
225 return reader.status();
228 decoder.SetTotalBytesLimit(INT_MAX, INT_MAX);
229 if (!msg->ParseFromCodedStream(&decoder)) {
232 if (!decoder.ConsumedEntireMessage()) {
236 g_core_codegen_interface->grpc_byte_buffer_destroy(buffer);
244 #ifdef GRPC_OPEN_SOURCE_PROTO 250 grpc::protobuf::Message, T>::value>::type> {
254 return internal::GenericSerialize<internal::GrpcBufferWriter, T>(
255 msg, bp, own_buffer);
260 return internal::GenericDeserialize<internal::GrpcBufferReader, T>(buffer,
268 #endif // GRPCPP_IMPL_CODEGEN_PROTO_UTILS_H Status GenericDeserialize(grpc_byte_buffer *buffer, grpc::protobuf::Message *msg)
Definition: proto_utils.h:213
#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:133
Definition: proto_utils.h:117
~GrpcBufferWriter() override
Definition: proto_utils.h:53
Status status_
Definition: proto_utils.h:183
int64_t byte_count_
Definition: proto_utils.h:110
grpc::protobuf::int64 ByteCount() const override
Definition: proto_utils.h:174
const int kGrpcBufferWriterMaxBufferLength
Definition: proto_utils.h:40
Status GenericSerialize(const grpc::protobuf::Message &msg, grpc_byte_buffer **bp, bool *own_buffer)
Definition: proto_utils.h:188
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1]. ...
Definition: slice.h:80
~GrpcBufferReader() override
Definition: proto_utils.h:127
int64_t byte_count_
Definition: proto_utils.h:179
bool Next(const void **data, int *size) override
Definition: proto_utils.h:131
const int total_size_
Definition: proto_utils.h:109
Definition: grpc_types.h:40
grpc_slice backup_slice_
Definition: proto_utils.h:113
#define GRPC_SLICE_START_PTR(slice)
Definition: slice.h:116
bool Skip(int count) override
Definition: proto_utils.h:159
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice.h:98
#define GRPC_SLICE_END_PTR(slice)
Definition: slice.h:125
void BackUp(int count) override
Definition: proto_utils.h:157
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
#define GRPC_SLICE_INLINED_SIZE
Definition: slice.h:68
GrpcBufferWriter(grpc_byte_buffer **bp, int block_size, int total_size)
Definition: proto_utils.h:44
::google::protobuf::io::ZeroCopyInputStream ZeroCopyInputStream
Definition: config_protobuf.h:88
struct grpc_slice_refcount * refcount
Definition: slice.h:81
void BackUp(int count) override
Definition: proto_utils.h:87
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
grpc_slice slice_
Definition: proto_utils.h:182
const int block_size_
Definition: proto_utils.h:108
CoreCodegenInterface * g_core_codegen_interface
Definition: call.h:46
Definition: proto_utils.h:42
bool have_backup_
Definition: proto_utils.h:112
friend class GrpcBufferWriterPeer
Definition: proto_utils.h:107
::google::protobuf::int64 int64
Definition: config_protobuf.h:73
grpc_slice slice_
Definition: proto_utils.h:114
Status status() const
Definition: proto_utils.h:155
bool ok() const
Is the status OK?
Definition: status.h:118
grpc::protobuf::int64 ByteCount() const override
Definition: proto_utils.h:104
bool Next(void **data, int *size) override
Definition: proto_utils.h:59
Did it work? If it didn't, why?
Definition: status.h:31
grpc_slice_buffer * slice_buffer_
Definition: proto_utils.h:111
int64_t backup_count_
Definition: proto_utils.h:180
::google::protobuf::io::ZeroCopyOutputStream ZeroCopyOutputStream
Definition: config_protobuf.h:87
#define GRPC_SLICE_LENGTH(slice)
Definition: slice.h:119
GrpcBufferReader(grpc_byte_buffer *buffer)
Definition: proto_utils.h:119
Definition: byte_buffer_reader.h:28
Internal errors.
Definition: status_code_enum.h:119
grpc_byte_buffer_reader reader_
Definition: proto_utils.h:181
::google::protobuf::Message Message
Definition: config_protobuf.h:72
::google::protobuf::io::CodedInputStream CodedInputStream
Definition: config_protobuf.h:89