26#include <system_error>
46 const uint8_t* m_bufferStart;
47 const uint8_t* m_bufferEnd;
52 void Init(
const uint8_t* bufStart,
const uint8_t* bufEnd);
59 const uint8_t*
begin()
const {
return m_bufferStart; }
60 const uint8_t*
end()
const {
return m_bufferEnd; }
61 size_t size()
const {
return m_bufferEnd - m_bufferStart; }
66 return {
reinterpret_cast<const char*
>(
begin()),
67 reinterpret_cast<const char*
>(
end())};
73 return "Unknown buffer";
82 int64_t fileSize = -1);
94 uint64_t mapSize, int64_t offset);
154 return {
reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
begin())),
155 reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
end()))};
158 static std::unique_ptr<WritableMemoryBuffer>
GetFile(
209 return {
reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
begin())),
210 reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
end()))};
213 static std::unique_ptr<WriteThroughMemoryBuffer>
GetFile(
233 std::span<const uint8_t> m_buffer;
241 : m_buffer(buffer), m_id(id) {}
243 std::span<const uint8_t>
GetBuffer()
const {
return m_buffer; }
247 const uint8_t*
begin()
const {
return &*m_buffer.begin(); }
248 const uint8_t*
end()
const {
return &*m_buffer.end(); }
249 size_t size()
const {
return m_buffer.size(); }
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:45
static std::unique_ptr< MemoryBuffer > GetOpenFileSlice(fs::file_t f, std::string_view filename, std::error_code &ec, uint64_t mapSize, int64_t offset)
Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetFile(std::string_view filename, std::error_code &ec, int64_t fileSize=-1)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition: MemoryBuffer.h:125
@ MemoryBuffer_Malloc
Definition: MemoryBuffer.h:125
@ MemoryBuffer_MMap
Definition: MemoryBuffer.h:125
virtual std::string_view GetBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:72
static std::unique_ptr< MemoryBuffer > GetOpenFile(fs::file_t f, std::string_view filename, std::error_code &ec, uint64_t fileSize)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetMemBuffer(std::span< const uint8_t > inputData, std::string_view bufferName="")
Open the specified memory range as a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetMemBufferCopy(std::span< const uint8_t > inputData, std::string_view bufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
const uint8_t * begin() const
Definition: MemoryBuffer.h:59
std::span< const uint8_t > GetBuffer() const
Definition: MemoryBuffer.h:63
virtual BufferKind GetBufferKind() const =0
Return information on the memory mechanism used to support the MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetFileSlice(std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
Map a subrange of the specified file as a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetFileAsStream(std::string_view filename, std::error_code &ec)
Read all of the specified file into a MemoryBuffer as a stream (i.e.
MemoryBuffer(const MemoryBuffer &)=delete
MemoryBuffer & operator=(const MemoryBuffer &)=delete
const uint8_t * end() const
Definition: MemoryBuffer.h:60
void Init(const uint8_t *bufStart, const uint8_t *bufEnd)
MemoryBufferRef GetMemBufferRef() const
static std::unique_ptr< MemoryBuffer > GetMemBuffer(MemoryBufferRef ref)
std::span< const char > GetCharBuffer() const
Definition: MemoryBuffer.h:65
size_t size() const
Definition: MemoryBuffer.h:61
Definition: MemoryBuffer.h:232
std::string_view GetBufferIdentifier() const
Definition: MemoryBuffer.h:245
MemoryBufferRef(MemoryBuffer &buffer)
Definition: MemoryBuffer.h:238
std::span< const uint8_t > GetBuffer() const
Definition: MemoryBuffer.h:243
MemoryBufferRef(std::span< const uint8_t > buffer, std::string_view id)
Definition: MemoryBuffer.h:240
const uint8_t * begin() const
Definition: MemoryBuffer.h:247
MemoryBufferRef()=default
size_t size() const
Definition: MemoryBuffer.h:249
const uint8_t * end() const
Definition: MemoryBuffer.h:248
This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying conte...
Definition: MemoryBuffer.h:138
WritableMemoryBuffer()=default
static std::unique_ptr< WritableMemoryBuffer > GetFile(std::string_view filename, std::error_code &ec, int64_t fileSize=-1)
static std::unique_ptr< WritableMemoryBuffer > GetFileSlice(std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
Map a subrange of the specified file as a WritableMemoryBuffer.
uint8_t * end()
Definition: MemoryBuffer.h:151
std::span< uint8_t > GetBuffer()
Definition: MemoryBuffer.h:152
uint8_t * begin()
Definition: MemoryBuffer.h:150
static std::unique_ptr< WritableMemoryBuffer > GetNewMemBuffer(size_t size, std::string_view bufferName="")
Allocate a new zero-initialized MemoryBuffer of the specified size.
static std::unique_ptr< WritableMemoryBuffer > GetNewUninitMemBuffer(size_t size, std::string_view bufferName="")
Allocate a new MemoryBuffer of the specified size that is not initialized.
std::span< char > GetCharBuffer() const
Definition: MemoryBuffer.h:153
size_t size() const
Definition: MemoryBuffer.h:61
This class is an extension of MemoryBuffer, which allows write access to the underlying contents and ...
Definition: MemoryBuffer.h:193
static std::unique_ptr< WriteThroughMemoryBuffer > GetFileSlice(std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
Map a subrange of the specified file as a ReadWriteMemoryBuffer.
WriteThroughMemoryBuffer()=default
static std::unique_ptr< WriteThroughMemoryBuffer > GetFile(std::string_view filename, std::error_code &ec, int64_t fileSize=-1)
std::span< char > GetCharBuffer() const
Definition: MemoryBuffer.h:208
std::span< uint8_t > GetBuffer()
Definition: MemoryBuffer.h:207
uint8_t * begin()
Definition: MemoryBuffer.h:205
uint8_t * end()
Definition: MemoryBuffer.h:206
basic_string_view< char > string_view
Definition: core.h:501
int file_t
Definition: fs.h:32
Definition: ntcore_cpp.h:26