The Free Software Media System - Server Backend & API
Added a precompiled protobuf serializer assembly
LukePulverenti Luke Pulverenti luke pulverentie6d689bdd342
diff --git a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs b/MediaBrowser.ApiInteraction.Metro/DataSerializer.csindex 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{+ /// <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 ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer();+public static T DeserializeFromStream<T>(Stream stream, SerializationFormats format)+ where T : class{if (format == ApiInteraction.SerializationFormats.Protobuf){- return Serializer.Deserialize<T>(stream);+ //return Serializer.Deserialize<T>(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.csprojindex 00e0992b52..63a91ac498 100644--- a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj+++ b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj@@ -59,6 +59,9 @@<Reference Include="protobuf-net"><HintPath>..\protobuf-net\Full\portable\protobuf-net.dll</HintPath></Reference>+ <Reference Include="ProtobufModelSerializer">+ <HintPath>..\MediaBrowser.Model\bin\ProtobufModelSerializer.dll</HintPath>+ </Reference></ItemGroup><Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /><!-- To modify your build process, add your task inside one of the targets below and uncomment it.diff --git a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs b/MediaBrowser.ApiInteraction.Portable/ApiClient.csindex eef73dd874..edadc9f058 100644--- a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs+++ b/MediaBrowser.ApiInteraction.Portable/ApiClient.cs@@ -348,6 +348,7 @@ namespace MediaBrowser.ApiInteraction.Portable/// Performs a GET request, and deserializes the response stream to an object of Type T/// </summary>private void GetDataAsync<T>(string url, Action<T> callback)+ where T : class{GetDataAsync<T>(url, callback, SerializationFormat);}@@ -356,6 +357,7 @@ namespace MediaBrowser.ApiInteraction.Portable/// Performs a GET request, and deserializes the response stream to an object of Type T/// </summary>private void GetDataAsync<T>(string url, Action<T> callback, SerializationFormats serializationFormat)+ where T : class{if (url.IndexOf('?') == -1){@@ -422,6 +424,7 @@ namespace MediaBrowser.ApiInteraction.Portable/// Performs a POST request, and deserializes the response stream to an object of Type T/// </summary>private void PostDataAsync<T>(string url, Dictionary<string, string> formValues, Action<T> callback, SerializationFormats serializationFormat)+ where T : class{if (url.IndexOf('?') == -1){@@ -445,7 +448,7 @@ namespace MediaBrowser.ApiInteraction.Portable{// Construct the bodystring postBody = string.Join("&", formValues.Keys.Select(s => string.Format("{0}={1}", s, formValues[s])).ToArray());-+// Convert the string into a byte array.byte[] byteArray = Encoding.UTF8.GetBytes(postBody);diff --git a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj b/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csprojindex a329746c0a..b46505e9db 100644--- a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj+++ b/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj@@ -51,6 +51,9 @@<Reference Include="protobuf-net"><HintPath>..\protobuf-net\Full\portable\protobuf-net.dll</HintPath></Reference>+ <Reference Include="ProtobufModelSerializer">+ <HintPath>..\MediaBrowser.Model\bin\ProtobufModelSerializer.dll</HintPath>+ </Reference></ItemGroup><ItemGroup><ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">diff --git a/MediaBrowser.ApiInteraction/BaseApiClient.cs b/MediaBrowser.ApiInteraction/BaseApiClient.csindex 59fb72911d..02895283c4 100644--- a/MediaBrowser.ApiInteraction/BaseApiClient.cs+++ b/MediaBrowser.ApiInteraction/BaseApiClient.cs@@ -350,6 +350,7 @@ namespace MediaBrowser.ApiInteraction}protected T DeserializeFromStream<T>(Stream stream)+ where T : class{return DataSerializer.DeserializeFromStream<T>(stream, SerializationFormat);}diff --git a/MediaBrowser.ApiInteraction/DataSerializer.cs b/MediaBrowser.ApiInteraction/DataSerializer.csindex c455bd15ef..ae3a72e622 100644--- a/MediaBrowser.ApiInteraction/DataSerializer.cs+++ b/MediaBrowser.ApiInteraction/DataSerializer.cs@@ -1,17 +1,29 @@-using System;+using ServiceStack.Text;+using System;using System.IO;-using ProtoBuf;-using ServiceStack.Text;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 ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer();++ /// <summary>+ /// Deserializes an object using generics+ /// </summary>public static T DeserializeFromStream<T>(Stream stream, SerializationFormats format)+ where T : class{if (format == ApiInteraction.SerializationFormats.Protobuf){- return Serializer.Deserialize<T>(stream);+ //return Serializer.Deserialize<T>(stream);+ return ProtobufModelSerializer.Deserialize(stream, null, typeof(T)) as T;}else if (format == ApiInteraction.SerializationFormats.Jsv){@@ -25,11 +37,15 @@ namespace MediaBrowser.ApiInteractionthrow new NotImplementedException();}+ /// <summary>+ /// Deserializes an object+ /// </summary>public static object DeserializeFromStream(Stream stream, SerializationFormats format, Type type){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/MediaBrowser.ApiInteraction.csproj b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csprojindex aba95a93ad..a1c5f5175c 100644--- a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj+++ b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj@@ -33,6 +33,9 @@<Reference Include="protobuf-net"><HintPath>..\protobuf-net\Full\net30\protobuf-net.dll</HintPath></Reference>+ <Reference Include="ProtobufModelSerializer">+ <HintPath>..\MediaBrowser.Model\bin\ProtobufModelSerializer.dll</HintPath>+ </Reference><Reference Include="ServiceStack.Text"><HintPath>..\packages\ServiceStack.Text.3.9.5\lib\net35\ServiceStack.Text.dll</HintPath></Reference>diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csprojindex e8d4dc6517..ed46a0e262 100644--- a/MediaBrowser.Common/MediaBrowser.Common.csproj+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj@@ -42,6 +42,9 @@<Reference Include="protobuf-net"><HintPath>..\protobuf-net\Full\net30\protobuf-net.dll</HintPath></Reference>+ <Reference Include="ProtobufModelSerializer">+ <HintPath>..\MediaBrowser.Model\bin\ProtobufModelSerializer.dll</HintPath>+ </Reference><Reference Include="ServiceStack.Text, Version=3.9.5.0, Culture=neutral, processorArchitecture=MSIL"><SpecificVersion>False</SpecificVersion><HintPath>..\packages\ServiceStack.Text.3.9.5\lib\net35\ServiceStack.Text.dll</HintPath>diff --git a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs b/MediaBrowser.Common/Serialization/ProtobufSerializer.csindex 6151e83413..ec8bbe3a3d 100644--- a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs+++ b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs@@ -9,21 +9,33 @@ namespace MediaBrowser.Common.Serialization/// </summary>public static class ProtobufSerializer{+ /// <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 ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer();+public static void SerializeToStream<T>(T obj, Stream stream){- ProtoBuf.Serializer.Serialize<T>(stream, obj);+ //new ProtobufModelSerializer.Serialize(stream, typeof(T));+ ProtoBuf.Serializer.Serialize(stream, obj);}public static T DeserializeFromStream<T>(Stream stream)+ where T : class{- return ProtoBuf.Serializer.Deserialize<T>(stream);+ //return ProtoBuf.Serializer.Deserialize<T>(stream);+ return ProtobufModelSerializer.Deserialize(stream, null, typeof(T)) as T;}public static object DeserializeFromStream(Stream stream, Type type){- throw new NotImplementedException();+ //throw new NotImplementedException();+ return ProtobufModelSerializer.Deserialize(stream, null, type);}-+public static void SerializeToFile<T>(T obj, string file){using (Stream stream = File.Open(file, FileMode.Create))@@ -33,6 +45,7 @@ namespace MediaBrowser.Common.Serialization}public static T DeserializeFromFile<T>(string file)+ where T : class{using (Stream stream = File.OpenRead(file)){diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csprojindex cd93c92bdf..18f7a063b9 100644--- a/MediaBrowser.Model/MediaBrowser.Model.csproj+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj@@ -76,6 +76,9 @@</Reference></ItemGroup><Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />+ <PropertyGroup>+ <PostBuildEvent>"$(ProjectDir)..\protobuf-net\Precompile\precompile.exe" "$(TargetPath)" -o:"$(ProjectDir)bin\ProtobufModelSerializer.dll" -t:ProtobufModelSerializer</PostBuildEvent>+ </PropertyGroup><!-- To modify your build process, add your task inside one of the targets below and uncomment it.Other similar extension points exist, see Microsoft.Common.targets.<Target Name="BeforeBuild">