C/C++ API Reference
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
25
28class PW_MULTIBUF_DEPRECATED Stream : public stream::SeekableReaderWriter {
29 public:
30 Stream(MultiBuf& multibuf)
31 : multibuf_(multibuf),
32 iterator_(multibuf_.begin()),
33 multibuf_offset_(0) {}
34
36 constexpr const MultiBuf& multibuf() const { return multibuf_; }
37
38 private:
40
41 StatusWithSize DoRead(ByteSpan destination) override;
42
46 Status DoSeek(ptrdiff_t offset, Whence origin) override;
47
48 size_t DoTell() override { return multibuf_offset_; }
49
50 size_t ConservativeLimit(LimitType) const override {
51 return multibuf_.size() - multibuf_offset_;
52 }
53
54 MultiBuf& multibuf_;
55 MultiBuf::iterator iterator_;
56 size_t multibuf_offset_;
57};
58
60
61} // namespace pw::multibuf
Definition: status.h:86
Definition: status_with_size.h:49
Definition: multibuf_v1.h:248
Definition: stream.h:28
size_t ConservativeLimit(LimitType) const override
Definition: stream.h:50
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:36
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:48
Definition: stream.h:612
Whence
Positions from which to seek.
Definition: stream.h:48