From 953318e783cbbf61113c787ff116ebf28a442e69 Mon Sep 17 00:00:00 2001 From: laolarou Date: Fri, 1 Dec 2023 23:55:15 -0800 Subject: [PATCH] add helper function --- .../Helpers/SessionExtensions.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Hive.Both.General/Helpers/SessionExtensions.cs diff --git a/Hive.Both.General/Helpers/SessionExtensions.cs b/Hive.Both.General/Helpers/SessionExtensions.cs new file mode 100644 index 0000000..35015f1 --- /dev/null +++ b/Hive.Both.General/Helpers/SessionExtensions.cs @@ -0,0 +1,22 @@ +using Hive.Codec.Abstractions; +using Hive.Network.Shared.Session; +using System.IO; +using System.Threading.Tasks; +using System.Threading; + +namespace Hive.Both.General.Helpers +{ + public static class SessionExtensions + { + public static async Task SendAsync( + this AbstractSession session, + IPacketCodec codec, + T message, + CancellationToken cancellationToken) + { + using var ms = new MemoryStream(); + codec.Encode(message, ms); + await session.SendAsync(ms, cancellationToken); + } + } +} \ No newline at end of file