public override async Task ReadTaggedData(ITransport transport, Action <IProtocolReader, string, ITransportMetadata> handler)
        {
            var receivedData = await transport.ReceiveTagged();

            var buffer = new MemoryStream(receivedData.Message.Payload);
            var reader = new MessagePackProtocolReader(buffer);

            handler(reader, receivedData.Id, receivedData.Message.Metadata);
        }
        public override async Task <TResult> ReadData <TResult>(ITransport transport, string messageId, Func <IProtocolReader, ITransportMetadata, TResult> handler)
        {
            var receivedData = await transport.Receive(messageId);

            var buffer = new MemoryStream(receivedData.Payload);
            var reader = new MessagePackProtocolReader(buffer);

            var result = handler(reader, receivedData.Metadata);

            return(result);
        }
        public override async Task <Func <Func <IProtocolReader, ITransportMetadata, TResult>, Task <TResult> > > WriteAndReadData <TResult>(ITransport transport, ITransportMetadata metadata, Action <IProtocolWriter> handler)
        {
            Func <Task <TransportMessage> > receiveHandler;

            using (var buffer = new MemoryStream())
            {
                var writer = new MessagePackProtocolWriter(buffer);
                handler(writer);

                buffer.Position = 0;
                var data = buffer.ToArray();
                receiveHandler = await transport.SendAndReceive(new TransportMessage(data, VolatileTransportMetadata.FromMetadata(metadata)));
            }

            return(new Func <Func <IProtocolReader, ITransportMetadata, TResult>, Task <TResult> >(async(readHandler) => {
                var receivedData = await receiveHandler();

                var buffer = new MemoryStream(receivedData.Payload);
                var reader = new MessagePackProtocolReader(buffer);

                return readHandler(reader, receivedData.Metadata);
            }));
        }