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

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

View File

@ -59,10 +59,10 @@ Result<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept {
}
Result<Vector<char>> stripClawHeader(const char *buff, std::size_t buffLen) noexcept {
Result<Buffer> stripClawHeader(const char *buff, std::size_t buffLen) noexcept {
auto header = detail::readHeader(buff, buffLen);
oxReturnError(header);
Vector<char> out(header.value.dataSize);
Buffer out(header.value.dataSize);
ox_memcpy(out.data(), header.value.data, out.size());
return ox::move(out);
}

View File

@ -12,8 +12,8 @@
#ifdef OX_USE_STDLIB
#include <ox/oc/read.hpp>
#endif
#include <ox/std/buffer.hpp>
#include <ox/std/string.hpp>
#include <ox/std/vector.hpp>
#include "format.hpp"
@ -33,7 +33,7 @@ Result<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept;
}
Result<Vector<char>> stripClawHeader(const char *buff, std::size_t buffLen) noexcept;
Result<Buffer> stripClawHeader(const char *buff, std::size_t buffLen) noexcept;
template<typename T>
Error readClaw(const char *buff, std::size_t buffLen, T *val) {
@ -65,7 +65,7 @@ Result<T> readClaw(const char *buff, std::size_t buffLen) {
}
template<typename T>
Result<T> readClaw(const Vector<char> &buff) {
Result<T> readClaw(const Buffer &buff) {
return readClaw<T>(buff.data(), buff.size());
}

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;