DotNetWorkQueue.Interceptors.GZipMessageInterceptor.BytesToMessage C# (CSharp) Method

BytesToMessage() public method

Runs the interceptor on the input and returns the output as a byte array. Used to re-construct a message stream.
public BytesToMessage ( byte input ) : byte[]
input byte The input.
return byte[]
        public byte[] BytesToMessage(byte[] input)
        {
            Guard.NotNull(() => input, input);
            var memoryStream = new MemoryStream(input);
            using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress, true))
            using (var destination = SharedMemoryStream.StreamManager.GetStream("gzip - uncompressed - output"))
            {
                gZipStream.CopyTo(destination);
                return destination.ToArray();
            }
        }
    }

Usage Example

        private void TestGzip(string body)
        {
            var configuration = new GZipMessageInterceptorConfiguration();
            var gzip = new GZipMessageInterceptor(configuration);

            var serialization = gzip.MessageToBytes(Encoding.UTF8.GetBytes(body));
            if (serialization.AddToGraph)
            {
                var actual = Encoding.UTF8.GetString(gzip.BytesToMessage(serialization.Output));
                Assert.Equal(body, actual);
            }
            else
            {
                Assert.Equal(body, Encoding.UTF8.GetString(serialization.Output));
            }
        }