diff --git a/src/HeboTech.ATLib.TestConsole/HeboTech.ATLib.TestConsole.csproj b/src/HeboTech.ATLib.TestConsole/HeboTech.ATLib.TestConsole.csproj index 1e63760..946f8ff 100644 --- a/src/HeboTech.ATLib.TestConsole/HeboTech.ATLib.TestConsole.csproj +++ b/src/HeboTech.ATLib.TestConsole/HeboTech.ATLib.TestConsole.csproj @@ -6,7 +6,6 @@ - diff --git a/src/HeboTech.ATLib.Tests/HeboTech.ATLib.Tests.csproj b/src/HeboTech.ATLib.Tests/HeboTech.ATLib.Tests.csproj index b596b34..3f66357 100644 --- a/src/HeboTech.ATLib.Tests/HeboTech.ATLib.Tests.csproj +++ b/src/HeboTech.ATLib.Tests/HeboTech.ATLib.Tests.csproj @@ -7,11 +7,13 @@ - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/HeboTech.ATLib/Communication/Communicator.cs b/src/HeboTech.ATLib/Communication/Communicator.cs deleted file mode 100644 index 87d6498..0000000 --- a/src/HeboTech.ATLib/Communication/Communicator.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Buffers; -using System.IO.Pipelines; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace HeboTech.ATLib.Communication -{ - public class Communicator - { - private static ReadOnlyMemory NewLine => new byte[] { (byte)'\r', (byte)'\n' }; - private readonly IDuplexPipe duplexPipe; - - public Communicator(IDuplexPipe duplexPipe) - { - this.duplexPipe = duplexPipe; - } - - public async ValueTask Write(string input, CancellationToken cancellationToken = default) - { - var bytes = Encoding.UTF8.GetBytes(input); - await duplexPipe.Output.WriteAsync(bytes, cancellationToken); - } - - public Task ReadLineAsync(CancellationToken cancellationToken = default) - { - return ReadLineAsync(NewLine, cancellationToken); - } - - public async Task ReadLineAsync(ReadOnlyMemory delimiter, CancellationToken cancellationToken = default) - { - while (true) - { - ReadResult result = await duplexPipe.Input.ReadAsync(cancellationToken); - ReadOnlySequence buffer = result.Buffer; - - try - { - // Process all messages from the buffer, modifying the input buffer on each - // iteration. - while (TryParseLine(ref buffer, delimiter.Span, out ReadOnlySequence line)) - { - return Encoding.UTF8.GetString(line.ToArray()); - } - - // There's no more data to be processed. - if (result.IsCompleted) - { - //if (buffer.Length > 0) - //{ - // // The message is incomplete and there's no more data to process. - // throw new InvalidDataException("Incomplete message."); - //} - break; - } - } - finally - { - // Since all messages in the buffer are being processed, you can use the - // remaining buffer's Start and End position to determine consumed and examined. - duplexPipe.Input.AdvanceTo(buffer.Start, buffer.Start); - } - } - - return default; - } - - private static bool TryParseLine(ref ReadOnlySequence buffer, ReadOnlySpan delimiter, out ReadOnlySequence line) - { - var reader = new SequenceReader(buffer); - - if (reader.TryReadTo(out line, delimiter)) - { - buffer = buffer.Slice(reader.Position); - return true; - } - - line = default; - return false; - } - } -} diff --git a/src/HeboTech.ATLib/HeboTech.ATLib.csproj b/src/HeboTech.ATLib/HeboTech.ATLib.csproj index 282d160..e254efc 100644 --- a/src/HeboTech.ATLib/HeboTech.ATLib.csproj +++ b/src/HeboTech.ATLib/HeboTech.ATLib.csproj @@ -21,11 +21,7 @@ - - - -