diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.hpp b/deps/ox/src/ox/fs/filesystem/filelocation.hpp index 048d6eda..cac98c0f 100644 --- a/deps/ox/src/ox/fs/filesystem/filelocation.hpp +++ b/deps/ox/src/ox/fs/filesystem/filelocation.hpp @@ -29,15 +29,17 @@ class FileAddress { friend ox::Error modelWrite(T*, FileAddress*); public: + static constexpr auto TypeName = "ox::FileAddress"; static constexpr auto Fields = 2; protected: - FileAddressType m_type = FileAddressType::None; - union { + union Data { char *path; const char *constPath; uint64_t inode; - } m_data; + }; + FileAddressType m_type = FileAddressType::None; + Data m_data; public: FileAddress(); @@ -94,9 +96,9 @@ class FileAddress { template ox::Error modelRead(T *io, FileAddress *fa) { - io->setTypeInfo("ox::FileAddress", FileAddress::Fields); + io->template setTypeInfo(); decltype(fa->m_data.inode) inode = 0; - const auto strSize = io->stringLength() + 1; + const auto strSize = io->stringLength("path") + 1; auto path = new char[strSize]; oxReturnError(io->field("path", SerStr(path, strSize - 1))); oxReturnError(io->field("inode", &inode)); @@ -113,7 +115,7 @@ ox::Error modelRead(T *io, FileAddress *fa) { template ox::Error modelWrite(T *io, FileAddress *fa) { - io->setTypeInfo("ox::FileAddress", FileAddress::Fields); + io->template setTypeInfo(); switch (fa->m_type) { case FileAddressType::Path: case FileAddressType::ConstPath: @@ -145,4 +147,21 @@ ox::Error modelWrite(T *io, FileAddress *fa) { return OxError(0); } +template +ox::Error modelWriteDefinition(T *io, FileAddress::Data *obj) { + io->template setTypeInfo(); + oxReturnError(io->field("path", &obj->path)); + oxReturnError(io->field("constPath", &obj->constPath)); + oxReturnError(io->field("inode", &obj->inode)); + return OxError(0); +} + +template +ox::Error modelWriteDefinition(T *io, FileAddress *fa) { + io->template setTypeInfo(); + oxReturnError(io->field("type", &fa->m_type)); + oxReturnError(io->field("data", UnionView(&fa->m_data, fa->m_type))); + return OxError(0); +} + }