예제 #1
0
        public static void WriteMessage <T>(Stream stream, T message, HttpContextServerCallContext?callContext = null)
            where T : class, IMessage
        {
            var pipeWriter = PipeWriter.Create(stream);

            PipeExtensions.WriteMessageAsync(pipeWriter, message, callContext ?? HttpContextServerCallContextHelper.CreateServerCallContext(), (r, c) => c.Complete(r.ToByteArray()), canFlush: true).GetAwaiter().GetResult();
        }
        public static void WriteMessage <T>(Stream stream, T message, string?compressionEncoding = null, List <ICompressionProvider>?compressionProviders = null) where T : class, IMessage
        {
            compressionProviders = compressionProviders ?? new List <ICompressionProvider>
            {
                new GzipCompressionProvider(CompressionLevel.Fastest)
            };

            var resolvedProviders = ResolveProviders(compressionProviders);

            var pipeWriter = PipeWriter.Create(stream);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers[GrpcProtocolConstants.MessageAcceptEncodingHeader] = compressionEncoding;

            var serverCallContext = HttpContextServerCallContextHelper.CreateServerCallContext(
                httpContext: httpContext,
                serviceOptions: new GrpcServiceOptions
            {
                ResponseCompressionAlgorithm = compressionEncoding,
                ResolvedCompressionProviders = resolvedProviders
            });

            serverCallContext.Initialize();

            PipeExtensions.WriteMessageAsync(pipeWriter, message, serverCallContext, (r, c) => c.Complete(r.ToByteArray()), canFlush: true).GetAwaiter().GetResult();
            stream.Seek(0, SeekOrigin.Begin);
        }
예제 #3
0
        public static void WriteMessage <T>(Stream stream, T message) where T : IMessage
        {
            var messageData = message.ToByteArray();

            var pipeWriter = PipeWriter.Create(stream);

            PipeExtensions.WriteMessageAsync(pipeWriter, messageData, TestServerCallContext, flush: true).GetAwaiter().GetResult();
        }
        public static void WriteMessage <T>(Stream stream, T message) where T : IMessage
        {
            var messageData = message.ToByteArray();

            var pipeWriter = new StreamPipeWriter(stream);

            PipeExtensions.WriteMessageAsync(pipeWriter, messageData, TestServiceOptions, flush: true).GetAwaiter().GetResult();
        }
예제 #5
0
        public static void WriteMessage(Stream stream, byte[] message)
        {
            var pipeWriter = new StreamPipeWriter(stream);

            PipeExtensions.WriteMessageAsync(pipeWriter, message, flush: true).GetAwaiter().GetResult();
        }
예제 #6
0
        public static void WriteMessage <T>(Stream stream, T message) where T : IMessage
        {
            var pipeWriter = PipeWriter.Create(stream);

            PipeExtensions.WriteMessageAsync(pipeWriter, message, TestServerCallContext, (r, c) => c.Complete(r.ToByteArray()), canFlush: true).GetAwaiter().GetResult();
        }