event_engine/slice.cc
Go to the documentation of this file.
1 // Copyright 2022 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <stdint.h>
18 
19 #include <string>
20 #include <utility>
21 
23 #include <grpc/slice.h>
24 #include <grpc/support/log.h>
25 
29 
30 namespace grpc_event_engine {
31 namespace experimental {
32 
33 namespace slice_detail {
34 
36 
37 template <>
40 }
41 
42 template <>
45 }
46 
47 } // namespace slice_detail
48 
49 MutableSlice::MutableSlice(const grpc_slice& slice)
50  : slice_detail::BaseSlice(slice) {
52 }
53 
55 
57  if (c_slice().refcount == nullptr) {
58  return Slice(c_slice());
59  }
61  return Slice(grpc_slice_copy(c_slice()));
62  }
63  return Slice(TakeCSlice());
64 }
65 
67  if (c_slice().refcount == nullptr) {
68  return Slice(c_slice());
69  }
71  return Slice(grpc_slice_copy(c_slice()));
72  }
74 }
75 
77  if (c_slice().refcount == nullptr) {
78  return MutableSlice(c_slice());
79  }
81  c_slice().refcount->IsUnique()) {
82  return MutableSlice(TakeCSlice());
83  }
85 }
86 
88 
90 
92  const uint8_t* end) {
94  out.refcount = r;
95  if (r != grpc_slice_refcount::NoopRefcount()) r->Ref();
96  out.data.refcounted.bytes = const_cast<uint8_t*>(begin);
97  out.data.refcounted.length = end - begin;
98  return Slice(out);
99 }
100 
101 } // namespace experimental
102 } // namespace grpc_event_engine
grpc_event_engine::experimental::Slice::Slice
Slice()=default
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
log.h
grpc_event_engine::experimental::slice_detail::CopyConstructors::FromCopiedString
static Out FromCopiedString(const char *s)
Definition: include/grpc/event_engine/slice.h:159
grpc_slice::refcount
struct grpc_slice_refcount * refcount
Definition: include/grpc/impl/codegen/slice.h:66
grpc_slice_ref_internal
const grpc_slice & grpc_slice_ref_internal(const grpc_slice &slice)
Definition: slice_refcount.h:32
GPR_DEBUG_ASSERT
#define GPR_DEBUG_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:103
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
grpc_event_engine::experimental::slice_detail::CopyConstructors
Definition: include/grpc/event_engine/slice.h:158
slice.h
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_event_engine::experimental::MutableSlice::~MutableSlice
~MutableSlice()
Definition: event_engine/slice.cc:54
grpc_event_engine::experimental::Slice::~Slice
~Slice()
Definition: event_engine/slice.cc:87
grpc_event_engine::experimental::slice_detail::BaseSlice::end
const uint8_t * end() const
Definition: include/grpc/event_engine/slice.h:59
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
slice_refcount_base.h
grpc_slice_refcount::IsUnique
bool IsUnique() const
Definition: slice_refcount_base.h:53
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
grpc_slice_refcount::NoopRefcount
static grpc_slice_refcount * NoopRefcount()
Definition: slice_refcount_base.h:29
refcount
size_t refcount
Definition: abseil-cpp/absl/strings/internal/cordz_info.cc:122
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
grpc_event_engine::experimental::Slice::TakeOwned
Slice TakeOwned()
Definition: event_engine/slice.cc:56
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
grpc_slice_refcount
Definition: slice_refcount_base.h:25
grpc_event_engine::experimental::Slice::TakeMutable
MutableSlice TakeMutable()
Definition: event_engine/slice.cc:76
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc_event_engine::experimental::MutableSlice
Definition: include/grpc/event_engine/slice.h:180
slice_internal.h
grpc_event_engine::experimental::slice_detail::BaseSlice::begin
const uint8_t * begin() const
Definition: include/grpc/event_engine/slice.h:58
stdint.h
grpc_event_engine::experimental::slice_detail::BaseSlice::slice_
grpc_slice slice_
Definition: include/grpc/event_engine/slice.h:114
grpc_event_engine::experimental::Slice::AsOwned
Slice AsOwned() const
Definition: event_engine/slice.cc:66
grpc_event_engine::experimental::Slice::FromRefcountAndBytes
static Slice FromRefcountAndBytes(grpc_slice_refcount *r, const uint8_t *begin, const uint8_t *end)
Definition: event_engine/slice.cc:91
fix_build_deps.r
r
Definition: fix_build_deps.py:491
grpc_event_engine
Definition: endpoint_config.h:24
grpc_event_engine::experimental::slice_detail::BaseSlice::Hash
uint32_t Hash() const
Definition: event_engine/slice.cc:35
grpc_slice_hash_internal
uint32_t grpc_slice_hash_internal(const grpc_slice &s)
Definition: slice_internal.h:67
grpc_slice_from_cpp_string
grpc_slice grpc_slice_from_cpp_string(std::string str)
Definition: slice/slice.cc:202
slice_refcount.h
slice.h
grpc_event_engine::experimental::Slice::Ref
Slice Ref() const
Definition: event_engine/slice.cc:89
grpc_event_engine::experimental::Slice
Definition: include/grpc/event_engine/slice.h:215
grpc_event_engine::experimental::slice_detail::BaseSlice::TakeCSlice
grpc_slice TakeCSlice()
Definition: include/grpc/event_engine/slice.h:68
grpc_event_engine::experimental::slice_detail::BaseSlice::c_slice
const grpc_slice & c_slice() const
Definition: include/grpc/event_engine/slice.h:64
grpc_slice_unref_internal
void grpc_slice_unref_internal(const grpc_slice &slice)
Definition: slice_refcount.h:39
grpc_slice_copy
GPRAPI grpc_slice grpc_slice_copy(grpc_slice s)
Definition: slice/slice.cc:46
port_platform.h


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