From 2d698d22c9a14c6d3c451c704aa055ab6bec6b10 Mon Sep 17 00:00:00 2001
From: Ed_ <edwardgz@gmail.com>
Date: Fri, 9 Feb 2024 13:39:08 -0500
Subject: [PATCH] Added versioning to project serialization

---
 code/serialize.odin | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/code/serialize.odin b/code/serialize.odin
index 4c53b94..d59cc97 100644
--- a/code/serialize.odin
+++ b/code/serialize.odin
@@ -11,7 +11,6 @@ Serializer_Loading :: false
 ArchiveData :: struct {
 	data        : [] byte,
 	version     : i32,
-	is_writting : b32
 }
 
 archive_init_temp :: proc () -> ^ ArchiveData {
@@ -34,7 +33,15 @@ project_serialize :: proc ( project : ^ Project, archive : ^ ArchiveData, is_wri
 
 	if is_writting
 	{
-		json_data, marshal_code := json.marshal( project^, options, allocator = context.temp_allocator )
+		marshal_archive : struct {
+			version : i32,
+			project : Project
+		}
+		marshal_archive.version = archive.version
+		marshal_archive.project = project^
+		// TODO(Ed): In the future this will be more complicated, as serialization of workspaces and the code database won't be trivial
+
+		json_data, marshal_code := json.marshal( marshal_archive, options, allocator = context.temp_allocator )
 		verify( marshal_code != json.Marshal_Data_Error.None, "Failed to marshal the project to JSON" )
 
 		archive.data = json_data
@@ -44,7 +51,11 @@ project_serialize :: proc ( project : ^ Project, archive : ^ ArchiveData, is_wri
 		parsed_json, parse_code := json.parse( archive.data, json.Specification.MJSON, allocator = context.temp_allocator )
 		verify( parse_code != json.Error.None, "Failed to parse project JSON")
 
-		project_json := parsed_json.(json.Object)
+		archive_json := parsed_json.(json.Object)
+		archive_version : i32 = cast(i32) archive_json["version"].(json.Float)
+		verify( Serializer_Version != archive_version, "Version mismatch on archive!" )
+
+		project_json := archive_json["project"].(json.Object)
 		project.name  = project_json["name"].(json.String)
 
 		// TODO(Ed) : Make this a separate proc