Skip to main content

Unity.Netcode.BufferSerializer-1

Two-way serializer wrapping FastBufferReader or FastBufferWriter.

Implemented as a ref struct for two reasons:

  1. The BufferSerializer cannot outlive the FBR/FBW it wraps or using it will cause a crash
  2. The BufferSerializer must always be passed by reference and can't be copied

Ref structs help enforce both of those rules: they can't ref live the stack context in which they were created, and they're always passed by reference no matter what.

BufferSerializer doesn't wrapp FastBufferReader or FastBufferWriter directly because it can't. ref structs can't implement interfaces, and in order to be able to have two different implementations with the same interface (which allows us to avoid an "if(IsReader)" on every call), the thing directly wrapping the struct has to implement an interface. So IReaderWriter exists as the interface, which is implemented by a normal struct, while the ref struct wraps the normal one to enforce the two above requirements. (Allowing direct access to the IReaderWriter struct would allow dangerous things to happen because the struct's lifetime could outlive the Reader/Writer's.)

Inherited Members#

System.ValueType.Equals(System.Object)

System.ValueType.GetHashCode()

System.ValueType.ToString()

System.Object.Equals(System.Object, System.Object)

System.Object.GetType()

System.Object.ReferenceEquals(System.Object, System.Object)

Syntax#
public ref struct BufferSerializer<TReaderWriter>
where TReaderWriter : IReaderWriter
Type Parameters#
NameDescription
TReaderWriterThe implementation struct

Properties#

IsReader#

Check if the contained implementation is a reader

Declaration#
public readonly bool IsReader { get; }
Property Value#
TypeDescription
System.Boolean

IsWriter#

Check if the contained implementation is a writer

Declaration#
public readonly bool IsWriter { get; }
Property Value#
TypeDescription
System.Boolean

Methods#

GetFastBufferReader()#

Retrieves the FastBufferReader instance. Only valid if IsReader = true, throws InvalidOperationException otherwise.

Declaration#
public FastBufferReader GetFastBufferReader()
Returns#
TypeDescription
FastBufferReaderReader instance

GetFastBufferWriter()#

Retrieves the FastBufferWriter instance. Only valid if IsWriter = true, throws InvalidOperationException otherwise.

Declaration#
public FastBufferWriter GetFastBufferWriter()
Returns#
TypeDescription
FastBufferWriterWriter instance

PreCheck(Int32)#

Declaration#
public bool PreCheck(int amount)
Parameters#
TypeNameDescription
System.Int32amount
Returns#
TypeDescription
System.Boolean

SerializeNetworkSerializable\<T>(ref T)#

Declaration#
public void SerializeNetworkSerializable<T>(ref T value)
where T : INetworkSerializable, new()
Parameters#
TypeNameDescription
Tvalue
Type Parameters#
NameDescription
T

SerializeValue(ref Color)#

Declaration#
public void SerializeValue(ref Color value)
Parameters#
TypeNameDescription
Colorvalue

SerializeValue(ref Color[])#

Declaration#
public void SerializeValue(ref Color[] value)
Parameters#
TypeNameDescription
Color[]value

SerializeValue(ref Color32)#

Declaration#
public void SerializeValue(ref Color32 value)
Parameters#
TypeNameDescription
Color32value

SerializeValue(ref Color32[])#

Declaration#
public void SerializeValue(ref Color32[] value)
Parameters#
TypeNameDescription
Color32[]value

SerializeValue(ref Quaternion)#

Declaration#
public void SerializeValue(ref Quaternion value)
Parameters#
TypeNameDescription
Quaternionvalue

SerializeValue(ref Quaternion[])#

Declaration#
public void SerializeValue(ref Quaternion[] value)
Parameters#
TypeNameDescription
Quaternion[]value

SerializeValue(ref Ray)#

Declaration#
public void SerializeValue(ref Ray value)
Parameters#
TypeNameDescription
Rayvalue

SerializeValue(ref Ray[])#

Declaration#
public void SerializeValue(ref Ray[] value)
Parameters#
TypeNameDescription
Ray[]value

SerializeValue(ref Ray2D)#

Declaration#
public void SerializeValue(ref Ray2D value)
Parameters#
TypeNameDescription
Ray2Dvalue

SerializeValue(ref Ray2D[])#

