-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flags to NatsMsg and JetStream Request #652
Draft
mtmk
wants to merge
13
commits into
main
Choose a base branch
from
nats-msg-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4b231fc
Add flags to NatsMsg
mtmk d8c80f9
Code comments for msg size
mtmk be0334f
Format
mtmk dfa7d03
Fix warnings
mtmk d68ec5b
Keep 503 header
mtmk 93c3ab7
Format
mtmk a4517e0
JetStream TryJSRequestAsync
mtmk 2f8e90e
Format
mtmk a64fd08
Fix tests
mtmk 71ed9d9
Refactor JetStream method results to use NatsResult
mtmk 7e5b699
Refactor NatsMsg size and flags handling in tests and class
mtmk 643e3d5
Refactor JSON document deserialization
mtmk 2f9e815
Refactor NatsJSContext error handling logic.
mtmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,38 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace NATS.Client.Core; | ||
|
||
public readonly struct NatsResult<T> | ||
{ | ||
private readonly T? _value; | ||
private readonly Exception? _error; | ||
|
||
public NatsResult(T value) | ||
{ | ||
_value = value; | ||
_error = null; | ||
} | ||
|
||
public NatsResult(Exception error) | ||
{ | ||
_value = default; | ||
_error = error; | ||
} | ||
|
||
public T Value => _value ?? ThrowValueIsNotSetException(); | ||
|
||
public Exception Error => _error ?? ThrowErrorIsNotSetException(); | ||
|
||
public bool Success => _error == null; | ||
|
||
public static implicit operator NatsResult<T>(T value) => new(value); | ||
|
||
public static implicit operator NatsResult<T>(Exception error) => new(error); | ||
|
||
private static T ThrowValueIsNotSetException() => throw CreateInvalidOperationException("Result value is not set"); | ||
|
||
private static Exception ThrowErrorIsNotSetException() => throw CreateInvalidOperationException("Result error is not set"); | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static Exception CreateInvalidOperationException(string message) => new InvalidOperationException(message); | ||
} |
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
41 changes: 0 additions & 41 deletions
41
src/NATS.Client.JetStream/Internal/NatsJSErrorAwareJsonSerializer.cs
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/NATS.Client.JetStream/Internal/NatsJSJsonDocumentSerializer.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,12 @@ | ||
using System.Buffers; | ||
using System.Text.Json; | ||
using NATS.Client.Core; | ||
|
||
namespace NATS.Client.JetStream.Internal; | ||
|
||
internal sealed class NatsJSJsonDocumentSerializer : INatsDeserialize<JsonDocument> | ||
{ | ||
public static readonly NatsJSJsonDocumentSerializer Default = new(); | ||
|
||
public JsonDocument? Deserialize(in ReadOnlySequence<byte> buffer) => buffer.Length == 0 ? default : JsonDocument.Parse(buffer); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be unnested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's pretty specific where server sets the 503 header for no responders and Go client seems to check for data being empty too. tbh I think no-responders is the only usage of 503 so i suppose it would be ok to move it out idk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nvm I guess I didn't realize they noresponders only came with empty 😅