Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
stream.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <cstddef>
17
18#include "pw_multibuf/config.h"
19#include "pw_multibuf/multibuf_v1.h"
20#include "pw_stream/stream.h"
21
22namespace pw::multibuf {
23
26class PW_MULTIBUF_DEPRECATED Stream : public stream::SeekableReaderWriter {
27 public:
28 Stream(MultiBuf& multibuf)
29 : multibuf_(multibuf),
30 iterator_(multibuf_.begin()),
31 multibuf_offset_(0) {}
32
34 constexpr const MultiBuf& multibuf() const { return multibuf_; }
35
36 private:
37 Status DoWrite(ConstByteSpan data) override;
38
39 StatusWithSize DoRead(ByteSpan destination) override;
40
44 Status DoSeek(ptrdiff_t offset, Whence origin) override;
45
46 size_t DoTell() override { return multibuf_offset_; }
47
48 size_t ConservativeLimit(LimitType) const override {
49 return multibuf_.size() - multibuf_offset_;
50 }
51
52 MultiBuf& multibuf_;
53 MultiBuf::iterator iterator_;
54 size_t multibuf_offset_;
55};
56
57} // namespace pw::multibuf
Definition: status.h:85
Definition: status_with_size.h:49
Definition: multibuf_v1.h:246
Definition: stream.h:26
size_t ConservativeLimit(LimitType) const override
Definition: stream.h:48
Status DoWrite(ConstByteSpan data) override
Virtual Write() function implemented by derived classes.
constexpr const MultiBuf & multibuf() const
Returns the MultiBuf backing this stream.
Definition: stream.h:34
Status DoSeek(ptrdiff_t offset, Whence origin) override
StatusWithSize DoRead(ByteSpan destination) override
Virtual Read() function implemented by derived classes.
size_t DoTell() override
Definition: stream.h:46
Definition: stream.h:598
Whence
Positions from which to seek.
Definition: stream.h:46