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 15 #include <grpc/event_engine/slice.h> 16 #include <grpc/event_engine/slice_buffer.h> 17 #include <grpc/slice_buffer.h> 18 #include <grpc/support/port_platform.h> 19 #include <stddef.h> 20 21 #include "src/core/lib/slice/slice.h" 22 23 namespace grpc_event_engine { 24 namespace experimental { 25 Append(Slice slice)26void SliceBuffer::Append(Slice slice) { 27 grpc_slice_buffer_add(&slice_buffer_, slice.TakeCSlice()); 28 } 29 AppendIndexed(Slice slice)30size_t SliceBuffer::AppendIndexed(Slice slice) { 31 return grpc_slice_buffer_add_indexed(&slice_buffer_, slice.TakeCSlice()); 32 } 33 TakeFirst()34Slice SliceBuffer::TakeFirst() { 35 return Slice(grpc_slice_buffer_take_first(&slice_buffer_)); 36 } 37 Prepend(Slice slice)38void SliceBuffer::Prepend(Slice slice) { 39 grpc_slice_buffer_undo_take_first(&slice_buffer_, slice.TakeCSlice()); 40 } 41 RefSlice(size_t index)42Slice SliceBuffer::RefSlice(size_t index) { 43 return Slice(grpc_core::CSliceRef(slice_buffer_.slices[index])); 44 } 45 46 } // namespace experimental 47 } // namespace grpc_event_engine 48