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

MessageToBytes() public method

Runs the interceptor on the input and returns the output as a byte array. Used to serialize a message stream.
public MessageToBytes ( byte input ) : MessageInterceptorResult
input byte The input.
return MessageInterceptorResult
        public MessageInterceptorResult MessageToBytes(byte[] input)
        {
            Guard.NotNull(() => input, input);
            if (input.Length < _configuration.MiniumSize)
            {
                return new MessageInterceptorResult(input, false, GetType());
            }
            var outStream = SharedMemoryStream.StreamManager.GetStream("gzip-compress");
            using (var gZipStream = new GZipStream(outStream, CompressionMode.Compress, true))
            using (var memoryStream = new MemoryStream(input))
                memoryStream.CopyTo(gZipStream);
            return new MessageInterceptorResult(outStream.ToArray(), true, GetType());
        }

Usage Example

        private void TestGzipNoCompression(string body, int length)
        {
            var configuration = new GZipMessageInterceptorConfiguration {MiniumSize = length};
            var gzip = new GZipMessageInterceptor(configuration);

            var serialization = gzip.MessageToBytes(Encoding.UTF8.GetBytes(body));
            Assert.Equal(false, serialization.AddToGraph);
            Assert.Equal(body, Encoding.UTF8.GetString(serialization.Output));
        }
All Usage Examples Of DotNetWorkQueue.Interceptors.GZipMessageInterceptor::MessageToBytes