Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ByteArraySerializer.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 namespace SiliconStudio.Core.Serialization.Serializers
4 {
5  /// <summary>
6  /// Implements <see cref="DataSerializer{T}"/> for a byte array.
7  /// </summary>
8  [DataSerializerGlobal(typeof(ByteArraySerializer))]
9  public class ByteArraySerializer : DataSerializer<byte[]>
10  {
11  /// <inheritdoc/>
12  public override void PreSerialize(ref byte[] obj, ArchiveMode mode, SerializationStream stream)
13  {
14  if (mode == ArchiveMode.Serialize)
15  {
16  stream.Write(obj.Length);
17  }
18  else if (mode == ArchiveMode.Deserialize)
19  {
20  int length = stream.ReadInt32();
21  obj = new byte[length];
22  }
23  }
24 
25  /// <inheritdoc/>
26  public override void Serialize(ref byte[] obj, ArchiveMode mode, SerializationStream stream)
27  {
28  stream.Serialize(obj, 0, obj.Length);
29  }
30  }
31 }
override void PreSerialize(ref byte[] obj, ArchiveMode mode, SerializationStream stream)
Implements DataSerializer{T} for a byte array.
Base class for implementation of SerializationStream.
override void Serialize(ref byte[] obj, ArchiveMode mode, SerializationStream stream)
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