From 1cb00589065fd05b8d7cf0030eed84c488e9634d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 16 Aug 2022 13:42:11 +0200 Subject: Avoid serialization. A great benefit of this is that the program doesn't need to COPY the data from the file view to the struct. --- c/data.h | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'c/data.h') diff --git a/c/data.h b/c/data.h index 91e34d9..4e25251 100644 --- a/c/data.h +++ b/c/data.h @@ -5,14 +5,18 @@ #include "util.h" #include "wcharptr.h" +/* ElvData and DlvData are written as-is to disk; note the careful + * alignment. */ + struct ElvData { - int rating = 0; - bool bWatched = false; - bool bTVOriginal = false; - wchar_t sRating[3] = {0}; - wchar_t siEp[5] = {0}; - wchar_t title[128] = {0}; + unsigned char version = 'a'; /* 0-1 */ + unsigned char rating = 0; /* 1-2 */ + unsigned char bWatched = 0; /* 2-3 */ + unsigned char bTVOriginal = 0; /* 3-4 */ + wchar_t sRating[4] = {0}; /* 4-12 */ + wchar_t siEp[6] = {0}; /* 12-24 */ + wchar_t title[128] = {0}; /* 24-280 */ }; struct DlvData @@ -24,19 +28,19 @@ struct DlvData wchar_t wiki[128] = {0}; }; -struct DatView +struct FileView { - DatView(const wchar_t* filename, size_t cb); - ~DatView(); + FileView(const wchar_t* filename, size_t cb); + ~FileView(); + inline operator unsigned char*() { return view; } HANDLE hf; HANDLE hm; - void* view; + unsigned char* view; /* TODO: Handle exceptions on read and write... */ }; -constexpr size_t CB_SERIALIZE_ELVDATA = 1+sizeof(ElvData); -unsigned char* Serialize(const ElvData& e, unsigned char* buf); -unsigned char* Unserialize(ElvData& e, unsigned char* buf); +void Write(unsigned char* buf, const ElvData& e); +ElvData* Read(unsigned char* buf); inline int FromWeb(const int iEp, ElvData& e, DlvData& d) noexcept { @@ -57,7 +61,7 @@ inline bool FromProlog(const int iEp, ElvData& e) noexcept else return false; - if (Pl("episode_data","episode_rating",iEp,&e.rating)) + if (Pl("episode_data","episode_rating",iEp,reinterpret_cast(&e.rating))) Swprintf(e.sRating, L"%d", e.rating); if (Pl("episode_data","tv_original",iEp)) -- cgit v1.2.3