aboutsummaryrefslogtreecommitdiff
path: root/c/data.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-16 13:42:11 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-16 13:42:11 +0200
commit1cb00589065fd05b8d7cf0030eed84c488e9634d (patch)
treef6054ff80e8c87d8a4b7a53dbfced30f05dd6dd2 /c/data.h
parent5095c2e2ba9aadf468514804fb3a872d10fdc17d (diff)
downloadEpisodeBrowser-1cb00589065fd05b8d7cf0030eed84c488e9634d.tar.gz
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.
Diffstat (limited to 'c/data.h')
-rw-r--r--c/data.h32
1 files changed, 18 insertions, 14 deletions
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<int*>(&e.rating)))
Swprintf(e.sRating, L"%d", e.rating);
if (Pl("episode_data","tv_original",iEp))