mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-19 23:11:50 +00:00
feat: add fill in ContentWriter classes for writing with x64 hosts
This commit is contained in:
@@ -14,9 +14,6 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
inline const auto PTR_FOLLOWING = reinterpret_cast<void*>(-1);
|
||||
inline const auto PTR_INSERT = reinterpret_cast<void*>(-2);
|
||||
|
||||
class ReusableEntry
|
||||
{
|
||||
public:
|
||||
@@ -182,6 +179,35 @@ namespace
|
||||
WriteDataInBlock(src, len + 1);
|
||||
}
|
||||
|
||||
ZoneStreamFillWriteAccessor WriteWithFill(const size_t size) override
|
||||
{
|
||||
// If no block has been pushed, load raw
|
||||
if (!m_block_stack.empty())
|
||||
{
|
||||
const auto* block = m_block_stack.top();
|
||||
|
||||
void* result = nullptr;
|
||||
switch (block->m_type)
|
||||
{
|
||||
case XBlockType::BLOCK_TYPE_TEMP:
|
||||
case XBlockType::BLOCK_TYPE_NORMAL:
|
||||
result = m_zone_data.GetBufferOfSize(size);
|
||||
break;
|
||||
|
||||
case XBlockType::BLOCK_TYPE_RUNTIME:
|
||||
case XBlockType::BLOCK_TYPE_DELAY:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
IncBlockPos(size);
|
||||
|
||||
return ZoneStreamFillWriteAccessor(result, size);
|
||||
}
|
||||
|
||||
return ZoneStreamFillWriteAccessor(m_zone_data.GetBufferOfSize(size), size);
|
||||
}
|
||||
|
||||
void MarkFollowing(const ZoneOutputOffset outputOffset) override
|
||||
{
|
||||
assert(!m_block_stack.empty());
|
||||
@@ -305,9 +331,9 @@ ZoneOutputOffset::ZoneOutputOffset(void* offset)
|
||||
{
|
||||
}
|
||||
|
||||
void* ZoneOutputOffset::Offset() const
|
||||
ZoneOutputOffset ZoneOutputOffset::AtOffset(const size_t innerOffset) const
|
||||
{
|
||||
return m_offset;
|
||||
return ZoneOutputOffset(static_cast<char*>(m_offset) + innerOffset);
|
||||
}
|
||||
|
||||
void ZoneOutputOffset::Inc(const size_t size)
|
||||
@@ -315,9 +341,9 @@ void ZoneOutputOffset::Inc(const size_t size)
|
||||
m_offset = static_cast<void*>(static_cast<char*>(m_offset) + size);
|
||||
}
|
||||
|
||||
ZoneOutputOffset ZoneOutputOffset::WithInnerOffset(const size_t innerOffset) const
|
||||
void* ZoneOutputOffset::Offset() const
|
||||
{
|
||||
return ZoneOutputOffset(static_cast<char*>(m_offset) + innerOffset);
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
std::unique_ptr<ZoneOutputStream>
|
||||
@@ -325,3 +351,19 @@ std::unique_ptr<ZoneOutputStream>
|
||||
{
|
||||
return std::make_unique<InMemoryZoneOutputStream>(pointerBitCount, blockBitCount, blocks, insertBlock, zoneData);
|
||||
}
|
||||
|
||||
ZoneStreamFillWriteAccessor::ZoneStreamFillWriteAccessor(void* blockBuffer, const size_t bufferSize)
|
||||
: m_block_buffer(blockBuffer),
|
||||
m_buffer_size(bufferSize)
|
||||
{
|
||||
}
|
||||
|
||||
ZoneStreamFillWriteAccessor ZoneStreamFillWriteAccessor::AtOffset(const size_t offset) const
|
||||
{
|
||||
return ZoneStreamFillWriteAccessor(static_cast<char*>(m_block_buffer) + offset, m_buffer_size - offset);
|
||||
}
|
||||
|
||||
ZoneOutputOffset ZoneStreamFillWriteAccessor::Offset() const
|
||||
{
|
||||
return ZoneOutputOffset(m_block_buffer);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Zone/Stream/IZoneStream.h"
|
||||
#include "Zone/XBlock.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
@@ -16,14 +17,41 @@ public:
|
||||
ZoneOutputOffset();
|
||||
explicit ZoneOutputOffset(void* offset);
|
||||
|
||||
[[nodiscard]] void* Offset() const;
|
||||
[[nodiscard]] ZoneOutputOffset AtOffset(size_t innerOffset) const;
|
||||
void Inc(size_t size);
|
||||
[[nodiscard]] ZoneOutputOffset WithInnerOffset(size_t innerOffset) const;
|
||||
[[nodiscard]] void* Offset() const;
|
||||
|
||||
private:
|
||||
void* m_offset;
|
||||
};
|
||||
|
||||
class ZoneStreamFillWriteAccessor
|
||||
{
|
||||
public:
|
||||
ZoneStreamFillWriteAccessor(void* blockBuffer, size_t bufferSize);
|
||||
|
||||
[[nodiscard]] ZoneStreamFillWriteAccessor AtOffset(size_t offset) const;
|
||||
[[nodiscard]] ZoneOutputOffset Offset() const;
|
||||
|
||||
template<typename T> void Fill(const T& value, const size_t offset) const
|
||||
{
|
||||
assert(offset + sizeof(T) <= m_buffer_size);
|
||||
|
||||
*reinterpret_cast<T*>(static_cast<char*>(m_block_buffer) + offset) = value;
|
||||
}
|
||||
|
||||
template<typename T, size_t S> void FillArray(T (&value)[S], const size_t offset) const
|
||||
{
|
||||
assert(offset + sizeof(T) * S <= m_buffer_size);
|
||||
|
||||
std::memcpy(static_cast<char*>(m_block_buffer) + offset, value, sizeof(T) * S);
|
||||
}
|
||||
|
||||
private:
|
||||
void* m_block_buffer;
|
||||
size_t m_buffer_size;
|
||||
};
|
||||
|
||||
class ZoneOutputStream : public IZoneStream
|
||||
{
|
||||
public:
|
||||
@@ -59,6 +87,8 @@ public:
|
||||
virtual void IncBlockPos(size_t size) = 0;
|
||||
virtual void WriteNullTerminated(const void* dst) = 0;
|
||||
|
||||
virtual ZoneStreamFillWriteAccessor WriteWithFill(size_t size) = 0;
|
||||
|
||||
virtual bool ReusableShouldWrite(void* pPtr, ZoneOutputOffset outputOffset, size_t size, std::type_index type) = 0;
|
||||
virtual void ReusableAddOffset(void* ptr, size_t size, size_t count, std::type_index type) = 0;
|
||||
virtual void MarkFollowing(ZoneOutputOffset offset) = 0;
|
||||
|
||||
Reference in New Issue
Block a user