aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.ApiInteraction.Metro/DataSerializer.cs20
-rw-r--r--MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj3
-rw-r--r--MediaBrowser.ApiInteraction.Portable/ApiClient.cs5
-rw-r--r--MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj3
-rw-r--r--MediaBrowser.ApiInteraction/BaseApiClient.cs1
-rw-r--r--MediaBrowser.ApiInteraction/DataSerializer.cs26
-rw-r--r--MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj3
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj3
-rw-r--r--MediaBrowser.Common/Serialization/ProtobufSerializer.cs21
-rw-r--r--MediaBrowser.Model/MediaBrowser.Model.csproj3
10 files changed, 73 insertions, 15 deletions
diff --git a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs
index 8af88014c..6445e8567 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.csproj
index 00e0992b5..63a91ac49 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.cs
index eef73dd87..edadc9f05 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 body
string 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.csproj
index a329746c0..b46505e9d 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.cs
index 59fb72911..02895283c 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.cs
index c455bd15e..ae3a72e62 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.ApiInteraction
throw 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.csproj
index aba95a93a..a1c5f5175 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.csproj
index e8d4dc651..ed46a0e26 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.cs
index 6151e8341..ec8bbe3a3 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.csproj
index cd93c92bd..18f7a063b 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">