Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SerializationStream.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 System.Linq;
5 using System.Text;
6 using System.Collections.Generic;
7 
8 using SiliconStudio.Core.IO;
9 
10 namespace SiliconStudio.Core.Serialization
11 {
12  // TODO: Switch to extensible/composite enumeration
13  public class SerializationTagType
14  {
15  public static readonly SerializationTagType StartElement = new SerializationTagType();
16  public static readonly SerializationTagType EndElement = new SerializationTagType();
17  public static readonly SerializationTagType Identifier = new SerializationTagType();
18  }
19 
20  public delegate void TagMarkedDelegate(SerializationStream stream, SerializationTagType tagType, object tagParam);
21 
22  /// <summary>
23  /// Base class for implementation of <see cref="SerializationStream"/>.
24  /// </summary>
25  public abstract class SerializationStream
26  {
27  // Helper buffer for classes needing it.
28  // If null, it should be initialized with NativeStreamBufferSize constant.
29  [ThreadStatic]
30  protected static byte[] bufferTLS;
31  protected const int BufferTLSSize = 1024;
32 
33  /// <inheritdoc/>
34  public NativeStream NativeStream { get; protected set; }
35 
36  /// <summary>
37  /// Initializes a new instance of the <see cref="SerializationStreamBase"/> class.
38  /// </summary>
40  {
41  Context = new SerializerContext();
42  }
43 
44  /// <inheritdoc/>
45  public SerializerContext Context { get; set; }
46 
47  /// <summary>
48  /// Serializes the specified boolean value.
49  /// </summary>
50  /// <param name="value">The value to serialize</param>
51  /// <returns></returns>
52  public abstract void Serialize(ref bool value);
53 
54  /// <summary>
55  /// Serializes the specified float value.
56  /// </summary>
57  /// <param name="value">The value to serialize</param>
58  /// <returns></returns>
59  public abstract void Serialize(ref float value);
60 
61  /// <summary>
62  /// Serializes the specified double value.
63  /// </summary>
64  /// <param name="value">The value to serialize</param>
65  /// <returns></returns>
66  public abstract void Serialize(ref double value);
67 
68  /// <summary>
69  /// Serializes the specified short value.
70  /// </summary>
71  /// <param name="value">The value to serialize</param>
72  /// <returns></returns>
73  public abstract void Serialize(ref short value);
74 
75  /// <summary>
76  /// Serializes the specified integer value.
77  /// </summary>
78  /// <param name="value">The value to serialize</param>
79  /// <returns></returns>
80  public abstract void Serialize(ref int value);
81 
82  /// <summary>
83  /// Serializes the specified long value.
84  /// </summary>
85  /// <param name="value">The value to serialize</param>
86  /// <returns></returns>
87  public abstract void Serialize(ref long value);
88 
89  /// <summary>
90  /// Serializes the specified ushort value.
91  /// </summary>
92  /// <param name="value">The value to serialize</param>
93  /// <returns></returns>
94  public abstract void Serialize(ref ushort value);
95 
96  /// <summary>
97  /// Serializes the specified unsigned integer value.
98  /// </summary>
99  /// <param name="value">The value to serialize</param>
100  /// <returns></returns>
101  public abstract void Serialize(ref uint value);
102 
103  /// <summary>
104  /// Serializes the specified unsigned long value.
105  /// </summary>
106  /// <param name="value">The value to serialize</param>
107  /// <returns></returns>
108  public abstract void Serialize(ref ulong value);
109 
110  /// <summary>
111  /// Serializes the specified string value.
112  /// </summary>
113  /// <param name="value">The value to serialize</param>
114  /// <returns></returns>
115  public abstract void Serialize(ref string value);
116 
117  /// <summary>
118  /// Serializes the specified char value.
119  /// </summary>
120  /// <param name="value">The value to serialize</param>
121  /// <returns></returns>
122  public abstract void Serialize(ref char value);
123 
124  /// <summary>
125  /// Serializes the specified byte value.
126  /// </summary>
127  /// <param name="value">The value to serialize</param>
128  /// <returns></returns>
129  public abstract void Serialize(ref byte value);
130 
131  /// <summary>
132  /// Serializes the specified signed byte value.
133  /// </summary>
134  /// <param name="value">The value to serialize</param>
135  /// <returns></returns>
136  public abstract void Serialize(ref sbyte value);
137 
138  /// <summary>
139  /// Serializes the specified byte array.
140  /// </summary>
141  /// <param name="values">The buffer to serialize.</param>
142  /// <param name="offset">The starting offset in the buffer to begin serializing.</param>
143  /// <param name="count">The size, in bytes, to serialize.</param>
144  /// <returns></returns>
145  public abstract void Serialize(byte[] values, int offset, int count);
146 
147  /// <summary>
148  /// Serializes the specified memory area.
149  /// </summary>
150  /// <param name="memory">The memory area to serialize.</param>
151  /// <param name="count">The size, in bytes, to serialize.</param>
152  /// <returns></returns>
153  public abstract void Serialize(IntPtr memory, int count);
154 
155  /// <summary>
156  /// Flushes all recent writes (for better batching).
157  /// Please note that if only Serialize has been used (no PopTag()),
158  /// Flush() should be called manually.
159  /// </summary>
160  public abstract void Flush();
161  }
162 }
delegate void TagMarkedDelegate(SerializationStream stream, SerializationTagType tagType, object tagParam)
_In_ size_t count
Definition: DirectXTexP.h:174
Base class for implementation of SerializationStream.
A Stream with additional methods for native read and write operations using IntPtr.
Definition: NativeStream.cs:11
SerializationStream()
Initializes a new instance of the SerializationStreamBase class.