using System; using Unity.Collections; using UnityEngine; namespace Unity.Netcode { /// /// Interface for an implementation of one side of a two-way serializer /// public interface IReaderWriter { /// /// Check whether this implementation is a "reader" - if it's been constructed to deserialize data /// bool IsReader { get; } /// /// Check whether this implementation is a "writer" - if it's been constructed to serialize data /// bool IsWriter { get; } /// /// Get the underlying FastBufferReader struct. /// Only valid when IsReader == true /// /// underlying FastBufferReader FastBufferReader GetFastBufferReader(); /// /// Get the underlying FastBufferWriter struct. /// Only valid when IsWriter == true /// /// underlying FastBufferWriter FastBufferWriter GetFastBufferWriter(); /// /// Read or write a string /// /// The value to read/write /// If true, characters will be limited to one-byte ASCII characters void SerializeValue(ref string s, bool oneByteChars = false); /// /// Read or write a single byte /// /// The value to read/write void SerializeValue(ref byte value); /// /// 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. /// /// The value to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable, IEquatable; /// /// 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. /// /// The values to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable, IEquatable; /// /// Read or write an enum value /// /// The value to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum; /// /// Read or write an array of enum values /// /// The value to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum; /// /// Read or write a struct value implementing ISerializeByMemcpy /// /// The value to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy; /// /// Read or write an array of struct values implementing ISerializeByMemcpy /// /// The values to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy; /// /// Read or write a struct or class value implementing INetworkSerializable /// /// The value to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new(); /// /// Read or write an array of struct or class values implementing INetworkSerializable /// /// The values to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new(); /// /// Read or write a FixedString value /// /// The value to read/write /// An unused parameter used for enabling overload resolution based on generic constraints /// The type being serialized void SerializeValue(ref T value, FastBufferWriter.ForFixedStrings unused = default) where T : unmanaged, INativeList, IUTF8Bytes; /// /// Read or write a Vector2 value /// /// The value to read/write void SerializeValue(ref Vector2 value); /// /// Read or write an array of Vector2 values /// /// The values to read/write void SerializeValue(ref Vector2[] value); /// /// Read or write a Vector3 value /// /// The value to read/write void SerializeValue(ref Vector3 value); /// /// Read or write an array of Vector3 values /// /// The values to read/write void SerializeValue(ref Vector3[] value); /// /// Read or write a Vector2Int value /// /// The value to read/write void SerializeValue(ref Vector2Int value); /// /// Read or write an array of Vector2Int values /// /// The values to read/write void SerializeValue(ref Vector2Int[] value); /// /// Read or write a Vector3Int value /// /// The value to read/write void SerializeValue(ref Vector3Int value); /// /// Read or write an array of Vector3Int values /// /// The values to read/write void SerializeValue(ref Vector3Int[] value); /// /// Read or write a Vector4 value /// /// The value to read/write void SerializeValue(ref Vector4 value); /// /// Read or write an array of Vector4 values /// /// The values to read/write void SerializeValue(ref Vector4[] value); /// /// Read or write a Quaternion value /// /// The value to read/write void SerializeValue(ref Quaternion value); /// /// Read or write an array of Quaternion values /// /// The values to read/write void SerializeValue(ref Quaternion[] value); /// /// Read or write a Color value /// /// The value to read/write void SerializeValue(ref Color value); /// /// Read or write an array of Color values /// /// The values to read/write void SerializeValue(ref Color[] value); /// /// Read or write a Color32 value /// /// The value to read/write void SerializeValue(ref Color32 value); /// /// Read or write an array of Color32 values /// /// The values to read/write void SerializeValue(ref Color32[] value); /// /// Read or write a Ray value /// /// The value to read/write void SerializeValue(ref Ray value); /// /// Read or write an array of Ray values /// /// The values to read/write void SerializeValue(ref Ray[] value); /// /// Read or write a Ray2D value /// /// The value to read/write void SerializeValue(ref Ray2D value); /// /// Read or write an array of Ray2D values /// /// The values to read/write void SerializeValue(ref Ray2D[] value); /// /// Read or write a NetworkSerializable value. /// SerializeValue() is the preferred method to do this - this is provided for backward compatibility only. /// /// The value to read/write /// The network serializable type void SerializeNetworkSerializable(ref T value) where T : INetworkSerializable, new(); /// /// 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. /// /// /// bool PreCheck(int amount); /// /// 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. /// /// The value to read/write /// If true, characters will be limited to one-byte ASCII characters void SerializeValuePreChecked(ref string s, bool oneByteChars = false); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref byte value); /// /// 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. /// /// The type being serialized /// The value to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable, IEquatable; /// /// 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. /// /// The type being serialized /// The values to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable, IEquatable; /// /// 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. /// /// The type being serialized /// The value to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum; /// /// 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. /// /// The type being serialized /// The values to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum; /// /// 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. /// /// The type being serialized /// The value to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy; /// /// 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. /// /// The type being serialized /// The values to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy; /// /// 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. /// /// The type being serialized /// The value to read/write /// An unused parameter that can be used for enabling overload resolution based on generic constraints void SerializeValuePreChecked(ref T value, FastBufferWriter.ForFixedStrings unused = default) where T : unmanaged, INativeList, IUTF8Bytes; /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector2 value); /// /// 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. /// /// The values to read/write void SerializeValuePreChecked(ref Vector2[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector3 value); /// /// 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. /// /// The values to read/write void SerializeValuePreChecked(ref Vector3[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector2Int value); /// /// 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. /// /// The values to read/write void SerializeValuePreChecked(ref Vector2Int[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector3Int value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector3Int[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector4 value); /// /// Serialize a Vector4Array, "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. /// /// The value to read/write void SerializeValuePreChecked(ref Vector4[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Quaternion value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Quaternion[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Color value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Color[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Color32 value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Color32[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Ray value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Ray[] value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Ray2D value); /// /// 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. /// /// The value to read/write void SerializeValuePreChecked(ref Ray2D[] value); } }