Go to the documentation of this file.
19 #ifndef GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
20 #define GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
22 #include <type_traits>
24 #include "absl/log/absl_check.h"
25 #include "absl/strings/cord.h"
53 : byte_count_(0), backup_count_(0), status_() {
56 if (!buffer->
Valid() ||
59 "Couldn't initialize byte buffer reader");
71 bool Next(
const void** data,
int* size)
override {
76 if (backup_count_ > 0) {
79 ABSL_CHECK_LE(backup_count_, INT_MAX);
80 *size =
static_cast<int>(backup_count_);
103 backup_count_ = count;
108 bool Skip(
int count)
override {
111 while (
Next(&data, &size)) {
124 int64_t
ByteCount()
const override {
return byte_count_ - backup_count_; }
126 #ifdef GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
132 virtual bool ReadCord(absl::Cord* cord,
int count)
133 #if GOOGLE_PROTOBUF_VERSION >= 4022000
152 int64_t take = (std::min)(
backup_count(),
static_cast<int64_t
>(count));
157 count -=
static_cast<int>(take);
168 if (slice_length <=
static_cast<uint64_t
>(count)) {
171 count -=
static_cast<int>(slice_length);
178 ABSL_CHECK_EQ(count, 0);
181 #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
196 #ifdef GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
202 *slice_for_cord =
slice;
203 return absl::MakeCordFromExternal(
207 [slice_for_cord](absl::string_view ) {
209 delete slice_for_cord;
212 #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED
215 int64_t backup_count_;
224 #endif // GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
#define GRPC_SLICE_START_PTR(slice)
Definition: slice_type.h:99
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:63
ProtoBufferReader(ByteBuffer *buffer)
Constructs buffer reader from buffer.
Definition: proto_buffer_reader.h:52
::google::protobuf::io::ZeroCopyInputStream ZeroCopyInputStream
Definition: config_protobuf.h:114
int64_t backup_count()
Definition: proto_buffer_reader.h:189
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:101
struct grpc_slice grpc_slice
Definition: slice_type.h:28
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:191
int64_t ByteCount() const override
Returns the total number of bytes read since this object was created.
Definition: proto_buffer_reader.h:124
bool Skip(int count) override
The proto library calls this to skip over count bytes.
Definition: proto_buffer_reader.h:108
A sequence of bytes.
Definition: byte_buffer.h:60
This is a specialization of the protobuf class ZeroCopyInputStream The principle is to get one chunk ...
Definition: proto_buffer_reader.h:48
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice_type.h:63
void set_byte_count(int64_t byte_count)
Definition: proto_buffer_reader.h:188
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:193
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:96
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:159
#define GRPC_SLICE_LENGTH(slice)
Definition: slice_type.h:102
::absl::Status Status
Definition: config_protobuf.h:106
grpc_slice * slice()
Definition: proto_buffer_reader.h:192
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:71
void set_backup_count(int64_t backup_count)
Definition: proto_buffer_reader.h:190
@ INTERNAL
Internal errors.
Definition: status_code_enum.h:121