Example #1
0
        public static async Task <Message> DeSerializeAsync(string contentType, string formatterType, byte[] buffer, int offset, int count, IMessageFactory factory)
        {
            if (!IsMessageContentType(contentType))
            {
                return(null);
            }

            Message    message   = factory.Create(GetMessageType(contentType));
            IFormatter formatter = new FormatterFactory().Create(formatterType);

            using (MemoryStream messageStream = new MemoryStream()) {
                await messageStream.WriteAsync(buffer, 0, count).ConfigureAwait(false);

                messageStream.Flip();

                formatter.Attach(messageStream);
                await message.DeserializeAsync(formatter).ConfigureAwait(false);

                return(message);
            }
        }