From ab621173afc918797a4ea68b5d6ceee7cc043f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 16 Aug 2022 15:24:24 +0200 Subject: Add data migration test. --- c/data.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'c/data.h') diff --git a/c/data.h b/c/data.h index 4e25251..e584442 100644 --- a/c/data.h +++ b/c/data.h @@ -5,27 +5,29 @@ #include "util.h" #include "wcharptr.h" -/* ElvData and DlvData are written as-is to disk; note the careful - * alignment. */ +/* ElvDataA and DlvDataA are written as-is to disk; note the careful + * alignment. As such, they should be regarded as immutable. If the + * format needs to be changed in the future, then new structs called + * ElvDataB and DlvDataB should be added. */ -struct ElvData +struct ElvDataA { - 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 */ + unsigned char version = 'a'; + unsigned char rating = 0; + unsigned char bWatched = 0; + unsigned char bTVOriginal = 0; + wchar_t sRating[4] = {0}; + wchar_t siEp[6] = {0}; + wchar_t title[128] = {0}; }; -struct DlvData +struct DlvDataA { - wchar_t date[64] = {0}; - wchar_t source[64] = {0}; - wchar_t screenwriter[64] = {0}; + wchar_t date[32] = {0}; + wchar_t source[48] = {0}; + wchar_t screenwriter[48] = {0}; wchar_t hint[128] = {0}; - wchar_t wiki[128] = {0}; + wchar_t wiki[192] = {0}; }; struct FileView @@ -39,10 +41,10 @@ struct FileView /* TODO: Handle exceptions on read and write... */ }; -void Write(unsigned char* buf, const ElvData& e); -ElvData* Read(unsigned char* buf); +void Write(unsigned char* buf, const ElvDataA& e); +ElvDataA* Read(unsigned char* buf); -inline int FromWeb(const int iEp, ElvData& e, DlvData& d) noexcept +inline int FromWeb(const int iEp, ElvDataA& e, DlvDataA& d) noexcept { WcharPtr title, wiki, date, source, hint; const int r = Pl("episode_data","fetch_episode_data",iEp,&title,&wiki,&date,&source,&hint); @@ -54,7 +56,7 @@ inline int FromWeb(const int iEp, ElvData& e, DlvData& d) noexcept return r; } -inline bool FromProlog(const int iEp, ElvData& e) noexcept +inline bool FromProlog(const int iEp, ElvDataA& e) noexcept { if (WcharPtr title; Pl("episode_data","episode_title",iEp,&title)) Wcscpy(e.title, title); @@ -75,7 +77,7 @@ inline bool FromProlog(const int iEp, ElvData& e) noexcept return true; } -inline void FromProlog(const int iEp, DlvData& d) noexcept +inline void FromProlog(const int iEp, DlvDataA& d) noexcept { if (WcharPtr wiki; Pl("episode_data","episode_wiki",iEp,&wiki)) Wcscpy(d.wiki, wiki); -- cgit v1.2.3