Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/28/19 13:41:42 (5 years ago)
Author:
gkronber
Message:

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/HeuristicLab.Clients.Hive

  • trunk/HeuristicLab.Clients.Hive/3.3/Util/PersistenceUtil.cs

    r15583 r16565  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Collections.Generic;
    2424using System.IO;
    25 using HeuristicLab.Persistence.Core;
     25using HEAL.Attic;
    2626using HeuristicLab.Persistence.Default.Xml;
    2727
     
    2929  public static class PersistenceUtil {
    3030    public static byte[] Serialize(object obj, out IEnumerable<Type> types) {
    31       using (MemoryStream memStream = new MemoryStream()) {
    32         XmlGenerator.Serialize(obj, memStream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types);
    33         byte[] jobByteArray = memStream.ToArray();
    34         return jobByteArray;
    35       }
     31      var ser = new ProtoBufSerializer();
     32      var bytes = ser.Serialize(obj, out SerializationInfo info);
     33      types = info.SerializedTypes;
     34      return bytes;
    3635    }
    3736
    3837    public static byte[] Serialize(object obj) {
    39       using (MemoryStream memStream = new MemoryStream()) {
    40         XmlGenerator.Serialize(obj, memStream);
    41         byte[] jobByteArray = memStream.ToArray();
    42         return jobByteArray;
    43       }
     38      var ser = new ProtoBufSerializer();
     39      return ser.Serialize(obj);
    4440    }
    4541
    4642    public static T Deserialize<T>(byte[] sjob) {
    47       using (MemoryStream memStream = new MemoryStream(sjob)) {
    48         T job = XmlParser.Deserialize<T>(memStream);
    49         return job;
     43      var ser = new ProtoBufSerializer();
     44      try {
     45        return (T)ser.Deserialize(sjob);
     46      } catch (Exception) {
     47        // retry with old persistence
     48        using (MemoryStream memStream = new MemoryStream(sjob)) {
     49          return XmlParser.Deserialize<T>(memStream);
     50        }
    5051      }
    5152    }
Note: See TracChangeset for help on using the changeset viewer.