blob: c33707a17633c23f23d827e04cbeb8253b748ae0 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
vasilvvffd151a2020-10-09 12:16:24 -07008#include "absl/strings/string_view.h"
QUICHE team5be974e2020-12-29 18:35:24 -05009#include "quic/platform/api/quic_export.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#include "net/quic/platform/impl/quic_mem_slice_span_impl.h"
11
12namespace 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.
22class QUIC_EXPORT_PRIVATE QuicMemSliceSpan {
23 public:
24 explicit QuicMemSliceSpan(QuicMemSliceSpanImpl impl) : impl_(impl) {}
25
QUICHE team4e952e72019-05-10 15:44:24 -070026 // Constructs a span with a single QuicMemSlice.
27 explicit QuicMemSliceSpan(QuicMemSlice* slice) : impl_(slice->impl()) {}
28
QUICHE teama6ef0a62019-03-07 20:34:33 -050029 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
wub553a9662019-03-28 20:13:23 -070036 template <typename ConsumeFunction>
37 QuicByteCount ConsumeAll(ConsumeFunction consume) {
38 return impl_.ConsumeAll(consume);
QUICHE teama6ef0a62019-03-07 20:34:33 -050039 }
40
dmcardle60acc062019-12-13 09:43:04 -080041 // Return data of the span at |index| by the form of a
vasilvvffd151a2020-10-09 12:16:24 -070042 // absl::string_view.
43 absl::string_view GetData(int index) { return impl_.GetData(index); }
QUICHE teama6ef0a62019-03-07 20:34:33 -050044
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_