aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Serialization/ProtobufSerializer.cs
diff options
context:
space:
mode:
authorLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-09-09 01:30:07 -0400
committerLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-09-09 01:30:07 -0400
commite6d689bdd3429cd5017de355093ee9c2f3fad069 (patch)
tree75e6c4eef0bb48ceae70ea802cb36a6073c2f218 /MediaBrowser.Common/Serialization/ProtobufSerializer.cs
parent50f88997bab58f4cfcbd3f420521776a54eb372d (diff)
Added a precompiled protobuf serializer assembly
Diffstat (limited to 'MediaBrowser.Common/Serialization/ProtobufSerializer.cs')
-rw-r--r--MediaBrowser.Common/Serialization/ProtobufSerializer.cs21
1 files changed, 17 insertions, 4 deletions
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))
{