瀏覽代碼

Added protobuf support for serializing ServerConfiguration

LukePulverenti Luke Pulverenti luke pulverenti 12 年之前
父節點
當前提交
50f88997ba

+ 1 - 4
MediaBrowser.ApiInteraction.Portable/ApiClient.cs

@@ -269,10 +269,7 @@ namespace MediaBrowser.ApiInteraction.Portable
         {
             string url = ApiUrl + "/ServerConfiguration";
 
-            // At the moment this can't be retrieved in protobuf format
-            SerializationFormats format = DataSerializer.CanDeSerializeJsv ? SerializationFormats.Jsv : SerializationFormats.Json;
-
-            GetDataAsync(url, callback, format);
+            GetDataAsync(url, callback);
         }
 
         /// <summary>

+ 2 - 5
MediaBrowser.ApiInteraction/BaseHttpApiClient.cs

@@ -313,12 +313,9 @@ namespace MediaBrowser.ApiInteraction
         {
             string url = ApiUrl + "/ServerConfiguration";
 
-            // At the moment this can't be retrieved in protobuf format
-            SerializationFormats format = DataSerializer.CanDeSerializeJsv ? SerializationFormats.Jsv : SerializationFormats.Json;
-
-            using (Stream stream = await GetSerializedStreamAsync(url, format).ConfigureAwait(false))
+            using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false))
             {
-                return DataSerializer.DeserializeFromStream<ServerConfiguration>(stream, format);
+                return DeserializeFromStream<ServerConfiguration>(stream);
             }
         }
 

+ 8 - 1
MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs

@@ -1,12 +1,19 @@
-
+using ProtoBuf;
+
 namespace MediaBrowser.Model.Configuration
 {
     /// <summary>
     /// Serves as a common base class for the Server and UI application Configurations
+    /// ProtoInclude tells Protobuf about subclasses,
+    /// The number 50 can be any number, so long as it doesn't clash with any of the ProtoMember numbers either here or in subclasses.
     /// </summary>
+    [ProtoContract, ProtoInclude(50, typeof(ServerConfiguration))]
     public class BaseApplicationConfiguration
     {
+        [ProtoMember(1)]
         public bool EnableDebugLevelLogging { get; set; }
+
+        [ProtoMember(2)]
         public int HttpServerPortNumber { get; set; }
 
         public BaseApplicationConfiguration()

+ 11 - 0
MediaBrowser.Model/Configuration/ServerConfiguration.cs

@@ -1,13 +1,24 @@
 using MediaBrowser.Model.Weather;
+using ProtoBuf;
 
 namespace MediaBrowser.Model.Configuration
 {
+    /// <summary>
+    /// Represents the server configuration.
+    /// </summary>
+    [ProtoContract]
     public class ServerConfiguration : BaseApplicationConfiguration
     {
+        [ProtoMember(3)]
         public bool EnableInternetProviders { get; set; }
+
+        [ProtoMember(4)]
         public bool EnableUserProfiles { get; set; }
 
+        [ProtoMember(5)]
         public string WeatherZipCode { get; set; }
+
+        [ProtoMember(6)]
         public WeatherUnits WeatherUnit { get; set; }
 
         public ServerConfiguration()