Declaration#
public void SerializeValue(ref Ray2D[] value)
Parameters#
TypeNameDescription
Ray2D[]value

SerializeValue(ref Byte)#

Declaration#
public void SerializeValue(ref byte value)
Parameters#
TypeNameDescription
System.Bytevalue

SerializeValue(ref String, Boolean)#

Declaration#
public void SerializeValue(ref string s, bool oneByteChars = false)
Parameters#
TypeNameDescription
System.Strings
System.BooleanoneByteChars

SerializeValue(ref Vector2)#

Declaration#
public void SerializeValue(ref Vector2 value)
Parameters#
TypeNameDescription
Vector2value

SerializeValue(ref Vector2[])#

Declaration#
public void SerializeValue(ref Vector2[] value)
Parameters#
TypeNameDescription
Vector2[]value

SerializeValue(ref Vector3)#

Declaration#
public void SerializeValue(ref Vector3 value)
Parameters#
TypeNameDescription
Vector3value

SerializeValue(ref Vector3[])#

Declaration#
public void SerializeValue(ref Vector3[] value)
Parameters#
TypeNameDescription
Vector3[]value

SerializeValue(ref Vector4)#

Declaration#
public void SerializeValue(ref Vector4 value)
Parameters#
TypeNameDescription
Vector4value

SerializeValue(ref Vector4[])#

Declaration#
public void SerializeValue(ref Vector4[] value)
Parameters#
TypeNameDescription
Vector4[]value

SerializeValue\<T>(ref T, FastBufferWriter.ForEnums)#

Declaration#
public void SerializeValue<T>(ref T value, FastBufferWriter.ForEnums unused = default(FastBufferWriter.ForEnums))
where T : struct, Enum
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForEnumsunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T, FastBufferWriter.ForNetworkSerializable)#

Declaration#
public void SerializeValue<T>(ref T value, FastBufferWriter.ForNetworkSerializable unused = default(FastBufferWriter.ForNetworkSerializable))
where T : INetworkSerializable, new()
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForNetworkSerializableunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T, FastBufferWriter.ForPrimitives)#

Declaration#
public void SerializeValue<T>(ref T value, FastBufferWriter.ForPrimitives unused = default(FastBufferWriter.ForPrimitives))
where T : struct, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForPrimitivesunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T, FastBufferWriter.ForStructs)#

Declaration#
public void SerializeValue<T>(ref T value, FastBufferWriter.ForStructs unused = default(FastBufferWriter.ForStructs))
where T : struct, INetworkSerializeByMemcpy
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForStructsunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T[], FastBufferWriter.ForEnums)#

Declaration#
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForEnums unused = default(FastBufferWriter.ForEnums))
where T : struct, Enum
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForEnumsunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T[], FastBufferWriter.ForNetworkSerializable)#

Declaration#
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForNetworkSerializable unused = default(FastBufferWriter.ForNetworkSerializable))
where T : INetworkSerializable, new()
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForNetworkSerializableunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T[], FastBufferWriter.ForPrimitives)#

Declaration#
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default(FastBufferWriter.ForPrimitives))
where T : struct, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForPrimitivesunused
Type Parameters#
NameDescription
T

SerializeValue\<T>(ref T[], FastBufferWriter.ForStructs)#

Declaration#
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForStructs unused = default(FastBufferWriter.ForStructs))
where T : struct, INetworkSerializeByMemcpy
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForStructsunused
Type Parameters#
NameDescription
T

SerializeValuePreChecked(ref Color)#

Declaration#
public void SerializeValuePreChecked(ref Color value)
Parameters#
TypeNameDescription
Colorvalue

SerializeValuePreChecked(ref Color[])#

Declaration#
public void SerializeValuePreChecked(ref Color[] value)
Parameters#
TypeNameDescription
Color[]value

SerializeValuePreChecked(ref Color32)#

Declaration#
public void SerializeValuePreChecked(ref Color32 value)
Parameters#
TypeNameDescription
Color32value

SerializeValuePreChecked(ref Color32[])#

Declaration#
public void SerializeValuePreChecked(ref Color32[] value)
Parameters#
TypeNameDescription
Color32[]value

SerializeValuePreChecked(ref Quaternion)#

Declaration#
public void SerializeValuePreChecked(ref Quaternion value)
Parameters#
TypeNameDescription
Quaternionvalue

