[ox/claw] Fix Claw read to check for type/version compatibility

This commit is contained in:
2022-02-17 02:50:14 -06:00
parent 1d17b3df82
commit 0c6e47e0b3
2 changed files with 36 additions and 1 deletions

View File

@@ -19,6 +19,9 @@
namespace ox {
constexpr auto Error_ClawTypeMismatch = 200;
constexpr auto Error_ClawTypeVersionMismatch = 200;
struct ClawHeader {
String typeName;
int typeVersion = -1;
@@ -38,6 +41,12 @@ Result<Buffer> stripClawHeader(const ox::Buffer &buff) noexcept;
template<typename T>
Error readClaw(const char *buff, std::size_t buffLen, T *val) {
oxRequire(header, readClawHeader(buff, buffLen));
if (header.typeName != getModelTypeName<T>()) {
return OxError(Error_ClawTypeMismatch, "Claw Read: Type mismatch");
}
if (header.typeVersion != getModelTypeVersion<T>()) {
return OxError(Error_ClawTypeVersionMismatch, "Claw Read: Type Verion mismatch");
}
switch (header.fmt) {
case ClawFormat::Metal:
{