include/grpcpp/impl/codegen/slice.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_SLICE_H
20 #define GRPCPP_IMPL_CODEGEN_SLICE_H
21 
22 // IWYU pragma: private, include <grpcpp/support/slice.h>
23 
28 
29 namespace grpc {
30 
36 class Slice final {
37  public:
42 
43  enum AddRef { ADD_REF };
47 
48  enum StealRef { STEAL_REF };
51 
53  explicit Slice(size_t len)
55 
57  Slice(const void* buf, size_t len)
59  reinterpret_cast<const char*>(buf), len)) {}
60 
62  /* NOLINTNEXTLINE(google-explicit-constructor) */
65  str.c_str(), str.length())) {}
66 
68 
70  Slice(const void* buf, size_t len, StaticSlice)
72  reinterpret_cast<const char*>(buf), len)) {}
73 
75  Slice(const Slice& other)
77 
79  Slice(Slice&& other) noexcept : slice_(other.slice_) {
81  }
82 
84  Slice& operator=(Slice other) {
85  std::swap(slice_, other.slice_);
86  return *this;
87  }
88 
94  Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data)
96  buf, len, destroy, user_data)) {}
97 
99  Slice(void* buf, size_t len, void (*destroy)(void*))
100  : Slice(buf, len, destroy, buf) {}
101 
103  Slice(void* buf, size_t len, void (*destroy)(void*, size_t))
105  destroy)) {}
106 
108  size_t size() const { return GRPC_SLICE_LENGTH(slice_); }
109 
111  const uint8_t* begin() const { return GRPC_SLICE_START_PTR(slice_); }
112 
114  const uint8_t* end() const { return GRPC_SLICE_END_PTR(slice_); }
115 
117  Slice sub(size_t begin, size_t end) const {
119  STEAL_REF);
120  }
121 
123  grpc_slice c_slice() const {
125  }
126 
127  private:
128  friend class ByteBuffer;
129 
131 };
132 
134  return grpc::string_ref(
135  reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(*slice)),
137 }
138 
140  return std::string(reinterpret_cast<char*>(GRPC_SLICE_START_PTR(slice)),
142 }
143 
146  str.length());
147 }
148 
151  str.length());
152 }
153 
154 } // namespace grpc
155 
156 #endif // GRPCPP_IMPL_CODEGEN_SLICE_H
grpc::Slice::Slice
Slice(void *buf, size_t len, void(*destroy)(void *, size_t))
Similar to the above but has a destroy that also takes slice length.
Definition: include/grpcpp/impl/codegen/slice.h:103
xds_interop_client.str
str
Definition: xds_interop_client.py:487
grpc::StringRefFromSlice
grpc::string_ref StringRefFromSlice(const grpc_slice *slice)
Definition: include/grpcpp/impl/codegen/slice.h:133
grpc::string_ref
Definition: grpcpp/impl/codegen/string_ref.h:43
grpc::Slice::STATIC_SLICE
@ STATIC_SLICE
Definition: include/grpcpp/impl/codegen/slice.h:67
grpc::Slice::StaticSlice
StaticSlice
Definition: include/grpcpp/impl/codegen/slice.h:67
grpc::Slice::sub
Slice sub(size_t begin, size_t end) const
Returns a substring of the slice as another slice.
Definition: include/grpcpp/impl/codegen/slice.h:117
grpc::Slice::end
const uint8_t * end() const
Raw pointer to the end (one byte past the last element) of the slice.
Definition: include/grpcpp/impl/codegen/slice.h:114
const
#define const
Definition: bloaty/third_party/zlib/zconf.h:230
grpc::CoreCodegenInterface::grpc_slice_unref
virtual void grpc_slice_unref(grpc_slice slice)=0
grpc
Definition: grpcpp/alarm.h:33
grpc::Slice::Slice
Slice(Slice &&other) noexcept
Move constructor, steals a reference.
Definition: include/grpcpp/impl/codegen/slice.h:79
grpc::Slice::~Slice
~Slice()
Destructor - drops one reference.
Definition: include/grpcpp/impl/codegen/slice.h:41
grpc::Slice::Slice
Slice(grpc_slice slice, AddRef)
Construct a slice from slice, adding a reference.
Definition: include/grpcpp/impl/codegen/slice.h:45
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
grpc::SliceFromCopiedString
grpc_slice SliceFromCopiedString(const std::string &str)
Definition: include/grpcpp/impl/codegen/slice.h:149
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::CoreCodegenInterface::grpc_empty_slice
virtual grpc_slice grpc_empty_slice()=0
core_codegen_interface.h
slice.h
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_slice_malloc
GPRAPI grpc_slice grpc_slice_malloc(size_t length)
Definition: slice/slice.cc:227
grpc::Slice::ADD_REF
@ ADD_REF
Definition: include/grpcpp/impl/codegen/slice.h:43
config.h
grpc::CoreCodegenInterface::grpc_slice_ref
virtual grpc_slice grpc_slice_ref(grpc_slice slice)=0
grpc::Slice::STEAL_REF
@ STEAL_REF
Definition: include/grpcpp/impl/codegen/slice.h:48
grpc::g_core_codegen_interface
CoreCodegenInterface * g_core_codegen_interface
Definition: include/grpcpp/impl/codegen/completion_queue.h:98
grpc::Slice::Slice
Slice(const std::string &str)
Construct a slice from a copied string.
Definition: include/grpcpp/impl/codegen/slice.h:63
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
grpc::Slice::Slice
Slice(const Slice &other)
Copy constructor, adds a reference.
Definition: include/grpcpp/impl/codegen/slice.h:75
grpc::Slice::Slice
Slice(size_t len)
Allocate a slice of specified size.
Definition: include/grpcpp/impl/codegen/slice.h:53
grpc::Slice::slice_
grpc_slice slice_
Definition: include/grpcpp/impl/codegen/slice.h:130
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
grpc::Slice::Slice
Slice(void *buf, size_t len, void(*destroy)(void *))
Specialization of above for common case where buf == user_data.
Definition: include/grpcpp/impl/codegen/slice.h:99
grpc_slice_from_static_buffer
GPRAPI grpc_slice grpc_slice_from_static_buffer(const void *source, size_t len)
Definition: slice/slice.cc:85
grpc::CoreCodegenInterface::grpc_slice_from_copied_buffer
virtual grpc_slice grpc_slice_from_copied_buffer(const void *buffer, size_t length)=0
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
grpc::CoreCodegenInterface::grpc_slice_sub
virtual grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end)=0
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
grpc_empty_slice
GPRAPI grpc_slice grpc_empty_slice(void)
Definition: slice/slice.cc:42
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
grpc::Slice::StealRef
StealRef
Definition: include/grpcpp/impl/codegen/slice.h:48
GRPC_SLICE_END_PTR
#define GRPC_SLICE_END_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:110
grpc::Slice::begin
const uint8_t * begin() const
Raw pointer to the beginning (first element) of the slice.
Definition: include/grpcpp/impl/codegen/slice.h:111
grpc::Slice::size
size_t size() const
Byte size.
Definition: include/grpcpp/impl/codegen/slice.h:108
grpc::Slice::operator=
Slice & operator=(Slice other)
Assignment, reference count is unchanged.
Definition: include/grpcpp/impl/codegen/slice.h:84
GRPC_SLICE_LENGTH
#define GRPC_SLICE_LENGTH(slice)
Definition: include/grpc/impl/codegen/slice.h:104
grpc_slice_new_with_user_data
GPRAPI grpc_slice grpc_slice_new_with_user_data(void *p, size_t len, void(*destroy)(void *), void *user_data)
Definition: slice/slice.cc:93
grpc::CoreCodegenInterface::grpc_slice_from_static_buffer
virtual grpc_slice grpc_slice_from_static_buffer(const void *buffer, size_t length)=0
grpc::Slice::Slice
Slice()
Construct an empty slice.
Definition: include/grpcpp/impl/codegen/slice.h:39
string_ref.h
grpc_slice_from_copied_buffer
GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len)
Definition: slice/slice.cc:170
grpc::Slice::Slice
Slice(grpc_slice slice, StealRef)
Construct a slice from slice, stealing a reference.
Definition: include/grpcpp/impl/codegen/slice.h:50
grpc::Slice::c_slice
grpc_slice c_slice() const
Raw C slice. Caller needs to call grpc_slice_unref when done.
Definition: include/grpcpp/impl/codegen/slice.h:123
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
grpc::Slice::Slice
Slice(const void *buf, size_t len, StaticSlice)
Construct a slice from a static buffer.
Definition: include/grpcpp/impl/codegen/slice.h:70
grpc::Slice
Definition: include/grpcpp/impl/codegen/slice.h:36
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
grpc::Slice::AddRef
AddRef
Definition: include/grpcpp/impl/codegen/slice.h:43
grpc::Slice::Slice
Slice(const void *buf, size_t len)
Construct a slice from a copied buffer.
Definition: include/grpcpp/impl/codegen/slice.h:57
grpc::Slice::Slice
Slice(void *buf, size_t len, void(*destroy)(void *), void *user_data)
Definition: include/grpcpp/impl/codegen/slice.h:94
destroy
static std::function< void(void *, Slot *)> destroy
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:42
grpc_slice_new_with_len
GPRAPI grpc_slice grpc_slice_new_with_len(void *p, size_t len, void(*destroy)(void *, size_t))
Definition: slice/slice.cc:161
grpc::StringFromCopiedSlice
std::string StringFromCopiedSlice(grpc_slice slice)
Definition: include/grpcpp/impl/codegen/slice.h:139
grpc::SliceReferencingString
grpc_slice SliceReferencingString(const std::string &str)
Definition: include/grpcpp/impl/codegen/slice.h:144
grpc_slice_ref
GPRAPI grpc_slice grpc_slice_ref(grpc_slice s)
Definition: slice_api.cc:27


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:13