Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readFromHead/writeToTail should propagate the Int returned from the lambda #360

Closed
JakeWharton opened this issue Jul 30, 2024 · 2 comments
Closed

Comments

@JakeWharton
Copy link
Contributor

I'm trying to implement RawSource.readAtMostTo using UnsafeBufferOperations.writeToTail.

I want to do

	override fun readAtMostTo(sink: Buffer, byteCount: Long): Long {
		return UnsafeBufferOperations.writeToTail(sink, 1) { bytes, startIndexInclusive, endIndexExclusive ->
			val read: Int = TODO()
			read
		}.toLong()
	}

but writeToTail doesn't give me the Int which I return from the lambda at the callsite in order to do this.

@JakeWharton JakeWharton changed the title writeToTail should propagate the Int returned from the lambda readFromHead/writeToTail should propagate the Int returned from the lambda Jul 30, 2024
@JakeWharton
Copy link
Contributor Author

Expanding this to readFromHead since you can end up reading fewer than requested with things like POSIX write.

@fzhinkin
Copy link
Collaborator

There are a few JVM-specific extensions allowing to read/write from/to java.nio.ByteBuffer. It might be worth updating those functions too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants