QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_PLATFORM_API_QUIC_MEM_SLICE_SPAN_H_ |
| 6 | #define QUICHE_QUIC_PLATFORM_API_QUIC_MEM_SLICE_SPAN_H_ |
| 7 | |
vasilvv | ffd151a | 2020-10-09 12:16:24 -0700 | [diff] [blame] | 8 | #include "absl/strings/string_view.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 9 | #include "quic/platform/api/quic_export.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "net/quic/platform/impl/quic_mem_slice_span_impl.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | |
| 14 | // QuicMemSliceSpan is effectively wrapper around an array of data structures |
| 15 | // used as QuicMemSlice. So it could implemented with: |
| 16 | // QuicMemSlice* slices_; |
| 17 | // size_t num_slices_; |
| 18 | // But for efficiency reasons, the actual implementation is an array of |
| 19 | // platform-specific objects. This could avoid the translation from |
| 20 | // platform-specific object to QuicMemSlice. |
| 21 | // QuicMemSliceSpan does not own the underling data buffers. |
| 22 | class QUIC_EXPORT_PRIVATE QuicMemSliceSpan { |
| 23 | public: |
| 24 | explicit QuicMemSliceSpan(QuicMemSliceSpanImpl impl) : impl_(impl) {} |
| 25 | |
QUICHE team | 4e952e7 | 2019-05-10 15:44:24 -0700 | [diff] [blame] | 26 | // Constructs a span with a single QuicMemSlice. |
| 27 | explicit QuicMemSliceSpan(QuicMemSlice* slice) : impl_(slice->impl()) {} |
| 28 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | QuicMemSliceSpan(const QuicMemSliceSpan& other) = default; |
| 30 | QuicMemSliceSpan& operator=(const QuicMemSliceSpan& other) = default; |
| 31 | QuicMemSliceSpan(QuicMemSliceSpan&& other) = default; |
| 32 | QuicMemSliceSpan& operator=(QuicMemSliceSpan&& other) = default; |
| 33 | |
| 34 | ~QuicMemSliceSpan() = default; |
| 35 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 36 | template <typename ConsumeFunction> |
| 37 | QuicByteCount ConsumeAll(ConsumeFunction consume) { |
| 38 | return impl_.ConsumeAll(consume); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 39 | } |
| 40 | |
dmcardle | 60acc06 | 2019-12-13 09:43:04 -0800 | [diff] [blame] | 41 | // Return data of the span at |index| by the form of a |
vasilvv | ffd151a | 2020-10-09 12:16:24 -0700 | [diff] [blame] | 42 | // absl::string_view. |
| 43 | absl::string_view GetData(int index) { return impl_.GetData(index); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 44 | |
| 45 | // Return the total length of the data inside the span. |
| 46 | QuicByteCount total_length() { return impl_.total_length(); } |
| 47 | |
| 48 | // Return total number of slices in the span. |
| 49 | size_t NumSlices() { return impl_.NumSlices(); } |
| 50 | |
| 51 | bool empty() const { return impl_.empty(); } |
| 52 | |
| 53 | private: |
| 54 | QuicMemSliceSpanImpl impl_; |
| 55 | }; |
| 56 | |
| 57 | } // namespace quic |
| 58 | |
| 59 | #endif // QUICHE_QUIC_PLATFORM_API_QUIC_MEM_SLICE_SPAN_H_ |