[ox/fs] Add modelWrite handler to FileAddress
This commit is contained in:
parent
5a0ba33b4c
commit
fbdb48a1ee
1
deps/ox/src/ox/fs/CMakeLists.txt
vendored
1
deps/ox/src/ox/fs/CMakeLists.txt
vendored
@ -52,7 +52,6 @@ install(
|
||||
|
||||
install(
|
||||
FILES
|
||||
filestore/filestoretemplate.hpp
|
||||
filesystem/filesystem.hpp
|
||||
filesystem/pathiterator.hpp
|
||||
DESTINATION
|
||||
|
@ -10,6 +10,11 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
FileAddress::FileAddress() {
|
||||
m_data.inode = 0;
|
||||
m_type = FileAddressType::Inode;
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(uint64_t inode) {
|
||||
m_data.inode = inode;
|
||||
m_type = FileAddressType::Inode;
|
||||
|
50
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
50
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -9,18 +9,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/std.hpp>
|
||||
#include <ox/model/types.hpp>
|
||||
|
||||
namespace ox {
|
||||
|
||||
enum class FileAddressType {
|
||||
None = -1,
|
||||
enum class FileAddressType: int8_t {
|
||||
None = -1,
|
||||
Path,
|
||||
ConstPath,
|
||||
Inode,
|
||||
};
|
||||
|
||||
class FileAddress {
|
||||
private:
|
||||
|
||||
template<typename T>
|
||||
friend ox::Error modelWrite(T*, FileAddress*);
|
||||
|
||||
public:
|
||||
static constexpr auto Fields = 2;
|
||||
|
||||
protected:
|
||||
FileAddressType m_type = FileAddressType::None;
|
||||
union {
|
||||
char *path;
|
||||
@ -29,6 +37,8 @@ class FileAddress {
|
||||
} m_data;
|
||||
|
||||
public:
|
||||
FileAddress();
|
||||
|
||||
FileAddress(uint64_t inode);
|
||||
|
||||
FileAddress(char *path);
|
||||
@ -69,4 +79,38 @@ class FileAddress {
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
ox::Error modelWrite(T *io, FileAddress *fa) {
|
||||
io->setTypeInfo("ox::FileAddress", FileAddress::Fields);
|
||||
switch (fa->m_type) {
|
||||
case FileAddressType::Path:
|
||||
case FileAddressType::ConstPath:
|
||||
{
|
||||
decltype(fa->m_data.inode) blank = 0;
|
||||
const auto strSize = ox_strlen(fa->m_data.constPath) + 1;
|
||||
auto path = ox_malloca(strSize, char, 0);
|
||||
memcpy(path.get(), fa->m_data.constPath, strSize);
|
||||
oxReturnError(io->field("path", SerStr(path.get(), strSize - 1)));
|
||||
oxReturnError(io->field("inode", &blank));
|
||||
break;
|
||||
}
|
||||
case FileAddressType::Inode:
|
||||
{
|
||||
char blankPath[1] = "";
|
||||
oxReturnError(io->field("path", SerStr(blankPath, 0)));
|
||||
oxReturnError(io->field("inode", &fa->m_data.inode));
|
||||
break;
|
||||
}
|
||||
case FileAddressType::None:
|
||||
{
|
||||
char blankPath[1] = "";
|
||||
decltype(fa->m_data.inode) blankInode = 0;
|
||||
oxReturnError(io->field("path", SerStr(blankPath, 0)));
|
||||
oxReturnError(io->field("inode", &blankInode));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,9 @@ ox::Error PassThroughFS::resize(uint64_t, void*) {
|
||||
Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_t) {
|
||||
auto p = (m_path / stripSlash(path));
|
||||
auto f = fopen(p.c_str(), "w");
|
||||
if (!f) {
|
||||
return OxError(1);
|
||||
}
|
||||
auto err = OxError(fwrite(buffer, size, 1, f) == 1 ? 0 : 1);
|
||||
fclose(f);
|
||||
return err;
|
||||
|
7
deps/ox/src/ox/mc/write.hpp
vendored
7
deps/ox/src/ox/mc/write.hpp
vendored
@ -84,19 +84,18 @@ Error MetalClawWriter::field(const char *name, ox::BString<L> *val) {
|
||||
|
||||
template<typename T>
|
||||
Error MetalClawWriter::field(const char*, T *val) {
|
||||
auto err = OxError(0);
|
||||
bool fieldSet = false;
|
||||
MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt);
|
||||
if (val) {
|
||||
err |= model(&writer, val);
|
||||
oxReturnError(model(&writer, val));
|
||||
if (static_cast<std::size_t>(writer.m_fieldPresence.getMaxLen()) < writer.m_buffIt) {
|
||||
m_buffIt += writer.m_buffIt;
|
||||
fieldSet = true;
|
||||
}
|
||||
}
|
||||
err |= m_fieldPresence.set(m_field, fieldSet);
|
||||
oxReturnError(m_fieldPresence.set(m_field, fieldSet));
|
||||
m_field++;
|
||||
return err;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
6
deps/ox/src/ox/std/memops.hpp
vendored
6
deps/ox/src/ox/std/memops.hpp
vendored
@ -10,6 +10,12 @@
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
#if __has_include(<cstring>)
|
||||
#include<cstring>
|
||||
#else
|
||||
void *memcpy(void *dest, const void *src, std::size_t size);
|
||||
#endif
|
||||
|
||||
int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept;
|
||||
|
||||
constexpr void *ox_memcpy(void *dest, const void *src, std::size_t size) noexcept {
|
||||
|
Loading…
Reference in New Issue
Block a user