byte_buffer_cc.cc
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 #include <vector>
20 
21 #include <grpc/byte_buffer.h>
25 #include <grpc/slice.h>
28 #include <grpcpp/support/slice.h>
29 #include <grpcpp/support/status.h>
30 
31 namespace grpc {
32 
34 
36  if (!buffer_) {
37  return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized");
38  }
39  if ((buffer_->type == GRPC_BB_RAW) &&
41  (buffer_->data.raw.slice_buffer.count == 1)) {
42  grpc_slice internal_slice = buffer_->data.raw.slice_buffer.slices[0];
43  *slice = Slice(internal_slice, Slice::ADD_REF);
44  return Status::OK;
45  } else {
47  "Buffer isn't made up of a single uncompressed slice.");
48  }
49 }
50 
52  if (!buffer_) {
53  return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized");
54  }
58  "Couldn't initialize byte buffer reader");
59  }
63  return Status::OK;
64 }
65 
66 Status ByteBuffer::Dump(std::vector<Slice>* slices) const {
67  slices->clear();
68  if (!buffer_) {
69  return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized");
70  }
74  "Couldn't initialize byte buffer reader");
75  }
76  grpc_slice s;
77  while (grpc_byte_buffer_reader_next(&reader, &s)) {
78  slices->push_back(Slice(s, Slice::STEAL_REF));
79  }
81  return Status::OK;
82 }
83 
84 } // namespace grpc
grpc::ByteBuffer::buffer_
grpc_byte_buffer * buffer_
Definition: include/grpcpp/impl/codegen/byte_buffer.h:191
grpc
Definition: grpcpp/alarm.h:33
slice.h
grpc_byte_buffer::grpc_byte_buffer_data::raw
struct grpc_byte_buffer::grpc_byte_buffer_data::grpc_compressed_buffer raw
grpc_byte_buffer_reader_readall
GRPCAPI grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader)
Definition: byte_buffer_reader.cc:84
grpc::g_gli_initializer
static grpc::internal::GrpcLibraryInitializer g_gli_initializer
Definition: channel_cc.cc:52
grpc_slice_buffer::slices
grpc_slice * slices
Definition: include/grpc/impl/codegen/slice.h:89
slice.h
grpc::ByteBuffer::TrySingleSlice
Status TrySingleSlice(Slice *slice) const
Definition: byte_buffer_cc.cc:35
grpc_byte_buffer_reader_next
GRPCAPI int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, grpc_slice *slice)
Definition: byte_buffer_reader.cc:66
GRPC_COMPRESS_NONE
@ GRPC_COMPRESS_NONE
Definition: compression_types.h:61
grpc::Slice::ADD_REF
@ ADD_REF
Definition: include/grpcpp/impl/codegen/slice.h:43
GRPC_BB_RAW
@ GRPC_BB_RAW
Definition: grpc_types.h:39
grpc.StatusCode.FAILED_PRECONDITION
tuple FAILED_PRECONDITION
Definition: src/python/grpcio/grpc/__init__.py:272
grpc::Slice::STEAL_REF
@ STEAL_REF
Definition: include/grpcpp/impl/codegen/slice.h:48
grpc_byte_buffer::type
grpc_byte_buffer_type type
Definition: grpc_types.h:45
byte_buffer_reader.h
grpc_types.h
grpc::internal::GrpcLibraryInitializer
Instantiating this class ensures the proper initialization of gRPC.
Definition: grpcpp/impl/grpc_library.h:39
grpc_slice_buffer::count
size_t count
Definition: include/grpc/impl/codegen/slice.h:91
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
grpc_byte_buffer_reader_init
GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, grpc_byte_buffer *buffer)
Definition: byte_buffer_reader.cc:33
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc::Status::OK
static const Status & OK
An OK pre-defined instance.
Definition: include/grpcpp/impl/codegen/status.h:113
grpc::ByteBuffer::Dump
Status Dump(std::vector< Slice > *slices) const
Dump (read) the buffer contents into slices.
Definition: byte_buffer_cc.cc:66
grpc::ByteBuffer::DumpToSingleSlice
Status DumpToSingleSlice(Slice *slice) const
Dump (read) the buffer contents into slics.
Definition: byte_buffer_cc.cc:51
grpc_byte_buffer::data
union grpc_byte_buffer::grpc_byte_buffer_data data
compression_types.h
grpc_library.h
grpc_byte_buffer::grpc_byte_buffer_data::grpc_compressed_buffer::compression
grpc_compression_algorithm compression
Definition: grpc_types.h:51
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
slices
SliceBuffer * slices
Definition: retry_filter.cc:631
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc_byte_buffer::grpc_byte_buffer_data::grpc_compressed_buffer::slice_buffer
grpc_slice_buffer slice_buffer
Definition: grpc_types.h:52
grpc::Slice
Definition: include/grpcpp/impl/codegen/slice.h:36
grpc.StatusCode.INTERNAL
tuple INTERNAL
Definition: src/python/grpcio/grpc/__init__.py:277
grpc_byte_buffer_reader
Definition: impl/codegen/byte_buffer_reader.h:30
reader
void reader(void *n)
Definition: libuv/docs/code/locks/main.c:8
grpc_byte_buffer_reader_destroy
GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader)
Definition: byte_buffer_reader.cc:45
status.h
byte_buffer.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:41