aboutsummaryrefslogtreecommitdiff
path: root/c/data.h
diff options
context:
space:
mode:
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))