Exemplo n.º 1
0
        /// <summary>
        /// Send bytes through noisy channel
        /// </summary>
        /// <param name="bytes">Text to send</param>
        /// <param name="channel">Noisy channel</param>
        /// <returns>Resulting bytes together with error information</returns>
        public static async Task <ByteArrayResult> SendBytes(byte[] bytes, ICommunicationChannel channel)
        {
            var bits = new BitStream(bytes);
            var bitsAfterTransmission = await Task.FromResult(channel.Transmit(bits));

            var result = await Task.FromResult(bitsAfterTransmission.ToByteArray());

            return(new ByteArrayResult
            {
                Errors = bits.Difference(bitsAfterTransmission),
                Result = result
            });
        }