slice_splitter.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 
20 
21 #include <string.h>
22 
23 #include <algorithm>
24 
25 #include <grpc/support/alloc.h>
26 
28 
30  switch (mode) {
32  return "identity";
34  return "merge_all";
36  return "one_byte";
37  }
38  return "error";
39 }
40 
42  size_t src_slice_count, grpc_slice** dst_slices,
43  size_t* dst_slice_count) {
44  size_t i, j;
45  size_t length;
46 
47  switch (mode) {
49  *dst_slice_count = src_slice_count;
50  *dst_slices = static_cast<grpc_slice*>(
51  gpr_malloc(sizeof(grpc_slice) * src_slice_count));
52  for (i = 0; i < src_slice_count; i++) {
53  (*dst_slices)[i] = src_slices[i];
54  grpc_slice_ref((*dst_slices)[i]);
55  }
56  break;
58  *dst_slice_count = 1;
59  length = 0;
60  for (i = 0; i < src_slice_count; i++) {
61  length += GRPC_SLICE_LENGTH(src_slices[i]);
62  }
63  *dst_slices = static_cast<grpc_slice*>(gpr_malloc(sizeof(grpc_slice)));
64  **dst_slices = grpc_slice_malloc(length);
65  length = 0;
66  for (i = 0; i < src_slice_count; i++) {
67  memcpy(GRPC_SLICE_START_PTR(**dst_slices) + length,
68  GRPC_SLICE_START_PTR(src_slices[i]),
69  GRPC_SLICE_LENGTH(src_slices[i]));
70  length += GRPC_SLICE_LENGTH(src_slices[i]);
71  }
72  break;
74  length = 0;
75  for (i = 0; i < src_slice_count; i++) {
76  length += GRPC_SLICE_LENGTH(src_slices[i]);
77  }
78  *dst_slice_count = length;
79  *dst_slices =
80  static_cast<grpc_slice*>(gpr_malloc(sizeof(grpc_slice) * length));
81  length = 0;
82  for (i = 0; i < src_slice_count; i++) {
83  for (j = 0; j < GRPC_SLICE_LENGTH(src_slices[i]); j++) {
84  (*dst_slices)[length] = grpc_slice_sub(src_slices[i], j, j + 1);
85  length++;
86  }
87  }
88  break;
89  }
90 }
91 
93  grpc_slice* src_slices, size_t src_slice_count,
96  size_t nslices;
97  size_t i;
98  grpc_split_slices(mode, src_slices, src_slice_count, &slices, &nslices);
99  for (i = 0; i < nslices; i++) {
100  /* add indexed to avoid re-merging split slices */
102  }
103  gpr_free(slices);
104 }
105 
109 }
110 
112  uint8_t* out = nullptr;
113  size_t length = 0;
114  size_t capacity = 0;
115  size_t i;
116 
117  for (i = 0; i < nslices; i++) {
120  out = static_cast<uint8_t*>(gpr_realloc(out, capacity));
121  }
125  }
126 
127  return grpc_slice_new(out, length, gpr_free);
128 }
grpc_slice_split_mode_name
const char * grpc_slice_split_mode_name(grpc_slice_split_mode mode)
Definition: slice_splitter.cc:29
dst
static const char dst[]
Definition: test-fs-copyfile.c:37
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
GRPC_SLICE_SPLIT_IDENTITY
@ GRPC_SLICE_SPLIT_IDENTITY
Definition: slice_splitter.h:32
capacity
uint16_t capacity
Definition: protobuf/src/google/protobuf/descriptor.cc:948
grpc_slice_new
GPRAPI grpc_slice grpc_slice_new(void *p, size_t len, void(*destroy)(void *))
Definition: slice/slice.cc:103
string.h
grpc_slice_split_mode
grpc_slice_split_mode
Definition: slice_splitter.h:28
grpc_slice_buffer::slices
grpc_slice * slices
Definition: include/grpc/impl/codegen/slice.h:89
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
useful.h
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition: alloc.cc:29
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
grpc_slice_sub
GPRAPI grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end)
Definition: slice/slice.cc:268
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_SPLIT_MERGE_ALL
@ GRPC_SLICE_SPLIT_MERGE_ALL
Definition: slice_splitter.h:30
slice_splitter.h
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
gpr_realloc
GPRAPI void * gpr_realloc(void *p, size_t size)
Definition: alloc.cc:56
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
grpc_slice_buffer::count
size_t count
Definition: include/grpc/impl/codegen/slice.h:91
grpc_split_slices_to_buffer
void grpc_split_slices_to_buffer(grpc_slice_split_mode mode, grpc_slice *src_slices, size_t src_slice_count, grpc_slice_buffer *dst)
Definition: slice_splitter.cc:92
grpc_split_slice_buffer
void grpc_split_slice_buffer(grpc_slice_split_mode mode, grpc_slice_buffer *src, grpc_slice_buffer *dst)
Definition: slice_splitter.cc:106
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc_slice_merge
grpc_slice grpc_slice_merge(grpc_slice *slices, size_t nslices)
Definition: slice_splitter.cc:111
GRPC_SLICE_LENGTH
#define GRPC_SLICE_LENGTH(slice)
Definition: include/grpc/impl/codegen/slice.h:104
grpc_split_slices
void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice *src_slices, size_t src_slice_count, grpc_slice **dst_slices, size_t *dst_slice_count)
Definition: slice_splitter.cc:41
alloc.h
slices
SliceBuffer * slices
Definition: retry_filter.cc:631
grpc_slice_buffer
Definition: include/grpc/impl/codegen/slice.h:83
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
GRPC_SLICE_SPLIT_ONE_BYTE
@ GRPC_SLICE_SPLIT_ONE_BYTE
Definition: slice_splitter.h:34
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
grpc_slice_buffer_add_indexed
GPRAPI size_t grpc_slice_buffer_add_indexed(grpc_slice_buffer *sb, grpc_slice slice)
Definition: slice/slice_buffer.cc:161
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