Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
AbstractByteBuffer.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://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,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
22#pragma once
23
24#include "sese/io/Stream.h"
26
27namespace sese::io {
28
33private:
37 struct Node {
39 void *buffer = nullptr;
41 Node *next = nullptr;
43 size_t length = 0;
45 size_t cap = 0;
50 explicit Node(size_t buffer_size);
52 ~Node();
53 };
54
55public:
61
63 AbstractByteBuffer(const AbstractByteBuffer &abstract_byte_buffer) noexcept;
65 AbstractByteBuffer(AbstractByteBuffer &&abstract_byte_buffer) noexcept;
66
67 ~AbstractByteBuffer() override;
69 virtual void resetPos();
71 virtual bool eof();
72
76 [[nodiscard]] virtual size_t getLength() const;
80 [[nodiscard]] virtual size_t getCapacity() const;
84 [[nodiscard]] virtual size_t getReadableSize() const;
85
90 virtual size_t freeCapacity();
91
92 virtual void swap(AbstractByteBuffer &other) noexcept;
93
94 // [[nodiscard]] size_t getCurrentWritePos() const { return currentWritePos; }
95 // [[nodiscard]] size_t getCurrentReadPos() const { return currentReadPos; }
96
97public:
98 int64_t read(void *buffer, size_t len) override;
99 int64_t write(const void *buffer, size_t len) override;
100
101 int64_t peek(void *buffer, size_t len) override;
102 int64_t trunc(size_t need_read) override;
103
104private:
105 size_t factor = 0;
106
107 Node *root = nullptr;
109 size_t currentWritePos = 0;
111 size_t currentReadPos = 0;
112
115 size_t length = 0;
116 size_t cap = 0;
117};
118
119} // namespace sese::io