protected override ValueTask <Memory <byte> > FillSendBufferAsync(string commandPackage, IMemoryOwner <byte> sendBuffer)
        {
            byte[] package        = Encoding.UTF8.GetBytes(commandPackage);
            int    encryptedCount = EncryptionHelpers.EncryptData(package.AsMemory(), sendBuffer.Memory, _encryptionKey);

            return(new ValueTask <Memory <byte> >(sendBuffer.Memory.Slice(0, encryptedCount)));
        }
        public void EncryptDecrypt_NonAllocating_Works()
        {
            byte[] key  = EncryptionHelpers.CreateEncryptionKey(128);
            string data = "Hello, Encryption World!";

            byte[] plaintext = System.Text.Encoding.UTF8.GetBytes(data);
            using (IMemoryOwner <byte> encrypted = MemoryPool <byte> .Shared.Rent(128))
                using (IMemoryOwner <byte> decrypted = MemoryPool <byte> .Shared.Rent(128))
                {
                    int encryptedCount = EncryptionHelpers.EncryptData(plaintext.AsMemory(), encrypted.Memory, key);
                    int decryptedCount = EncryptionHelpers.DecryptData(encrypted.Memory.Slice(0, encryptedCount), decrypted.Memory, key);
                    Assert.Equal(plaintext.Length, decryptedCount);

                    string final = System.Text.Encoding.UTF8.GetString(decrypted.Memory.Span.Slice(0, decryptedCount));
                    Assert.Equal(data, final);
                }
        }