diff options
Diffstat (limited to 'c/data.cpp')
-rw-r--r-- | c/data.cpp | 33 |
1 files changed, 8 insertions, 25 deletions
@@ -18,7 +18,7 @@ inline unsigned char* BufToVal(unsigned char* const buf, T& val) return buf+sizeof(val); } -DatView::DatView(const wchar_t* const filename, const size_t cb) +FileView::FileView(const wchar_t* const filename, const size_t cb) { hf = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); @@ -39,12 +39,12 @@ DatView::DatView(const wchar_t* const filename, const size_t cb) if (!hm) throw Win32Error{}; - view = MapViewOfFile(hm, FILE_MAP_ALL_ACCESS, 0, 0, 0); + view = reinterpret_cast<unsigned char*>(MapViewOfFile(hm, FILE_MAP_ALL_ACCESS, 0, 0, 0)); if (!view) throw Win32Error{}; } -DatView::~DatView() +FileView::~FileView() { FlushViewOfFile(view, 0); UnmapViewOfFile(view); @@ -52,31 +52,14 @@ DatView::~DatView() CloseHandle(hf); } -unsigned char* Serialize(const ElvData& e, unsigned char* buf) +void Write(unsigned char* buf, const ElvData& e) { - unsigned char version = 'a'; - buf = ValToBuf(version, buf); - buf = ValToBuf(e.rating, buf); - buf = ValToBuf(e.bWatched, buf); - buf = ValToBuf(e.bTVOriginal, buf); - buf = ValToBuf(e.sRating, buf); - buf = ValToBuf(e.siEp, buf); - buf = ValToBuf(e.title, buf); - return buf; + memcpy(buf, reinterpret_cast<const unsigned char*>(&e), sizeof(e)); } -unsigned char* Unserialize(ElvData& e, unsigned char* buf) +ElvData* Read(unsigned char* const buf) { - unsigned char version; - buf = BufToVal(buf, version); - if (version != 'a') + if (buf[0] != 'a') return nullptr; - - buf = BufToVal(buf, e.rating); - buf = BufToVal(buf, e.bWatched); - buf = BufToVal(buf, e.bTVOriginal); - buf = BufToVal(buf, e.sRating); - buf = BufToVal(buf, e.siEp); - buf = BufToVal(buf, e.title); - return buf; + return reinterpret_cast<ElvData*>(buf); } |