tink_io icon indicating copy to clipboard operation
tink_io copied to clipboard

StreamParserObject::eof returns an Option

Open kevinresol opened this issue 4 years ago • 1 comments

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 avatar Jun 18 '21 08:06 kevinresol

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.

kevinresol avatar Jul 18 '21 10:07 kevinresol