Go to the documentation of this file.
15 #ifndef GRPCPP_IMPL_GENERIC_SERIALIZE_H
16 #define GRPCPP_IMPL_GENERIC_SERIALIZE_H
31 #include <type_traits>
33 #include "absl/log/absl_check.h"
34 #include "absl/strings/str_cat.h"
42 template <
class ProtoBufferWriter,
class T>
47 "ProtoBufferWriter must be a subclass of "
48 "::protobuf::io::ZeroCopyOutputStream");
50 size_t byte_size = msg.ByteSizeLong();
51 if (byte_size > std::numeric_limits<int>::max()) {
53 "Protobuf is too large to be serialized",
54 absl::StrCat(byte_size,
" bytes is beyond the limit 2^31-1"));
57 Slice slice(byte_size);
59 ABSL_CHECK(slice.
end() == msg.SerializeWithCachedSizesToArray(
60 const_cast<uint8_t*
>(slice.
begin())));
67 static_cast<int>(byte_size));
69 msg.SerializeWithCachedSizes(&cs);
76 template <
class ProtoBufferReader,
class T>
81 "ProtoBufferReader must be a subclass of "
82 "::protobuf::io::ZeroCopyInputStream");
83 if (buffer ==
nullptr) {
92 if (!msg->ParseFromZeroCopyStream(&reader)) {
102 #endif // GRPCPP_IMPL_GENERIC_SERIALIZE_H
This is a specialization of the protobuf class ZeroCopyOutputStream.
Definition: proto_buffer_writer.h:55
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
const uint8_t * begin() const
Raw pointer to the beginning (first element) of the slice.
Definition: slice.h:102
::google::protobuf::io::ZeroCopyInputStream ZeroCopyInputStream
Definition: config_protobuf.h:115
bool ok() const
Is the status OK?
Definition: status.h:125
const uint8_t * end() const
Raw pointer to the end (one byte past the last element) of the slice.
Definition: slice.h:105
Status GenericSerialize(const grpc::protobuf::MessageLite &msg, ByteBuffer *bb, bool *own_buffer)
Definition: generic_serialize.h:43
Did it work? If it didn't, why?
Definition: status.h:34
void Clear()
Remove all data.
Definition: byte_buffer.h:127
A sequence of bytes.
Definition: byte_buffer.h:59
void Swap(ByteBuffer *other)
Swap the state of *this and *other.
Definition: byte_buffer.h:151
This is a specialization of the protobuf class ZeroCopyInputStream The principle is to get one chunk ...
Definition: proto_buffer_reader.h:47
Status GenericDeserialize(ByteBuffer *buffer, grpc::protobuf::MessageLite *msg)
Definition: generic_serialize.h:77
const int kProtoBufferWriterMaxBufferLength
Definition: proto_buffer_writer.h:46
A wrapper around grpc_slice.
Definition: slice.h:33
::google::protobuf::io::CodedOutputStream CodedOutputStream
Definition: config_protobuf.h:117
Status status() const
Returns the status of the buffer reader.
Definition: proto_buffer_reader.h:95
static const Status & OK
An OK pre-defined instance.
Definition: status.h:112
::absl::Status Status
Definition: config_protobuf.h:107
#define GRPC_SLICE_INLINED_SIZE
Definition: slice_type.h:46
::google::protobuf::MessageLite MessageLite
Definition: config_protobuf.h:90
@ INTERNAL
Internal errors.
Definition: status_code_enum.h:121