SimplePipe will only extend exactly the elements requested (from what is
availble), so it can be used for testing with a static buffer to simulate
data coming in at any rate.
The upstream data. This can be any iopipe. Throughout the library, the
upstream data is generally saved as a member called "chain" as a matter
of convention. This is not required or expected.
Get more data from the pipe. The parameter indicates the desired number
of elements to add to the end of the window. If 0 is passed, then it is
up to the implementation of the pipe to determine the optimal number of
elements to add.
Release the given number of elements from the front of the window. After
calling this, make sure to update any tracking indexes for the window
that you are maintaining.
Get the current window of elements for the pipe. This is the data that
can be used at this moment in time.
Example
// any array is a valid iopipe source.
auto source = "hello, world!";
auto pipe = SimplePipe!(string)(source);
// SimplePipe holds back data until you extend it.
assert(pipe.window.length == 0);
// Note: elements of narrow strings are code units for purposes of iopipe
// library.
assert(pipe.extend(5) == 5);
assert(pipe.window == "hello");
// Release data to inform the pipe you are done with it
pipe.release(3);
assert(pipe.window == "lo");
// you can request "some data" by extending with 0, letting the pipe define
// what is the best addition of data. This is useful for optimizing OS
// system call reads.
assert(pipe.extend(0) == 1);
assert(pipe.window == "lo,");
// you aren't guaranteed to get all the data you ask for.
assert(pipe.extend(100) == 7);
assert(pipe.window == "lo, world!");
pipe.release(pipe.window.length);
// this signifies EOF.
assert(pipe.extend(1) == 0);