Refactor: Streamline code formatting, introduce cleaner structure, and remove unused Class1. Add .editorconfig for consistent coding style.
This commit is contained in:
@@ -8,10 +8,7 @@ public static class IpcProtocol
|
||||
// Keep the prototype safe from accidental runaway memory usage.
|
||||
public const int DefaultMaxFrameBytes = 4 * 1024 * 1024; // 4 MiB
|
||||
|
||||
public static async Task WriteFrameAsync(
|
||||
Stream stream,
|
||||
IpcFrame frame,
|
||||
CancellationToken cancellationToken = default)
|
||||
public static async Task WriteFrameAsync(Stream stream, IpcFrame frame, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Always include a timestamp if the sender didn't set one.
|
||||
if (frame.Timestamp is null)
|
||||
@@ -32,10 +29,7 @@ public static class IpcProtocol
|
||||
await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<IpcFrame?> ReadFrameAsync(
|
||||
Stream stream,
|
||||
int maxFrameBytes = DefaultMaxFrameBytes,
|
||||
CancellationToken cancellationToken = default)
|
||||
public static async Task<IpcFrame?> ReadFrameAsync(Stream stream, int maxFrameBytes = DefaultMaxFrameBytes, CancellationToken cancellationToken = default)
|
||||
{
|
||||
byte[] header = ArrayPool<byte>.Shared.Rent(4);
|
||||
try
|
||||
@@ -50,10 +44,7 @@ public static class IpcProtocol
|
||||
throw new EndOfStreamException("Unexpected end of stream while reading frame header.");
|
||||
}
|
||||
|
||||
int len = header[0]
|
||||
| (header[1] << 8)
|
||||
| (header[2] << 16)
|
||||
| (header[3] << 24);
|
||||
int len = header[0] | (header[1] << 8) | (header[2] << 16) | (header[3] << 24);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
@@ -106,18 +97,12 @@ public static class IpcProtocol
|
||||
return element.Value.Deserialize<T>(IpcJson.Options);
|
||||
}
|
||||
|
||||
private static async Task<int> ReadExactOrEofAsync(
|
||||
Stream stream,
|
||||
byte[] buffer,
|
||||
int offset,
|
||||
int count,
|
||||
CancellationToken cancellationToken)
|
||||
private static async Task<int> ReadExactOrEofAsync(Stream stream, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
int total = 0;
|
||||
while (total < count)
|
||||
{
|
||||
int n = await stream.ReadAsync(buffer.AsMemory(offset + total, count - total), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
int n = await stream.ReadAsync(buffer.AsMemory(offset + total, count - total), cancellationToken).ConfigureAwait(false);
|
||||
if (n == 0)
|
||||
{
|
||||
return total; // EOF
|
||||
|
||||
Reference in New Issue
Block a user