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: Added a precompiled protobuf serializer assembly --- .../Serialization/ProtobufSerializer.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Common/Serialization') diff --git a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs index 6151e83413..ec8bbe3a3d 100644 --- a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs +++ b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs @@ -9,21 +9,33 @@ namespace MediaBrowser.Common.Serialization /// public static class ProtobufSerializer { + /// + /// 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 void SerializeToStream(T obj, Stream stream) { - ProtoBuf.Serializer.Serialize(stream, obj); + //new ProtobufModelSerializer.Serialize(stream, typeof(T)); + ProtoBuf.Serializer.Serialize(stream, obj); } public static T DeserializeFromStream(Stream stream) + where T : class { - return ProtoBuf.Serializer.Deserialize(stream); + //return ProtoBuf.Serializer.Deserialize(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 obj, string file) { using (Stream stream = File.Open(file, FileMode.Create)) @@ -33,6 +45,7 @@ namespace MediaBrowser.Common.Serialization } public static T DeserializeFromFile(string file) + where T : class { using (Stream stream = File.OpenRead(file)) { -- cgit v1.2.3