Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
AbstractByteBuffer.h
浏览该文件的文档.
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
68 ~AbstractByteBuffer() override;
70 virtual void resetPos();
72 virtual bool eof();
73
77 [[nodiscard]] virtual size_t getLength() const;
82 [[nodiscard]] virtual size_t getCapacity() const;
87 [[nodiscard]] virtual size_t getReadableSize() const;
88
93 virtual size_t freeCapacity();
94
95 virtual void swap(AbstractByteBuffer &other) noexcept;
96
97 // [[nodiscard]] size_t getCurrentWritePos() const { return currentWritePos; }
98 // [[nodiscard]] size_t getCurrentReadPos() const { return currentReadPos; }
99
100public:
101 int64_t read(void *buffer, size_t len) override;
102 int64_t write(const void *buffer, size_t len) override;
103
104 int64_t peek(void *buffer, size_t len) override;
105 int64_t trunc(size_t need_read) override;
106
107private:
108 size_t factor = 0;
109
110 Node *root = nullptr;
112 size_t currentWritePos = 0;
114 size_t currentReadPos = 0;
115
118 size_t length = 0;
119 size_t cap = 0;
120};
121
122} // namespace sese::io