[ox] Make model type version mandatory

This commit is contained in:
2022-05-29 22:21:05 -05:00
parent 3834de3318
commit c4a1655a8f
14 changed files with 89 additions and 76 deletions

View File

@@ -28,9 +28,11 @@ class FileAddress {
public:
static constexpr auto TypeName = "net.drinkingtea.ox.FileAddress";
static constexpr auto TypeVersion = 1;
union Data {
static constexpr auto TypeName = "net.drinkingtea.ox.FileAddress.Data";
static constexpr auto TypeVersion = 1;
char *path = nullptr;
const char *constPath;
uint64_t inode;
@@ -129,8 +131,14 @@ constexpr const char *getModelTypeName<FileAddress>() noexcept {
template<typename T>
constexpr Error model(T *io, FileAddress::Data *obj) noexcept {
io->template setTypeInfo<FileAddress::Data>();
oxReturnError(io->field("path", SerStr(&obj->path)));
oxReturnError(io->field("constPath", SerStr(&obj->path)));
if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) {
String dummy;
oxReturnError(io->field("path", &dummy));
oxReturnError(io->field("constPath", &dummy));
} else {
oxReturnError(io->field("path", SerStr(&obj->path)));
oxReturnError(io->field("constPath", SerStr(&obj->path)));
}
oxReturnError(io->field("inode", &obj->inode));
return OxError(0);
}
@@ -138,10 +146,16 @@ constexpr Error model(T *io, FileAddress::Data *obj) noexcept {
template<typename T>
constexpr Error model(T *io, FileAddress *fa) noexcept {
io->template setTypeInfo<FileAddress>();
auto type = static_cast<int8_t>(fa->m_type);
oxReturnError(io->field("type", &type));
fa->m_type = static_cast<FileAddressType>(type);
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) {
int8_t type = 0;
oxReturnError(io->field("type", &type));
oxReturnError(io->field("data", UnionView(&fa->m_data, 0)));
} else {
auto type = static_cast<int8_t>(fa->m_type);
oxReturnError(io->field("type", &type));
fa->m_type = static_cast<FileAddressType>(type);
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
}
return OxError(0);
}