/// <summary> /// Queues a packet to be sent. /// </summary> /// <param name="channelId">Destination channel Id</param> /// <param name="packet">Packet to be queued</param> /// <remarks> /// This method will destroy the packet if its <see cref="ENetPacket.ReferenceCount"/> is zero /// </remarks> public void Send(byte channelId, ENetPacket packet) { ThrowIfNull(); if (packet.IsNull) { throw new ArgumentNullException(nameof(packet)); } if (LibENet.PeerSend(m_Native, channelId, packet.GetNativePointer()) < 0) { ThrowHelper.ThrowENetPeerSendFailed(); } }
/// <summary> /// Tries to retrieve user-data from <see cref="ENetPeer"/> of given type. /// </summary> /// <typeparam name="TData">The data type.</typeparam> /// <param name="packet">The packet that holds the user-data.</param> /// <param name="data">The result user-data.</param> /// <returns>Returns true if the user-data found; otherwise false.</returns> /// <remarks> /// If the data type differs from what was supplied to <see cref="SetUserData{TData}(ENetPacket, TData)"/> then return value becomes false. /// </remarks> public static bool TryGetUserData <TData>(this ENetPacket packet, out TData data) { var native = packet.GetNativePointer(); return(TryGetUserData(native->UserData, out data)); }
/// <summary> /// An extension method for clearing the user-data. /// </summary> /// <param name="packet">The packet that holds the user-data.</param> public static void UnsetUserData(this ENetPacket packet) { var native = packet.GetNativePointer(); UnsetUserData(ref native->UserData); }
/// <summary> /// Sets or overwrites the user-data of the given packet. /// </summary> /// <typeparam name="TData">The user-data type.</typeparam> /// <param name="packet">The packet to store user-data into it's <see cref="ENetPacket.UserData"/> field.</param> /// <param name="data">The user-data.</param> public static void SetUserData <TData>(this ENetPacket packet, TData data) { var native = packet.GetNativePointer(); SetUserData(ref native->UserData, data); }