using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace MediaBrowser.Common.Serialization { public static class ProtobufSerializer { public static void SerializeToStream(T obj, Stream stream) { ProtoBuf.Serializer.Serialize(stream, obj); } public static T DeserializeFromStream(Stream stream) { return ProtoBuf.Serializer.Deserialize(stream); } public static void SerializeToFile(T obj, string file) { using (Stream stream = File.Open(file, FileMode.Create)) { SerializeToStream(obj, stream); } } public static T DeserializeFromFile(string file) { using (Stream stream = File.OpenRead(file)) { return DeserializeFromStream(stream); } } } }