Table of Contents

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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream

The 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 SerializationStream
ptr nint
length 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 SerializationStream
ptr 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 SerializationStream

The stream to serialize to.

obj T

The object to serialize.

mode ArchiveMode

The 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 SerializationStream

The stream to serialize to.

obj T

The object to serialize.

mode ArchiveMode

The 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 SerializationStream
value 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 SerializationStream

The stream to serialize to.

obj T

The object to serialize.

mode ArchiveMode

The 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 SerializationStream

The stream.

value bool

The 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 SerializationStream

The stream.

value byte

The 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 SerializationStream

The stream.

values byte[]

The byte array to write.

offset int

The starting offset in values to write.

count int

The 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 SerializationStream

The stream.

value char

The 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 SerializationStream

The stream.

value double

The 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 SerializationStream

The stream.

value short

The 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 SerializationStream

The stream.

value int

The 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 SerializationStream

The stream.

value long

The 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 SerializationStream

The stream.

value sbyte

The 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 SerializationStream

The stream.

value float

The 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 SerializationStream

The stream.

value string

The 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 SerializationStream

The stream.

value ushort

The 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 SerializationStream

The stream.

value uint

The 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 SerializationStream

The stream.

value ulong

The 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 SerializationStream

The stream to write the object to.

obj T

The object to write.

Type Parameters

T

The type of the object to write.