kotlinx-io icon indicating copy to clipboard operation
kotlinx-io copied to clipboard

Provide Input.readTo(Buffer)

Open qwwdfsad opened this issue 5 years ago • 3 comments

With best-effort zero-copy

qwwdfsad avatar Nov 26 '19 11:11 qwwdfsad

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.

altavir avatar Nov 28 '19 05:11 altavir

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.

qwwdfsad avatar Nov 28 '19 08:11 qwwdfsad

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.

altavir avatar Nov 28 '19 13:11 altavir

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.

fzhinkin avatar Jun 12 '23 11:06 fzhinkin