feat: serializing / deserializing over streams #13
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.
Currently, this library provides no way to perform:
Uint8List
This PR contains:
package:async/async.dart
StreamSerializer
, which implementsStreamTransformer<dynamic, Uint8List>
StreamDeserializer
, which implementsStreamTransformer<List<int>, dynamic>
StreamTransformer
The discrepancy between the implemented
StreamTransformer
interface between the two is because:Uint8List
, which implementsList<int>
, it does not make sense to downgrade the type information here.Stream<Uint8List>
while someStream<List<int>>
, loosening the type constraint here should increase compatibility and avoid scenarios ofStream<List<int>>.map((e) => Uint8List.fromList(e))
.UsingStreamTransformer.cast()
can properly recast bothStreamSerializer
andStreamDeserializer
betweenUint8List
andList<int>
for compatibility in bothStream<List<int>>
andStream<Uint8List>
if the underlying stream elements have correct types during runtime.StreamTransformer.bind
directly rather thanStream.transform
allows to properly bypass usingStream.cast
orStreamTransformer.cast
which has performance costNoteworthy stream behaviors:
StreamDeserializer
will wait for more bytes upstream if it requires more bytes in order to complete deserializationStreamDeserializer
will emitUpstreamClosedError
if upstream closes unexpected (in the midst of deserializing a dart object that spans over many bytes)StreamSerializer
andStreamDeserializer
have similar constructor arguments to their non-stream counterparts.This PR should close #6, closely relates to #10 and should be generally a better solution than exposing
Deserializer.offset
.Serializing Dart objects into msgpack binary and outputting into a stream is already something any user can implement on their own with the existing
Serializer
class, but semantics of deserializing from a byte stream or multipleUint8List
into multiple Dart objects are not possible with the currentDeserializer
interface.Usage: