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
obj
T
Returns
- T
Type Parameters
T
ReadBoolean(SerializationStream)
Reads a boolean value from the stream.
public static bool ReadBoolean(this SerializationStream stream)
Parameters
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe stream.
count
int
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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe 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
stream
SerializationStreamThe stream to read the object from.
Returns
- T
The object that has just been read.
Type Parameters
T
The 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
serializer
SerializationStreamptr
nintlength
int
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
serializer
SerializationStreamptr
void*length
int
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
stream
SerializationStreamThe stream to serialize to.
obj
TThe object to serialize.
mode
ArchiveModeThe serialization mode.
dataSerializer
DataSerializer<T>The data serializer (can be null).
Type Parameters
T
The 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
stream
SerializationStreamThe stream to serialize to.
obj
TThe object to serialize.
mode
ArchiveModeThe serialization mode.
dataSerializer
DataSerializer<T>The data serializer (can be null).
Type Parameters
T
The 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
serializer
SerializationStreamvalue
T
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
stream
SerializationStreamThe stream to serialize to.
obj
TThe object to serialize.
mode
ArchiveModeThe 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
stream
SerializationStreamThe stream.
value
boolThe 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
stream
SerializationStreamThe stream.
value
byteThe 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
stream
SerializationStreamThe stream.
values
byte[]The byte array to write.
offset
intThe starting offset in values to write.
count
intThe 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
stream
SerializationStreamThe stream.
value
charThe 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
stream
SerializationStreamThe stream.
value
doubleThe 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
stream
SerializationStreamThe stream.
value
shortThe 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
stream
SerializationStreamThe stream.
value
intThe 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
stream
SerializationStreamThe stream.
value
longThe 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
stream
SerializationStreamThe stream.
value
sbyteThe 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
stream
SerializationStreamThe stream.
value
floatThe 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
stream
SerializationStreamThe stream.
value
stringThe 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
stream
SerializationStreamThe stream.
value
ushortThe 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
stream
SerializationStreamThe stream.
value
uintThe 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
stream
SerializationStreamThe stream.
value
ulongThe 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
stream
SerializationStreamThe stream to write the object to.
obj
TThe object to write.
Type Parameters
T
The type of the object to write.