-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[CBOR] Implement indefinite length writer and reader support #33831
Conversation
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborReaderTests.Map.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborReader.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborWriter.Array.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborWriter.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborReaderTests.String.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborReader.String.cs
Outdated
Show resolved
Hide resolved
// performing validation and returning a list of ranges containing the individual chunk payloads | ||
private List<(int offset, int length)> ReadChunkedStringRanges(CborMajorType type, out int encodingLength, out int concatenatedBufferSize) | ||
{ | ||
var ranges = new List<(int offset, int length)>(); |
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.
I don't know if it's worth the complexity; but you could do something like
List<(int offset, int length)> ranges = Interlocked.Exchange(ref _ranges, null);
ranges ??= new List<(int, int)>();
ranges.Clear();
And have all of the calling members assign it back to the field right before returning.
It's not super important, though.
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.
I'll give it a shot, provided it doesn't make things too hard to read. Or maybe wait until benchmarking demonstrates issues with allocations.
Also, why Interlocked? The class offers no thread safety guarantees.
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 both a quick way of "I've taken this" (in case somehow this ever went recursive, which I know isn't currently possible) and it means that the kinds of scary race conditions are limited. (overlapping writes from a read method is scarier to me than read twice or read slightly forward)
Adds indefinite length writer and reader support for strings, maps and arrays: