[ox/preloader] Fix ox::String handling, add start and end alloc functions

This commit is contained in:
Gary Talent 2022-12-03 01:47:04 -06:00
parent 5bac497293
commit 517ffddf04

View File

@ -86,6 +86,10 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
template<typename T>
constexpr ox::Error field(CRStringView, const T **val, std::size_t cnt) noexcept;
constexpr ox::Error startAlloc(std::size_t sz) noexcept;
constexpr ox::Error endAlloc() noexcept;
constexpr ox::Error offsetPtrs(std::size_t offset) noexcept;
[[nodiscard]]
@ -220,11 +224,23 @@ constexpr ox::Error Preloader<PlatSpec>::field(CRStringView, const T **val, std:
return {};
}
template<typename PlatSpec>
constexpr ox::Error Preloader<PlatSpec>::startAlloc(std::size_t sz) noexcept {
oxRequire(p, ox::allocate(&m_writer, sz));
return m_writer.seekp(p);
}
template<typename PlatSpec>
constexpr ox::Error Preloader<PlatSpec>::endAlloc() noexcept {
return m_writer.seekp(0, ox::ios_base::end);
}
template<typename PlatSpec>
constexpr ox::Error Preloader<PlatSpec>::offsetPtrs(std::size_t offset) noexcept {
for (const auto &p : m_ptrs) {
oxReturnError(m_writer.seekp(p.loc));
oxReturnError(ox::serialize(&m_writer, PlatSpec::correctEndianness(p.value + offset)));
const auto val = PlatSpec::template correctEndianness<typename PlatSpec::PtrType>(p.value + offset);
oxReturnError(ox::serialize(&m_writer, val));
}
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
return {};