Class SerializerExtensions
- Namespace
- Stride.Core.Serialization
- Assembly
- Stride.Core.dll
Various useful extension methods on top of SerializationStream for serialization/deserialization of common types.
public static class SerializerExtensions
- Inheritance
-
SerializerExtensions
Methods
Clone<T>(T)
public static T Clone<T>(T obj)
Parameters
objT
Returns
- T
Type Parameters
T
ReadBoolean(SerializationStream)
Reads a boolean value from the stream.
public static bool ReadBoolean(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- bool
A boolean value read from the stream.
ReadByte(SerializationStream)
Reads a unsigned byte integer from the stream.
public static byte ReadByte(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- byte
An unsigned byte read from the stream.
ReadBytes(SerializationStream, int)
Reads the specified number of bytes.
[Obsolete("Allocates. Read into the destination.")]
public static byte[] ReadBytes(this SerializationStream stream, int count)
Parameters
streamSerializationStreamThe stream.
countint
Returns
- byte[]
A byte array containing the data read from the stream.
ReadChar(SerializationStream)
Reads a unicode character from the stream.
public static char ReadChar(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- char
A unicode character read from the stream.
ReadDouble(SerializationStream)
Reads a 8-byte floating point value from the stream.
public static double ReadDouble(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- double
A 8-byte floating point value read from the stream.
ReadInt16(SerializationStream)
Reads a 2-byte signed integer from the stream.
public static short ReadInt16(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- short
A 2-byte signed integer read from the stream.
ReadInt32(SerializationStream)
Reads a 4-byte signed integer from the stream.
public static int ReadInt32(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- int
A 4-byte signed integer read from the stream.
ReadInt64(SerializationStream)
Reads a 8-byte signed integer from the stream.
public static long ReadInt64(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- long
A 8-byte signed integer read from the stream.
ReadSByte(SerializationStream)
Reads a signed byte from the stream.
public static sbyte ReadSByte(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- sbyte
A signed byte read from the stream.
ReadSingle(SerializationStream)
Reads a 4-byte floating point value from the stream.
public static float ReadSingle(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- float
A 4-byte floating point value read from the stream.
ReadString(SerializationStream)
Reads a string.
public static string ReadString(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- string
A string read from the stream.
ReadUInt16(SerializationStream)
Reads a 2-byte unsigned integer from the stream.
public static ushort ReadUInt16(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- ushort
A 2-byte unsigned integer read from the stream.
ReadUInt32(SerializationStream)
Reads a 4-byte unsigned integer from the stream.
public static uint ReadUInt32(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- uint
A 4-byte unsigned integer read from the stream.
ReadUInt64(SerializationStream)
Reads a 8-byte unsigned integer from the stream.
public static ulong ReadUInt64(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream.
Returns
- ulong
A 8-byte unsigned integer read from the stream.
Read<T>(SerializationStream)
Reads the specified object from the stream.
public static T Read<T>(this SerializationStream stream)
Parameters
streamSerializationStreamThe stream to read the object from.
Returns
- T
The object that has just been read.
Type Parameters
TThe type of the object to read.
Serialize(SerializationStream, nint, int)
Serializes or deserializes the memory using Serialize(Span<byte>).
[Obsolete("Use Serialize(Span<byte>)")]
public static void Serialize(this SerializationStream serializer, nint ptr, int length)
Parameters
serializerSerializationStreamptrIntPtrlengthint
Serialize(SerializationStream, void*, int)
Serializes or deserializes the memory using Serialize(Span<byte>).
[Obsolete("Use Serialize(Span<byte>)")]
public static void Serialize(this SerializationStream serializer, void* ptr, int length)
Parameters
serializerSerializationStreamptrvoid*lengthint
SerializeExtended<T>(SerializationStream, T, ArchiveMode, DataSerializer<T>)
Serializes the specified object.
public static void SerializeExtended<T>(this SerializationStream stream, T obj, ArchiveMode mode, DataSerializer<T> dataSerializer = null)
Parameters
streamSerializationStreamThe stream to serialize to.
objTThe object to serialize.
modeArchiveModeThe serialization mode.
dataSerializerDataSerializer<T>The data serializer (can be null).
Type Parameters
TThe object type to serialize.
SerializeExtended<T>(SerializationStream, ref T, ArchiveMode, DataSerializer<T>)
Serializes the specified object.
public static void SerializeExtended<T>(this SerializationStream stream, ref T obj, ArchiveMode mode, DataSerializer<T> dataSerializer = null)
Parameters
streamSerializationStreamThe stream to serialize to.
objTThe object to serialize.
modeArchiveModeThe serialization mode.
dataSerializerDataSerializer<T>The data serializer (can be null).
Type Parameters
TThe object type to serialize.
Serialize<T>(SerializationStream, ref T)
Serializes or deserializes the value using Serialize(Span<byte>).
public static void Serialize<T>(this SerializationStream serializer, ref T value)
Parameters
serializerSerializationStreamvalueT
Type Parameters
T
Serialize<T>(SerializationStream, ref T, ArchiveMode)
Serializes the specified object.
public static void Serialize<T>(this SerializationStream stream, ref T obj, ArchiveMode mode)
Parameters
streamSerializationStreamThe stream to serialize to.
objTThe object to serialize.
modeArchiveModeThe serialization mode.
Type Parameters
T
Write(SerializationStream, bool)
Writes a boolean value to the specified stream.
public static SerializationStream Write(this SerializationStream stream, bool value)
Parameters
streamSerializationStreamThe stream.
valueboolThe boolean value to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, byte)
Writes an unsigned byte to the specified stream.
public static SerializationStream Write(this SerializationStream stream, byte value)
Parameters
streamSerializationStreamThe stream.
valuebyteThe unsigned byte to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, byte[], int, int)
Writes a byte array region to the specified stream.
public static SerializationStream Write(this SerializationStream stream, byte[] values, int offset, int count)
Parameters
streamSerializationStreamThe stream.
valuesbyte[]The byte array to write.
offsetintThe starting offset in values to write.
countintThe number of bytes to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, char)
Writes a unicode character to the specified stream.
public static SerializationStream Write(this SerializationStream stream, char value)
Parameters
streamSerializationStreamThe stream.
valuecharThe unicode character to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, double)
Writes a 8-byte floating point value to the specified stream.
public static SerializationStream Write(this SerializationStream stream, double value)
Parameters
streamSerializationStreamThe stream.
valuedoubleThe 8-byte floating point value to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, short)
Writes a 2-byte signed integer to the specified stream.
public static SerializationStream Write(this SerializationStream stream, short value)
Parameters
streamSerializationStreamThe stream.
valueshortThe 2-byte signed integer to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, int)
Writes a 4-byte signed integer to the specified stream.
public static SerializationStream Write(this SerializationStream stream, int value)
Parameters
streamSerializationStreamThe stream.
valueintThe 4-byte signed integer to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, long)
Writes a 8-byte signed integer to the specified stream.
public static SerializationStream Write(this SerializationStream stream, long value)
Parameters
streamSerializationStreamThe stream.
valuelongThe 8-byte signed integer to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, sbyte)
Writes a signed byte to the specified stream.
public static SerializationStream Write(this SerializationStream stream, sbyte value)
Parameters
streamSerializationStreamThe stream.
valuesbyteThe signed byte to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, float)
Writes a 4-byte floating point value to the specified stream.
public static SerializationStream Write(this SerializationStream stream, float value)
Parameters
streamSerializationStreamThe stream.
valuefloatThe 4-byte floating point value to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, string)
Writes a string to the specified stream.
public static SerializationStream Write(this SerializationStream stream, string value)
Parameters
streamSerializationStreamThe stream.
valuestringThe string to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, ushort)
Writes a 2-byte unsigned integer to the specified stream.
public static SerializationStream Write(this SerializationStream stream, ushort value)
Parameters
streamSerializationStreamThe stream.
valueushortThe 2-byte unsigned integer to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, uint)
Writes a 4-byte unsigned integer to the specified stream.
public static SerializationStream Write(this SerializationStream stream, uint value)
Parameters
streamSerializationStreamThe stream.
valueuintThe 4-byte unsigned integer to write.
Returns
- SerializationStream
The stream.
Write(SerializationStream, ulong)
Writes a 8-byte unsigned integer to the specified stream.
public static SerializationStream Write(this SerializationStream stream, ulong value)
Parameters
streamSerializationStreamThe stream.
valueulongThe 8-byte unsigned integer to write.
Returns
- SerializationStream
The stream.
Write<T>(SerializationStream, T)
Writes the specified object to the stream.
public static void Write<T>(this SerializationStream stream, T obj)
Parameters
streamSerializationStreamThe stream to write the object to.
objTThe object to write.
Type Parameters
TThe type of the object to write.