From e6d689bdd3429cd5017de355093ee9c2f3fad069 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 9 Sep 2012 01:30:07 -0400 Subject: [PATCH] Added a precompiled protobuf serializer assembly --- .../DataSerializer.cs | 20 ++++++++++---- .../MediaBrowser.ApiInteraction.Metro.csproj | 3 +++ .../ApiClient.cs | 5 +++- ...ediaBrowser.ApiInteraction.Portable.csproj | 3 +++ MediaBrowser.ApiInteraction/BaseApiClient.cs | 1 + MediaBrowser.ApiInteraction/DataSerializer.cs | 26 +++++++++++++++---- .../MediaBrowser.ApiInteraction.csproj | 3 +++ .../MediaBrowser.Common.csproj | 3 +++ .../Serialization/ProtobufSerializer.cs | 21 ++++++++++++--- MediaBrowser.Model/MediaBrowser.Model.csproj | 3 +++ 10 files changed, 73 insertions(+), 15 deletions(-) diff --git a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs index 8af88014c4..6445e8567b 100644 --- a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs +++ b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs @@ -1,17 +1,26 @@ -using System; +using Newtonsoft.Json; +using System; using System.IO; -using Newtonsoft.Json; -using ProtoBuf; namespace MediaBrowser.ApiInteraction { public static class DataSerializer { + /// + /// 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. + /// + private static ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); + public static T DeserializeFromStream(Stream stream, SerializationFormats format) + where T : class { if (format == ApiInteraction.SerializationFormats.Protobuf) { - return Serializer.Deserialize(stream); + //return Serializer.Deserialize(stream); + return ProtobufModelSerializer.Deserialize(stream, null, typeof(T)) as T; } else if (format == ApiInteraction.SerializationFormats.Jsv) { @@ -35,7 +44,8 @@ namespace MediaBrowser.ApiInteraction { if (format == ApiInteraction.SerializationFormats.Protobuf) { - throw new NotImplementedException(); + //throw new NotImplementedException(); + return ProtobufModelSerializer.Deserialize(stream, null, type); } else if (format == ApiInteraction.SerializationFormats.Jsv) { diff --git a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj index 00e0992b52..63a91ac498 100644 --- a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj +++ b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj @@ -59,6 +59,9 @@ ..\protobuf-net\Full\portable\protobuf-net.dll + + ..\MediaBrowser.Model\bin\ProtobufModelSerializer.dll +