haxetink / tink_io

Asynchronous I/O everywhere
https://haxetink.github.io/tink_io
MIT License
18 stars 12 forks source link

StreamParserObject::eof returns an Option #46

Open kevinresol opened 3 years ago

kevinresol commented 3 years ago

Mainly changed the following:

interface StreamParserObject<Result> {
-   function eof(rest:ChunkCursor):Outcome<Result, Error>;
+   function eof(rest:ChunkCursor):Outcome<Option<Result>, Error>;
}

Rationale: an eof of a stream might come "detached" from any data. For example for signal stream the Data and End signal are always separated. In that case, there could be no data to process (if the previous chunks are complete and already get emitted) and thus no result to emit in eof() and the current API is unable to express that.

Breaking change: added function readEof():Outcome<Option<Result>, Error> to BytewiseParser and the eof is no longer handled with a -1 byte.

At the same time, I updated/simplified Splitter implementation to use ChunkCursor::seek

kevinresol commented 3 years ago

Before this PR, the way to work is to wrap every result in an extra Option so that one can emit None in eof. I believe this change can eliminate these extra allocations.