-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix batch collection massages through sockets (#7265)
- Loading branch information
1 parent
bab117f
commit 0315f4a
Showing
3 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Nethermind/Nethermind.JsonRpc.Test/MemoryMessageStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Nethermind.Sockets; | ||
|
||
namespace Nethermind.JsonRpc.Test; | ||
|
||
public class MemoryMessageStream : MemoryStream, IMessageBorderPreservingStream | ||
{ | ||
private static readonly byte Delimiter = Convert.ToByte('\n'); | ||
|
||
public Task<ReceiveResult?> ReceiveAsync(ArraySegment<byte> buffer) | ||
{ | ||
int read = Read(buffer.AsSpan()); | ||
return Task.FromResult<ReceiveResult?>(new ReceiveResult | ||
{ | ||
Read = read, | ||
EndOfMessage = read > 0 && buffer[read - 1] == Delimiter | ||
}); | ||
} | ||
|
||
public Task<int> WriteEndOfMessageAsync() | ||
{ | ||
WriteByte(Delimiter); | ||
return Task.FromResult(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters