Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ChunkHeader.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.IO;
4 
5 namespace SiliconStudio.Core.Serialization.Assets
6 {
7  /// <summary>
8  /// This class describes the header of an asset serialized in a blob file. Its (serialized) size has to remain constant
9  /// </summary>
10  public sealed class ChunkHeader
11  {
12  public const int CurrentVersion = 1;
13 
14  public const int Magic = 0x43484E4B; // "CHNK"
15  public int Version { get; set; }
16  public string Type { get; set; }
17  public int OffsetToObject { get; set; }
18  public int OffsetToReferences { get; set; }
19 
20  public ChunkHeader()
21  {
22  Version = CurrentVersion;
23  OffsetToObject = -1;
24  OffsetToReferences = -1;
25  }
26 
27  private ChunkHeader(int version)
28  {
29  Version = version;
30  OffsetToObject = -1;
31  OffsetToReferences = -1;
32  }
33 
34  public void Write(SerializationStream stream)
35  {
36  stream.Write(Magic);
37  stream.Write(Version);
38  if (Version == 1)
39  {
40  stream.Write(Type);
41  stream.Write(OffsetToObject);
42  stream.Write(OffsetToReferences);
43  }
44  }
45 
46  public static ChunkHeader Read(SerializationStream stream)
47  {
48  int magic = stream.ReadInt32();
49  if (magic != Magic)
50  {
51  // Rewind
52  stream.NativeStream.Seek(-4, SeekOrigin.Current);
53  return null;
54  }
55 
56  int version = stream.ReadInt32();
57  var header = new ChunkHeader(version);
58  if (version == 1)
59  {
60  header.Type = stream.ReadString();
61  header.OffsetToObject = stream.ReadInt32();
62  header.OffsetToReferences = stream.ReadInt32();
63  }
64  return header;
65  }
66  }
67 }
This class describes the header of an asset serialized in a blob file. Its (serialized) size has to r...
Definition: ChunkHeader.cs:10
Base class for implementation of SerializationStream.
static ChunkHeader Read(SerializationStream stream)
Definition: ChunkHeader.cs:46
void Write(SerializationStream stream)
Definition: ChunkHeader.cs:34