| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.IO.Pipelines; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using Microsoft.Extensions.Logging.Abstractions; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public static class MsmqDecodeHelper |
| | | 11 | | { |
| | | 12 | | private const int DefaultMaxViaSize = 2048; |
| | | 13 | | private const int DefaultMaxContentTypeSize = 256; |
| | | 14 | | |
| | | 15 | | public static async Task DecodeTransportDatagram(PipeReader pipeReader) |
| | | 16 | | { |
| | 0 | 17 | | var serverModeDecoder = new ServerModeDecoder(NullLogger.Instance); |
| | 0 | 18 | | await serverModeDecoder.ReadModeAsync(pipeReader); |
| | 0 | 19 | | var decoder = |
| | 0 | 20 | | new ServerSingletonSizedDecoder(DefaultMaxViaSize, DefaultMaxContentTypeSize, NullLogger.Instance); |
| | 0 | 21 | | var readResult = await pipeReader.ReadAsync(); |
| | 0 | 22 | | if (readResult.IsCompleted) |
| | | 23 | | { |
| | 0 | 24 | | return; |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | var buffer = readResult.Buffer; |
| | | 28 | | |
| | | 29 | | try |
| | | 30 | | { |
| | | 31 | | do |
| | | 32 | | { |
| | 0 | 33 | | if (buffer.Length <= 0) |
| | | 34 | | { |
| | 0 | 35 | | throw decoder.CreatePrematureEOFException(); |
| | | 36 | | } |
| | | 37 | | |
| | 0 | 38 | | int decoded = decoder.Decode(buffer); |
| | 0 | 39 | | buffer = buffer.Slice(decoded); |
| | 0 | 40 | | } while (decoder.CurrentState != ServerSingletonSizedDecoder.State.Start); |
| | | 41 | | |
| | 0 | 42 | | pipeReader.AdvanceTo(buffer.Start); |
| | 0 | 43 | | } |
| | 0 | 44 | | catch (ProtocolException ex) |
| | | 45 | | { |
| | 0 | 46 | | throw new MsmqPoisonMessageException(0, ex); |
| | | 47 | | } |
| | 0 | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |