diff options
| author | Luke <luke.pulverenti@gmail.com> | 2013-02-20 17:10:49 -0800 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2013-02-20 17:10:49 -0800 |
| commit | 845554722efaed872948a9e0f7202e3ef52f1b6e (patch) | |
| tree | 534ab2d11fe4824ed303bb01e885b330631b657e /MediaBrowser.ApiInteraction.Metro/DataSerializer.cs | |
| parent | 2f142263f080f7b012a0ec2095d350ccf75b49b7 (diff) | |
| parent | 14bbb6804718ef78a8118fe750896ba679e3b6cb (diff) | |
Merge pull request #1 from MediaBrowser/Repo
Repo
Diffstat (limited to 'MediaBrowser.ApiInteraction.Metro/DataSerializer.cs')
| -rw-r--r-- | MediaBrowser.ApiInteraction.Metro/DataSerializer.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs new file mode 100644 index 000000000..92e3f7c2b --- /dev/null +++ b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs @@ -0,0 +1,78 @@ +using Newtonsoft.Json;
+using System;
+using System.IO;
+
+namespace MediaBrowser.ApiInteraction
+{
+ public static class DataSerializer
+ {
+ /// <summary>
+ /// This is an auto-generated Protobuf Serialization assembly for best performance.
+ /// It is created during the Model project's post-build event.
+ /// This means that this class can currently only handle types within the Model project.
+ /// If we need to, we can always add a param indicating whether or not the model serializer should be used.
+ /// </summary>
+ private static readonly ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer();
+
+ public static T DeserializeFromStream<T>(Stream stream, SerializationFormats format)
+ where T : class
+ {
+ if (format == ApiInteraction.SerializationFormats.Protobuf)
+ {
+ return ProtobufModelSerializer.Deserialize(stream, null, typeof(T)) as T;
+ }
+ else if (format == ApiInteraction.SerializationFormats.Jsv)
+ {
+ throw new NotImplementedException();
+ }
+ else if (format == ApiInteraction.SerializationFormats.Json)
+ {
+ using (StreamReader streamReader = new StreamReader(stream))
+ {
+ using (JsonReader jsonReader = new JsonTextReader(streamReader))
+ {
+ return JsonSerializer.Create(new JsonSerializerSettings()).Deserialize<T>(jsonReader);
+ }
+ }
+ }
+
+ throw new NotImplementedException();
+ }
+
+ public static object DeserializeFromStream(Stream stream, SerializationFormats format, Type type)
+ {
+ if (format == ApiInteraction.SerializationFormats.Protobuf)
+ {
+ return ProtobufModelSerializer.Deserialize(stream, null, type);
+ }
+ else if (format == ApiInteraction.SerializationFormats.Jsv)
+ {
+ throw new NotImplementedException();
+ }
+ else if (format == ApiInteraction.SerializationFormats.Json)
+ {
+ using (StreamReader streamReader = new StreamReader(stream))
+ {
+ using (JsonReader jsonReader = new JsonTextReader(streamReader))
+ {
+ return JsonSerializer.Create(new JsonSerializerSettings()).Deserialize(jsonReader, type);
+ }
+ }
+ }
+
+ throw new NotImplementedException();
+ }
+
+ public static void Configure()
+ {
+ }
+
+ public static bool CanDeSerializeJsv
+ {
+ get
+ {
+ return false;
+ }
+ }
+ }
+}
|
