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 | |
| 8 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 9 | #include "net/quic/platform/impl/quic_mem_slice_span_impl.h" |
| 10 | |
| 11 | namespace quic { |
| 12 | |
| 13 | // QuicMemSliceSpan is effectively wrapper around an array of data structures |
| 14 | // used as QuicMemSlice. So it could implemented with: |
| 15 | // QuicMemSlice* slices_; |
| 16 | // size_t num_slices_; |
| 17 | // But for efficiency reasons, the actual implementation is an array of |
| 18 | // platform-specific objects. This could avoid the translation from |
| 19 | // platform-specific object to QuicMemSlice. |
| 20 | // QuicMemSliceSpan does not own the underling data buffers. |
| 21 | class QUIC_EXPORT_PRIVATE QuicMemSliceSpan { |
| 22 | public: |
| 23 | explicit QuicMemSliceSpan(QuicMemSliceSpanImpl impl) : impl_(impl) {} |
| 24 | |
QUICHE team | 4e952e7 | 2019-05-10 15:44:24 -0700 | [diff] [blame] | 25 | // Constructs a span with a single QuicMemSlice. |
| 26 | explicit QuicMemSliceSpan(QuicMemSlice* slice) : impl_(slice->impl()) {} |
| 27 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | QuicMemSliceSpan(const QuicMemSliceSpan& other) = default; |
| 29 | QuicMemSliceSpan& operator=(const QuicMemSliceSpan& other) = default; |
| 30 | QuicMemSliceSpan(QuicMemSliceSpan&& other) = default; |
| 31 | QuicMemSliceSpan& operator=(QuicMemSliceSpan&& other) = default; |
| 32 | |
| 33 | ~QuicMemSliceSpan() = default; |
| 34 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 35 | template <typename ConsumeFunction> |
| 36 | QuicByteCount ConsumeAll(ConsumeFunction consume) { |
| 37 | return impl_.ConsumeAll(consume); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // Return data of the span at |index| by the form of a QuicStringPiece. |
| 41 | QuicStringPiece GetData(int index) { return impl_.GetData(index); } |
| 42 | |
| 43 | // Return the total length of the data inside the span. |
| 44 | QuicByteCount total_length() { return impl_.total_length(); } |
| 45 | |
| 46 | // Return total number of slices in the span. |
| 47 | size_t NumSlices() { return impl_.NumSlices(); } |
| 48 | |
| 49 | bool empty() const { return impl_.empty(); } |
| 50 | |
| 51 | private: |
| 52 | QuicMemSliceSpanImpl impl_; |
| 53 | }; |
| 54 | |
| 55 | } // namespace quic |
| 56 | |
| 57 | #endif // QUICHE_QUIC_PLATFORM_API_QUIC_MEM_SLICE_SPAN_H_ |