Skip to content

Commit

Permalink
nats-io#636 - JetStream Batch Get Client support
Browse files Browse the repository at this point in the history
* Added eod parse in headers
  • Loading branch information
Ivandemidov00 committed Nov 23, 2024
1 parent 075f749 commit 95a495f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/NATS.Client.Core/NatsHeaderParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ private bool TryParseHeaderLine(ReadOnlySpan<byte> headerLine, NatsHeaders heade
headers.Message = NatsHeaders.Messages.MessageSizeExceedsMaxBytes;
headers.MessageText = NatsHeaders.MessageMessageSizeExceedsMaxBytesStr;
}
else if (headerLine.SequenceEqual(NatsHeaders.MessageEobCode))
{
headers.Message = NatsHeaders.Messages.EobCode;
headers.MessageText = NatsHeaders.MessageEobCodeStr;
}
else
{
headers.Message = NatsHeaders.Messages.Text;
Expand Down
5 changes: 5 additions & 0 deletions src/NATS.Client.Core/NatsHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum Messages
NoMessages,
RequestTimeout,
MessageSizeExceedsMaxBytes,
EobCode,
}

// Uses C# compiler's optimization for static byte[] data
Expand Down Expand Up @@ -56,6 +57,10 @@ public enum Messages
internal static ReadOnlySpan<byte> MessageMessageSizeExceedsMaxBytes => new byte[] { 77, 101, 115, 115, 97, 103, 101, 32, 83, 105, 122, 101, 32, 69, 120, 99, 101, 101, 100, 115, 32, 77, 97, 120, 66, 121, 116, 101, 115 };
internal static readonly string MessageMessageSizeExceedsMaxBytesStr = "Message Size Exceeds MaxBytes";

// EOB
internal static ReadOnlySpan<byte> MessageEobCode => new byte[] { 69, 79, 66 };
internal static readonly string MessageEobCodeStr = "EOB";

private static readonly string[] EmptyKeys = Array.Empty<string>();
private static readonly StringValues[] EmptyValues = Array.Empty<StringValues>();

Expand Down
1 change: 1 addition & 0 deletions tests/NATS.Client.CoreUnit.Tests/NatsHeaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void ParserTests()
[InlineData("Request Timeout", NatsHeaders.Messages.RequestTimeout)]
[InlineData("Message Size Exceeds MaxBytes", NatsHeaders.Messages.MessageSizeExceedsMaxBytes)]
[InlineData("test message", NatsHeaders.Messages.Text)]
[InlineData("EOB", NatsHeaders.Messages.EobCode)]
public void ParserMessageEnumTests(string message, NatsHeaders.Messages result)
{
var parser = new NatsHeaderParser(Encoding.UTF8);
Expand Down

0 comments on commit 95a495f

Please sign in to comment.