SerializeValuePreChecked(ref Quaternion[])#

Declaration#
public void SerializeValuePreChecked(ref Quaternion[] value)
Parameters#
TypeNameDescription
Quaternion[]value

SerializeValuePreChecked(ref Ray)#

Declaration#
public void SerializeValuePreChecked(ref Ray value)
Parameters#
TypeNameDescription
Rayvalue

SerializeValuePreChecked(ref Ray[])#

Declaration#
public void SerializeValuePreChecked(ref Ray[] value)
Parameters#
TypeNameDescription
Ray[]value

SerializeValuePreChecked(ref Ray2D)#

Declaration#
public void SerializeValuePreChecked(ref Ray2D value)
Parameters#
TypeNameDescription
Ray2Dvalue

SerializeValuePreChecked(ref Ray2D[])#

Declaration#
public void SerializeValuePreChecked(ref Ray2D[] value)
Parameters#
TypeNameDescription
Ray2D[]value

SerializeValuePreChecked(ref Byte)#

Declaration#
public void SerializeValuePreChecked(ref byte value)
Parameters#
TypeNameDescription
System.Bytevalue

SerializeValuePreChecked(ref String, Boolean)#

Declaration#
public void SerializeValuePreChecked(ref string s, bool oneByteChars = false)
Parameters#
TypeNameDescription
System.Strings
System.BooleanoneByteChars

SerializeValuePreChecked(ref Vector2)#

Declaration#
public void SerializeValuePreChecked(ref Vector2 value)
Parameters#
TypeNameDescription
Vector2value

SerializeValuePreChecked(ref Vector2[])#

Declaration#
public void SerializeValuePreChecked(ref Vector2[] value)
Parameters#
TypeNameDescription
Vector2[]value

SerializeValuePreChecked(ref Vector3)#

Declaration#
public void SerializeValuePreChecked(ref Vector3 value)
Parameters#
TypeNameDescription
Vector3value

SerializeValuePreChecked(ref Vector3[])#

Declaration#
public void SerializeValuePreChecked(ref Vector3[] value)
Parameters#
TypeNameDescription
Vector3[]value

SerializeValuePreChecked(ref Vector4)#

Declaration#
public void SerializeValuePreChecked(ref Vector4 value)
Parameters#
TypeNameDescription
Vector4value

SerializeValuePreChecked(ref Vector4[])#

Declaration#
public void SerializeValuePreChecked(ref Vector4[] value)
Parameters#
TypeNameDescription
Vector4[]value

SerializeValuePreChecked\<T>(ref T, FastBufferWriter.ForEnums)#

Declaration#
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForEnums unused = default(FastBufferWriter.ForEnums))
where T : struct, Enum
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForEnumsunused
Type Parameters#
NameDescription
T

SerializeValuePreChecked\<T>(ref T, FastBufferWriter.ForPrimitives)#

Declaration#
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForPrimitives unused = default(FastBufferWriter.ForPrimitives))
where T : struct, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForPrimitivesunused
Type Parameters#
NameDescription
T

SerializeValuePreChecked\<T>(ref T, FastBufferWriter.ForStructs)#

Declaration#
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForStructs unused = default(FastBufferWriter.ForStructs))
where T : struct, INetworkSerializeByMemcpy
Parameters#
TypeNameDescription
Tvalue
FastBufferWriter.ForStructsunused
Type Parameters#
NameDescription
T

SerializeValuePreChecked\<T>(ref T[], FastBufferWriter.ForEnums)#

Declaration#
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForEnums unused = default(FastBufferWriter.ForEnums))
where T : struct, Enum
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForEnumsunused
Type Parameters#
NameDescription
T

SerializeValuePreChecked\<T>(ref T[], FastBufferWriter.ForPrimitives)#

Declaration#
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default(FastBufferWriter.ForPrimitives))
where T : struct, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForPrimitivesunused
Type Parameters#
NameDescription
T

SerializeValuePreChecked\<T>(ref T[], FastBufferWriter.ForStructs)#

Declaration#
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForStructs unused = default(FastBufferWriter.ForStructs))
where T : struct, INetworkSerializeByMemcpy
Parameters#
TypeNameDescription
T[]value
FastBufferWriter.ForStructsunused
Type Parameters#
NameDescription
T