Struct BufferSerializer<TReaderWriter>
Two-way serializer wrapping FastBufferReader or FastBufferWriter.
Implemented as a ref struct to help enforce the requirement that the BufferSerializer cannot outlive the FBR/FBW it wraps or using it will cause a crash
BufferSerializer doesn't wrap 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
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public ref struct BufferSerializer<TReaderWriter> where TReaderWriter : IReaderWriter
Type Parameters
Name | Description |
---|---|
TReaderWriter | The implementation struct |
Properties
Name | Description |
---|---|
Is |
Check if the contained implementation is a reader |
Is |
Check if the contained implementation is a writer |
Methods
Name | Description |
---|---|
Get |
Retrieves the FastBufferReader instance. Only valid if IsReader = true, throws InvalidOperationException otherwise. |
Get |
Retrieves the FastBufferWriter instance. Only valid if IsWriter = true, throws InvalidOperationException otherwise. |
Pre |
Performs an advance check to ensure space is available to read/write one or more values. This provides a performance benefit for serializing multiple values using the SerializeValuePreChecked methods. But note that the benefit is small and only likely to be noticeable if serializing a very large number of items. |
Serialize |
Read or write a NetworkSerializable value. SerializeValue() is the preferred method to do this - this is provided for backward compatibility only. |
Serialize |
Read or write a single byte |
Serialize |
Read or write a string |
Serialize |
Read or write a Color32 value |
Serialize |
Read or write an array of Color32 values |
Serialize |
Read or write a Color value |
Serialize |
Read or write an array of Color values |
Serialize |
Read or write a Quaternion value |
Serialize |
Read or write an array of Quaternion values |
Serialize |
Read or write a Ray2D value |
Serialize |
Read or write an array of Ray2D values |
Serialize |
Read or write a Ray value |
Serialize |
Read or write an array of Ray values |
Serialize |
Read or write a Vector2 value |
Serialize |
Read or write a Vector2Int value |
Serialize |
Read or write an array of Vector2Int values |
Serialize |
Read or write an array of Vector2 values |
Serialize |
Read or write a Vector3 value |
Serialize |
Read or write a Vector3Int value |
Serialize |
Read or write an array of Vector3Int values |
Serialize |
Read or write an array of Vector3 values |
Serialize |
Read or write a Vector4 value |
Serialize |
Read or write an array of Vector4 values |
Serialize |
Serialize a byte, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a string, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Color32, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Color32 array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Color, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Color array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Quaternion, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Quaternion array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Ray2D, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Ray2D array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Ray, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Ray array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector2, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector2Int, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector2Int array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector2 array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector3, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector3Int, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector3Int array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector3 array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector4, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a Vector4 array, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a NativeArray of structs, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize an enum, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a FixedString, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a primitive, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize a struct, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize an array of enums, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize an array of primitives, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Serialize an array of structs, "pre-checked", which skips buffer checks. In debug and editor builds, a check is made to ensure you've called "PreCheck" before calling this. In release builds, calling this without calling "PreCheck" may read or write past the end of the buffer, which will cause memory corruption and undefined behavior. |
Serialize |
Read or write a NativeArray of FixedString values |
Serialize |
Read or write a NativeArray of struct values implementing ISerializeByMemcpy |
Serialize |
Read or write an enum value |
Serialize |
Read or write a FixedString value |
Serialize |
Read or write a struct or class value implementing INetworkSerializable |
Serialize |
Read or write a primitive value (int, bool, etc) Accepts any value that implements the given interfaces, but is not guaranteed to work correctly on values that are not primitives. |
Serialize |
Read or write a struct value implementing ISerializeByMemcpy |
Serialize |
Read or write an array of enum values |
Serialize |
Read or write an array of struct or class values implementing INetworkSerializable |
Serialize |
Read or write an array of primitive values (int, bool, etc) Accepts any value that implements the given interfaces, but is not guaranteed to work correctly on values that are not primitives. |
Serialize |
Read or write an array of struct values implementing ISerializeByMemcpy |