Go to the documentation of this file.
19 #ifndef GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
20 #define GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
31 #include <type_traits>
33 #include "absl/log/absl_check.h"
34 #include "absl/strings/cord.h"
52 : byte_count_(0), backup_count_(0), status_() {
55 if (!buffer->
Valid() ||
58 "Couldn't initialize byte buffer reader");
70 bool Next(
const void** data,
int* size)
override {
75 if (backup_count_ > 0) {
78 ABSL_CHECK_LE(backup_count_, INT_MAX);
79 *size =
static_cast<int>(backup_count_);
102 backup_count_ = count;
107 bool Skip(
int count)
override {
110 while (
Next(&data, &size)) {
123 int64_t
ByteCount()
const override {
return byte_count_ - backup_count_; }
125 #ifdef GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
131 virtual bool ReadCord(absl::Cord* cord,
int count)
132 #if GOOGLE_PROTOBUF_VERSION >= 4022000
151 int64_t take = (std::min)(
backup_count(),
static_cast<int64_t
>(count));
156 count -=
static_cast<int>(take);
167 if (slice_length <=
static_cast<uint64_t
>(count)) {
170 count -=
static_cast<int>(slice_length);
177 ABSL_CHECK_EQ(count, 0);
180 #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
195 #ifdef GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
201 *slice_for_cord =
slice;
202 return absl::MakeCordFromExternal(
206 [slice_for_cord](absl::string_view ) {
208 delete slice_for_cord;
211 #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
214 int64_t backup_count_;
223 #endif // GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
#define GRPC_SLICE_START_PTR(slice)
Definition: slice_type.h:98
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
~ProtoBufferReader() override
Definition: proto_buffer_reader.h:62
ProtoBufferReader(ByteBuffer *buffer)
Constructs buffer reader from buffer.
Definition: proto_buffer_reader.h:51
::google::protobuf::io::ZeroCopyInputStream ZeroCopyInputStream
Definition: config_protobuf.h:115
int64_t backup_count()
Definition: proto_buffer_reader.h:188
bool ok() const
Is the status OK?
Definition: status.h:125
void BackUp(int count) override
The proto library calls this to indicate that we should back up count bytes that have already been re...
Definition: proto_buffer_reader.h:100
struct grpc_slice grpc_slice
Definition: slice_type.h:27
GPRAPI grpc_slice grpc_slice_ref(grpc_slice s)
Increment the refcount of s.
Did it work? If it didn't, why?
Definition: status.h:34
grpc_byte_buffer_reader * reader()
Definition: proto_buffer_reader.h:190
int64_t ByteCount() const override
Returns the total number of bytes read since this object was created.
Definition: proto_buffer_reader.h:123
bool Skip(int count) override
The proto library calls this to skip over count bytes.
Definition: proto_buffer_reader.h:107
A sequence of bytes.
Definition: byte_buffer.h:59
This is a specialization of the protobuf class ZeroCopyInputStream The principle is to get one chunk ...
Definition: proto_buffer_reader.h:47
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice_type.h:62
void set_byte_count(int64_t byte_count)
Definition: proto_buffer_reader.h:187
GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader)
Cleanup and destroy reader.
grpc_slice ** mutable_slice_ptr()
Definition: proto_buffer_reader.h:192
GPRAPI grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end)
Return a result slice derived from s, which shares a ref count with s, where result....
GPRAPI grpc_slice grpc_slice_split_head(grpc_slice *s, size_t split)
Splits s into two: modifies s to be s[split:s.length], and returns a new slice, sharing a refcount wi...
Status status() const
Returns the status of the buffer reader.
Definition: proto_buffer_reader.h:95
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,...
GRPCAPI int grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader *reader, grpc_slice **slice)
EXPERIMENTAL API - This function may be removed and changed, in the future.
GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, grpc_byte_buffer *buffer)
Initialize reader to read over buffer.
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:158
#define GRPC_SLICE_LENGTH(slice)
Definition: slice_type.h:101
::absl::Status Status
Definition: config_protobuf.h:107
grpc_slice * slice()
Definition: proto_buffer_reader.h:191
Definition: byte_buffer_reader.h:30
bool Next(const void **data, int *size) override
Give the proto library a chunk of data from the stream.
Definition: proto_buffer_reader.h:70
void set_backup_count(int64_t backup_count)
Definition: proto_buffer_reader.h:189
@ INTERNAL
Internal errors.
Definition: status_code_enum.h:121