private static async Task <ServerInitMessage> ParseServerInitAsync(PipeReader reader, CancellationToken token)
        {
            var result = await reader.ReadMinBytesAsync(24, token);

            var messageBytes = result.Buffer.Slice(0, 24).ToArray();

            reader.AdvanceTo(result.Buffer.GetPosition(24));
            var nameLength = BinaryPrimitives.ReadUInt32BigEndian(messageBytes.AsSpan(20, 4));
            var nameBytes  = await reader.ReadBytesAsync((int)nameLength, token);

            return(new ServerInitMessage(
                       BinaryPrimitives.ReadUInt16BigEndian(messageBytes.AsSpan(0, 2)),
                       BinaryPrimitives.ReadUInt16BigEndian(messageBytes.AsSpan(2, 2)),
                       new PixelFormat()
            {
                BitsPerPixel = messageBytes[4],
                Depth = messageBytes[5],
                BigEndianFlag = messageBytes[6],
                TrueColorFlag = messageBytes[7],
                RedMax = BinaryPrimitives.ReadUInt16BigEndian(messageBytes.AsSpan(8, 2)),
                GreenMax = BinaryPrimitives.ReadUInt16BigEndian(messageBytes.AsSpan(10, 2)),
                BlueMax = BinaryPrimitives.ReadUInt16BigEndian(messageBytes.AsSpan(12, 2)),
                RedShift = messageBytes[14],
                GreenShift = messageBytes[15],
                BlueShift = messageBytes[16]
            },
                       Encoding.UTF8.GetString(nameBytes)));
        }
 private static Task <byte[]> ParseSecurityChallengeAsync(PipeReader reader, CancellationToken token)
 {
     return(reader.ReadBytesAsync(16, token));
 }