Question and API proposal regarding DotNext.IO #182
Replies: 1 comment 2 replies
-
It is not mandatory to have settable members on types implementing These optimizations are possible only of the object contents is in contiguous memory (while
This reduces a surface for potential reuse. For instance, stackalloc'ed memory cannot be represented as |
Beta Was this translation helpful? Give feedback.
-
Hello, first of all I would first like to express my sincere appreciation for this amazing library !
Question
For the sake of my personal understanding, I am curious about the motivations behind your choice to design a non-generic SequenceReader, rather than enhancing the existing System.Buffers.SequenceReader (aside from the async method overloads).
API proposal
Furthermore, I would like to make a proposal for new APIs and changes to existing ones for pipe-related scenarios which could be beneficial for users willing to directly read from a sequence that was obtained from a
PipeReader
via aSequenceReader<byte>
.I have largely completed the necessary work and testing within a private repository of my own, achieving close to 90% coverage. If required, I can ensure this coverage reaches 100%. It would be my pleasure to introduce these modifications to DotNext via a pull request.
Background and motivation
The
IBinaryFormattable<TSelf>
, from my perspective, is somewhat lacking in terms of extensibility. It could be beneficial to divide it into separate read-only and write-only interfaces. Additionally, new interfaces could be introduced for binary readable types that expose settable members, which would not necessarily require the implementation of a static abstract interface method.In relation to pipe-related scenarios, users might desire to implement an
IBinaryFormattable<TSelf>
, and as such, may not be inclined to implement parsing logic based on aSpanReader<byte>
to process input data from aReadOnlySequence<byte>
. Instead, they could directly depend on aSequenceReader<byte>
, which would eliminate the need to copy the input data into a single stack-allocated or rented span.I believe that implementing these modifications would pave the way for APIs that are prepared for source-generator integration which is a feature I intend to develop in the future.
Proposal
Consequently, my proposal could take several directions depending on the scenarios we aim to address:
If we primarily want to address pipe-related scenarios:
IBinaryFormattable<TSelf>
into three interfaces:IBinaryWritable
with a publicvoid Serialize(ref SpanWriter<T> output)
and potentially an instanceint GetSizeOf()
method, or another interface enabling the addition of extension methods to write into anIBufferWriter<byte>
or various memory owners.IBinaryReadable
with a publicvoid Deserialize(ref SpanReader<T> input)
for objects with settable members.IBinaryReadable<TSelf>
with a static abstractRead
method for objects with init-only members.IBinaryFormattable : IBinaryWritable, IBinaryReadable
for objects exposing setting members.IBinaryFormattable<TSelf>
toIBinaryFormattable<TSelf> : IBinaryReadable<TSelf>, IBinaryWritable
.IBufferReadable
andIBufferReadable<TSelf>
that mirror theIBinaryReadable
interfaces but use aSequenceReader<byte>
instead.IBinaryFormattable
-like interfaces for the sequence-basedIBufferReadable
interfaces.If we aim to cover a broader range of scenarios (e.g., spans of chars):
ISpanReadable<T>
,ISpanReadable<TSelf, T>
andISpanWritable<T>
interfaces, where T represents the span element type.Source code
I have made some of the suggested APIs available in a gist, which can be found here: https://gist.github.com/thenameless314159/a2a6487ce19c0da24d08a1cf328ddc8e
Beta Was this translation helpful? Give feedback.
All reactions