Ejemplo n.º 1
0
        public async Task ReceiveAsync(
            PipeWriter writer,
            CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested &&
                   !Incoming.Any())
            {
                await Task.Delay(100, cancellationToken);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            GenericOperationMessage message = Incoming.Dequeue();
            string json = JsonConvert.SerializeObject(message);

            byte[] buffer = Encoding.UTF8.GetBytes(json);

            Memory <byte> memory = writer.GetMemory(buffer.Length);

            for (int i = 0; i < buffer.Length; i++)
            {
                memory.Span[i] = buffer[i];
            }

            writer.Advance(buffer.Length);

            await writer
            .FlushAsync(cancellationToken)
            .ConfigureAwait(false);
        }
        public async Task ReceiveMessageAsync(
            Stream messageStream,
            CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested &&
                   !Incoming.Any())
            {
                await Task.Delay(100, cancellationToken);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            GenericOperationMessage message = Incoming.Dequeue();
            string json = JsonConvert.SerializeObject(message);

            byte[] buffer = Encoding.UTF8.GetBytes(json);

            messageStream.Write(buffer, 0, buffer.Length);
        }
Ejemplo n.º 3
0
 public byte Read()
 {
     return(Incoming.Count > 0 ? Incoming.Dequeue() : STOP_BIT);
 }