Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ObjectId.Serializer.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using SiliconStudio.Core.Serialization;
5 using SiliconStudio.Core.Serialization.Serializers;
6 
7 namespace SiliconStudio.Core.Storage
8 {
9  /// <summary>
10  /// A hash to uniquely identify data.
11  /// </summary>
12  [DataSerializer(typeof(ObjectId.Serializer))]
13  public unsafe partial struct ObjectId
14  {
15  internal class Serializer : DataSerializer<ObjectId>
16  {
17  public override void Serialize(ref ObjectId obj, ArchiveMode mode, SerializationStream stream)
18  {
19  if (mode == ArchiveMode.Serialize)
20  {
21  bool hasId = obj != Empty;
22  stream.Write(hasId);
23  if (hasId)
24  {
25  fixed (uint* hash = &obj.hash1)
26  stream.Serialize((IntPtr)hash, HashSize);
27  }
28  }
29  else if (mode == ArchiveMode.Deserialize)
30  {
31  bool hasId = stream.ReadBoolean();
32  if (hasId)
33  {
34  var id = new byte[HashSize];
35  stream.Serialize(id, 0, HashSize);
36  obj = new ObjectId(id);
37  }
38  else
39  {
40  obj = ObjectId.Empty;
41  }
42  }
43  }
44  }
45  }
46 }
Base class for implementation of SerializationStream.
Describes how to serialize and deserialize an object without knowing its type. Used as a common base ...
ArchiveMode
Enumerates the different mode of serialization (either serialization or deserialization).
Definition: ArchiveMode.cs:8