Files
ox/src/nostalgia/foundation/asset.hpp
T

48 lines
1.2 KiB
C++

/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/defines.hpp>
#include <ox/claw/claw.hpp>
#include <ox/fs/fs.hpp>
#include <nostalgia/foundation/context.hpp>
namespace nostalgia::foundation {
[[nodiscard]]
ox::Result<ox::UUID> readUuidHeader(const ox::Buffer &buff) noexcept;
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
ox::Error writeUuidHeader(ox::Writer_c auto *writer, const ox::UUID &uuid) noexcept {
const auto hdr = ox::sfmt<ox::BString<40>>("N1{};", uuid.toString());
return write(writer, hdr);
}
template<typename T>
ox::Result<T> readAsset(const ox::Buffer &buff) noexcept {
std::size_t offset = 0;
const auto err = readUuidHeader(buff).error;
if (!err) {
offset = 40; // the size of N1 headers
}
return ox::readClaw<T>(buff.data() + offset, buff.size() - offset);
}
ox::Result<ox::ModelObject> readAsset(ox::TypeStore *ts, const ox::Buffer &buff) noexcept;
struct AssetHdr {
ox::UUID uuid;
ox::ClawHeader clawHdr;
};
ox::Result<AssetHdr> readAssetHeader(const char *buff, std::size_t buffLen) noexcept;
ox::Result<AssetHdr> readAssetHeader(const ox::Buffer &buff) noexcept;
}