[ox/claw] Replace Vector<char> with Buffer

This commit is contained in:
2021-05-03 20:02:04 -04:00
parent d20a24d10f
commit 947b1e7798
3 changed files with 10 additions and 21 deletions

View File

@ -12,8 +12,8 @@
#ifdef OX_USE_STDLIB
#include <ox/oc/write.hpp>
#endif
#include <ox/std/buffer.hpp>
#include <ox/std/string.hpp>
#include <ox/std/vector.hpp>
#include "format.hpp"
@ -40,15 +40,6 @@ struct TypeInfoCatcher {
};
template<typename T>
[[nodiscard]] constexpr int getTypeVersion(int version = T::TypeVersion) noexcept {
return version;
}
[[nodiscard]] constexpr int getTypeVersion(...) noexcept {
return -1;
}
template<typename T, typename = int>
struct type_version {
static constexpr auto value = -1;
@ -92,12 +83,10 @@ Result<String> writeClawHeader(T *t, ClawFormat fmt) noexcept {
}
template<typename T>
Result<Vector<char>> writeClaw(T *t, ClawFormat fmt) {
auto [header, headerErr] = detail::writeClawHeader(t, fmt);
oxReturnError(headerErr);
const auto [data, dataErr] = fmt == ClawFormat::Metal ? writeMC(t) : writeOC(t);
oxReturnError(dataErr);
ox::Vector<char> out(header.len() + data.size());
Result<Buffer> writeClaw(T *t, ClawFormat fmt) {
oxRequire(header, detail::writeClawHeader(t, fmt));
oxRequire(data, fmt == ClawFormat::Metal ? writeMC(t) : writeOC(t));
Buffer out(header.len() + data.size());
memcpy(out.data(), header.data(), header.len());
memcpy(out.data() + header.len(), data.data(), data.size());
return out;