impl/codegen/proto_buffer_reader.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_READER_H
20 #define GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_READER_H
21 
22 // IWYU pragma: private, include <grpcpp/support/proto_buffer_reader.h>
23 
24 #include <type_traits>
25 
34 
37 
38 namespace grpc {
39 
40 extern CoreCodegenInterface* g_core_codegen_interface;
41 
49  public:
53  : byte_count_(0), backup_count_(0), status_() {
56  if (!buffer->Valid() ||
58  &reader_, buffer->c_buffer())) {
60  "Couldn't initialize byte buffer reader");
61  }
62  }
63 
64  ~ProtoBufferReader() override {
65  if (status_.ok()) {
67  }
68  }
69 
72  bool Next(const void** data, int* size) override {
73  if (!status_.ok()) {
74  return false;
75  }
77  if (backup_count_ > 0) {
81  *size = static_cast<int>(backup_count_);
82  backup_count_ = 0;
83  return true;
84  }
87  &slice_)) {
88  return false;
89  }
91  // On win x64, int is only 32bit
93  byte_count_ += * size = static_cast<int>(GRPC_SLICE_LENGTH(*slice_));
94  return true;
95  }
96 
98  Status status() const { return status_; }
99 
103  void BackUp(int count) override {
104  GPR_CODEGEN_ASSERT(count <= static_cast<int>(GRPC_SLICE_LENGTH(*slice_)));
106  }
107 
110  bool Skip(int count) override {
111  const void* data;
112  int size;
113  while (Next(&data, &size)) {
114  if (size >= count) {
115  BackUp(size - count);
116  return true;
117  }
118  // size < count;
119  count -= size;
120  }
121  // error or we have too large count;
122  return false;
123  }
124 
126  int64_t ByteCount() const override { return byte_count_ - backup_count_; }
127 
128  // These protected members are needed to support internal optimizations.
129  // they expose internal bits of grpc core that are NOT stable. If you have
130  // a use case needs to use one of these functions, please send an email to
131  // https://groups.google.com/forum/#!forum/grpc-io.
132  protected:
133  void set_byte_count(int64_t byte_count) { byte_count_ = byte_count; }
137  grpc_slice* slice() { return slice_; }
139 
140  private:
144  grpc_slice* slice_;
147 };
148 
149 } // namespace grpc
150 
151 #endif // GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_READER_H
grpc
Definition: grpcpp/alarm.h:33
byte_buffer_reader.h
grpc::Status::ok
bool ok() const
Is the status OK?
Definition: include/grpcpp/impl/codegen/status.h:126
grpc::protobuf::io::ZeroCopyInputStream
GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream
Definition: include/grpcpp/impl/codegen/config_protobuf.h:101
serialization_traits.h
grpc::ProtoBufferReader::set_byte_count
void set_byte_count(int64_t byte_count)
Definition: impl/codegen/proto_buffer_reader.h:133
grpc::ProtoBufferReader::backup_count_
int64_t backup_count_
how far backed up in the stream we are
Definition: impl/codegen/proto_buffer_reader.h:142
core_codegen_interface.h
slice.h
grpc::ProtoBufferReader::Skip
bool Skip(int count) override
Definition: impl/codegen/proto_buffer_reader.h:110
grpc_types.h
grpc::ProtoBufferReader::status_
Status status_
status of the entire object
Definition: impl/codegen/proto_buffer_reader.h:146
grpc::g_core_codegen_interface
CoreCodegenInterface * g_core_codegen_interface
Definition: include/grpcpp/impl/codegen/completion_queue.h:98
grpc::ProtoBufferReader::slice_
grpc_slice * slice_
current slice passed back to the caller
Definition: impl/codegen/proto_buffer_reader.h:145
grpc::ProtoBufferReader
Definition: impl/codegen/proto_buffer_reader.h:48
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
grpc::CoreCodegenInterface::grpc_byte_buffer_reader_peek
virtual int grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader *reader, grpc_slice **slice)=0
grpc::ProtoBufferReader::reader_
grpc_byte_buffer_reader reader_
Definition: impl/codegen/proto_buffer_reader.h:143
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
grpc::ProtoBufferReader::slice
grpc_slice * slice()
Definition: impl/codegen/proto_buffer_reader.h:137
grpc::ProtoBufferReader::backup_count
int64_t backup_count()
Definition: impl/codegen/proto_buffer_reader.h:134
grpc::ProtoBufferReader::status
Status status() const
Returns the status of the buffer reader.
Definition: impl/codegen/proto_buffer_reader.h:98
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc::ByteBuffer
A sequence of bytes.
Definition: include/grpcpp/impl/codegen/byte_buffer.h:61
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
byte_buffer.h
grpc::ProtoBufferReader::reader
grpc_byte_buffer_reader * reader()
Definition: impl/codegen/proto_buffer_reader.h:136
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
grpc::ProtoBufferReader::mutable_slice_ptr
grpc_slice ** mutable_slice_ptr()
Definition: impl/codegen/proto_buffer_reader.h:138
GRPC_SLICE_LENGTH
#define GRPC_SLICE_LENGTH(slice)
Definition: include/grpc/impl/codegen/slice.h:104
status.h
grpc::ProtoBufferReader::BackUp
void BackUp(int count) override
Definition: impl/codegen/proto_buffer_reader.h:103
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
config_protobuf.h
grpc::ProtoBufferReader::set_backup_count
void set_backup_count(int64_t backup_count)
Definition: impl/codegen/proto_buffer_reader.h:135
grpc::ProtoBufferReader::Next
bool Next(const void **data, int *size) override
Definition: impl/codegen/proto_buffer_reader.h:72
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::ProtoBufferReader::~ProtoBufferReader
~ProtoBufferReader() override
Definition: impl/codegen/proto_buffer_reader.h:64
GPR_CODEGEN_ASSERT
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: grpcpp/impl/codegen/core_codegen_interface.h:151
grpc::CoreCodegenInterface::grpc_byte_buffer_reader_init
virtual int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, grpc_byte_buffer *buffer) GRPC_MUST_USE_RESULT=0
grpc::ProtoBufferReader::ByteCount
int64_t ByteCount() const override
Returns the total number of bytes read since this object was created.
Definition: impl/codegen/proto_buffer_reader.h:126
grpc::ProtoBufferReader::ProtoBufferReader
ProtoBufferReader(ByteBuffer *buffer)
Definition: impl/codegen/proto_buffer_reader.h:52
grpc.StatusCode.INTERNAL
tuple INTERNAL
Definition: src/python/grpcio/grpc/__init__.py:277
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
grpc::CoreCodegenInterface::grpc_byte_buffer_reader_destroy
virtual void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader)=0
grpc::ProtoBufferReader::byte_count_
int64_t byte_count_
total bytes read since object creation
Definition: impl/codegen/proto_buffer_reader.h:141
grpc_byte_buffer_reader
Definition: impl/codegen/byte_buffer_reader.h:30


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:56