kotlinx-io
kotlinx-io copied to clipboard
Provide Input.readTo(Buffer)
With best-effort zero-copy
Buffer should be treated as an internal object because it could cause a lot of damage if leaked. I prefer not to expose it if possible. This method if implemented should be internal and used inside Input
to read to Bytes
.
I am not sure how things you said interfere with my proposal.
We have Input.readArray(array)
, why can't we have Input.readTo(Buffer)
as well? Nothing dangerous in this particular method.
The idea is to make it best effort zero-copy, if Input
does not have anything pre-cached, so it will be possible to .g. have zero-copy LimitingInput
using only public API.
The Buffer
should not be exposed at all since it is quite easy to mess with its disposal. It's appearance in public API could be tempting to something wrong. I do not see a way to implement zero-copy limits via filling buffer from the input because Input class does not allow to send your own buffer inside it. So even if you can directly read from input to buffer, this buffer is created by another input.
The method should be useful for internal API though. But in order to use it properly, we also need a way to hack into a way Input generates those Buffers.
We're rebooting the kotlinx-io development (see https://github.com/Kotlin/kotlinx-io/issues/131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.