[ox/fs] Add model definition for FileAddress
This commit is contained in:
parent
d0f5819072
commit
ed0bf268ba
31
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
31
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -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<typename T>
|
||||
ox::Error modelRead(T *io, FileAddress *fa) {
|
||||
io->setTypeInfo("ox::FileAddress", FileAddress::Fields);
|
||||
io->template setTypeInfo<FileAddress>();
|
||||
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<typename T>
|
||||
ox::Error modelWrite(T *io, FileAddress *fa) {
|
||||
io->setTypeInfo("ox::FileAddress", FileAddress::Fields);
|
||||
io->template setTypeInfo<FileAddress>();
|
||||
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<typename T>
|
||||
ox::Error modelWriteDefinition(T *io, FileAddress::Data *obj) {
|
||||
io->template setTypeInfo<FileAddress::Data>();
|
||||
oxReturnError(io->field("path", &obj->path));
|
||||
oxReturnError(io->field("constPath", &obj->constPath));
|
||||
oxReturnError(io->field("inode", &obj->inode));
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Error modelWriteDefinition(T *io, FileAddress *fa) {
|
||||
io->template setTypeInfo<FileAddress>();
|
||||
oxReturnError(io->field("type", &fa->m_type));
|
||||
oxReturnError(io->field("data", UnionView(&fa->m_data, fa->m_type)));
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user