Procházet zdrojové kódy

Add serialisation to PPVM

Billy Barrow před 2 roky
rodič
revize
9df0cc0974
1 změnil soubory, kde provedl 35 přidání a 0 odebrání
  1. 35 0
      src/lib/Ppvm.vala

+ 35 - 0
src/lib/Ppvm.vala

@@ -19,6 +19,11 @@ namespace Ppub {
         private Gee.HashMap<string, string> entries { get; set; }
 
         public Invercargill.Sequence<VideoDescription> streams { get; set; }
+
+        public VideoManifest() {
+            entries = new Gee.HashMap<string, string>();
+            streams = Invercargill.empty<VideoDescription>().to_sequence();
+        }
     
         public string? get_value(string name) {
             if (entries.has_key(name)) {
@@ -149,6 +154,23 @@ namespace Ppub {
 
         }
 
+        public string to_string() {
+            var data = "PPVM\n";
+            foreach (var key in entries.keys) {
+                data += @"$key: $(entries[key])\n";
+            }
+
+            data += "\n";
+
+            foreach (var stream in streams) {
+                data += @"$VIDEO: $(stream.to_string())\n";
+            }
+
+            data += "\n";
+
+            return data;
+        }
+
 
     }
 
@@ -162,6 +184,10 @@ namespace Ppub {
 
         private Gee.HashMap<string, string> properties { get; set; }
 
+        public VideoDescription() {
+            properties = new Gee.HashMap<string, string>();
+        }
+
         public VideoDescription.from_string(string line) {
             var fields = line.split(", ", 3);
             version_label = fields[0];
@@ -182,6 +208,15 @@ namespace Ppub {
             }
         }
 
+        public string to_string() {
+            var meta = "";
+            foreach(var key in properties.keys) {
+                meta += @" $key=\"$(properties[key])\";";
+            }
+
+            return @"$version_label, $file_name,$meta";
+        }
+
         public string? get_property(string name) {
             if (properties.has_key(name)) {
                 return properties.get(name);