summaryrefslogtreecommitdiff
path: root/data_buffer.h
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2024-02-05 01:20:51 +0300
committerOxore <oxore@protonmail.com>2024-02-05 01:21:59 +0300
commit21a9aa92a7cf8767a0fcb33858546dea744c4071 (patch)
treea5313fdaff5c0ed2d3db416d027e6df21d3cd7ff /data_buffer.h
parent9fd2eba95beb6c9ce6fb26e1442aa2f68aac9b1f (diff)
Organize source code and tests
Diffstat (limited to 'data_buffer.h')
-rw-r--r--data_buffer.h41
1 files changed, 0 insertions, 41 deletions
diff --git a/data_buffer.h b/data_buffer.h
deleted file mode 100644
index bc264d2..0000000
--- a/data_buffer.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-
-/* SPDX-License-Identifier: Unlicense
- */
-
-#include "common.h"
-
-#include <cstddef>
-#include <cstdint>
-
-struct DataView {
- const uint8_t *const buffer{};
- const size_t size{};
-};
-
-struct DataBuffer {
- DataBuffer(){};
- DataBuffer(const DataBuffer&) = delete;
- constexpr DataBuffer(DataBuffer&& other)
- : buffer(other.buffer)
- , buffer_size(other.buffer_size)
- , occupied_size(other.occupied_size)
- {
- other.occupied_size = 0;
- other.buffer_size = 0;
- other.buffer = nullptr;
- };
- static constexpr size_t kInitialSize = 4 * 1024;
- uint8_t *buffer{new uint8_t[kInitialSize]};
- size_t buffer_size{kInitialSize};
- size_t occupied_size{};
- void Expand(size_t new_size);
- constexpr auto View(size_t offset = 0, size_t size = SIZE_MAX) const
- {
- if (offset >= occupied_size) {
- return DataView{};
- }
- return DataView{buffer + offset, Min(occupied_size - offset, size)};
- };
- ~DataBuffer();
-};