summaryrefslogtreecommitdiff
path: root/data_buffer.h
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-06-04 21:58:39 +0300
committerOxore <oxore@protonmail.com>2023-06-04 23:26:13 +0300
commita3f3fb052678b9cf1f80bbdc72c42afc3705ac0b (patch)
treef45953c256f4e463f073afcdc920c916afc4c0d1 /data_buffer.h
parentb5c24afbc10a36f65e73d5ef2100da4ff173a109 (diff)
Add initial support of ELF files
Diffstat (limited to 'data_buffer.h')
-rw-r--r--data_buffer.h29
1 files changed, 28 insertions, 1 deletions
diff --git a/data_buffer.h b/data_buffer.h
index c3d86e8..bc264d2 100644
--- a/data_buffer.h
+++ b/data_buffer.h
@@ -1,14 +1,41 @@
#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();
};
-