/[cits3200i]/branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/MetadataListSerializer.cs


UCC Code Repository

Contents of /branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/MetadataListSerializer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (show annotations) (download)
Mon Oct 11 06:42:56 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 1591 byte(s)
Committing partially implemented Metadata plugin.
Couldn't finish it before the meeting :(
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Runtime.Serialization;
5 using System.Runtime.Serialization.Formatters.Binary;
6 using System.Text;
7
8 namespace MetadataPlugin.Source
9 {
10 class MetadataListSerializer
11 {
12 private MetadataListSerializer() {}
13
14 // NOTE: Increment this if the data storage mechanism changes
15 private static int SERIAL_VERSION = 0;
16
17 public static MetadataList Deserialize(byte[] input)
18 {
19 if (input == null)
20 {
21 return null;
22 }
23 MemoryStream stream = new MemoryStream(input);
24 IFormatter formatter = new BinaryFormatter();
25 int version = (int)formatter.Deserialize(stream);
26 if (version != SERIAL_VERSION)
27 {
28 // FIXME: warn when finding incompatible data
29 return null;
30 }
31 MetadataList ret = (MetadataList)formatter.Deserialize(stream);
32 stream.Close();
33 return ret;
34 }
35
36 public static byte[] Serialize(MetadataList input)
37 {
38 if (input == null)
39 {
40 return null;
41 }
42 MemoryStream stream = new MemoryStream();
43 IFormatter formatter = new BinaryFormatter();
44 formatter.Serialize(stream, SERIAL_VERSION);
45 formatter.Serialize(stream, input);
46 byte[] ret = stream.ToArray();
47 stream.Close();
48 return ret;
49 }
50 }
51 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26