Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/10 15:50:50 (14 years ago)
Author:
epitzer
Message:

add support for type information interleaving and subsequently true streaming (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs

    r3004 r3005  
    4949    private readonly bool isTestRun;
    5050    private readonly List<Exception> exceptions;
     51
     52    public bool InterleaveTypeInformation { get; set; }
    5153
    5254    /// <summary>
     
    106108    /// don't stop at the first exception</param>
    107109    public Serializer(object obj, Configuration configuration, string rootName, bool isTestRun) {
     110      this.InterleaveTypeInformation = false;
    108111      this.obj = obj;
    109112      this.rootName = rootName;
     
    144147      if (obj2id.ContainsKey(value))
    145148        return ReferenceEnumerator(accessor.Name, obj2id[value]);
    146       if (!typeCache.ContainsKey(type))
     149      bool emitTypeInfo = false;
     150      if (!typeCache.ContainsKey(type)) {
    147151        typeCache.Add(type, typeCache.Count);
     152        emitTypeInfo = InterleaveTypeInformation;
     153      }
    148154      int typeId = typeCache[type];
    149155      int? id = null;
     
    155161        IPrimitiveSerializer primitiveSerializer = configuration.GetPrimitiveSerializer(type);
    156162        if (primitiveSerializer != null)
    157           return PrimitiveEnumerator(accessor.Name, typeId, primitiveSerializer.Format(value), id);
     163          return PrimitiveEnumerator(
     164            accessor.Name,
     165            typeId,
     166            primitiveSerializer.Format(value),
     167            id,
     168            emitTypeInfo);
    158169        ICompositeSerializer compositeSerializer = configuration.GetCompositeSerializer(type);
    159170        if (compositeSerializer != null)
    160           return CompositeEnumerator(accessor.Name, compositeSerializer.Decompose(value), id, typeId, compositeSerializer.CreateMetaInfo(value));
     171          return CompositeEnumerator(
     172            accessor.Name,
     173            compositeSerializer.Decompose(value),
     174            id,
     175            typeId,
     176            compositeSerializer.CreateMetaInfo(value),
     177            emitTypeInfo);
    161178        throw CreatePersistenceException(type);
    162179      } catch (Exception x) {
     
    200217
    201218    private IEnumerator<ISerializationToken> PrimitiveEnumerator(string name,
    202         int typeId, ISerialData serializedValue, int? id) {
     219        int typeId, ISerialData serializedValue, int? id, bool emitTypeInfo) {
     220      if (emitTypeInfo) {
     221        var mapping = TypeCache[typeId];
     222        yield return new TypeToken(mapping.Id, mapping.TypeName, mapping.Serializer);
     223      }
    203224      yield return new PrimitiveToken(name, typeId, id, serializedValue);
    204225    }
    205226
    206227    private IEnumerator<ISerializationToken> CompositeEnumerator(
    207         string name, IEnumerable<Tag> tags, int? id, int typeId, IEnumerable<Tag> metaInfo) {
     228        string name, IEnumerable<Tag> tags, int? id, int typeId, IEnumerable<Tag> metaInfo,
     229        bool emitTypeInfo) {
     230      if (emitTypeInfo) {
     231        var mapping = TypeCache[typeId];
     232        yield return new TypeToken(mapping.Id, mapping.TypeName, mapping.Serializer);
     233      }
    208234      yield return new BeginToken(name, typeId, id);
    209235      bool first = true;
Note: See TracChangeset for help on using the changeset viewer.