-
Notifications
You must be signed in to change notification settings - Fork 61
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
Refine Source|Buffer.indexOf(ByteBuffer) contracts #424
base: develop
Are you sure you want to change the base?
Conversation
core/common/src/ByteStrings.kt
Outdated
@@ -85,6 +85,8 @@ public fun Source.readByteString(byteCount: Int): ByteString { | |||
* expands the source's buffer as necessary until [byteString] is found. This reads an unbounded number of | |||
* bytes into the buffer. Returns `-1` if the stream is exhausted before the requested bytes are found. | |||
* | |||
* For empty byte strings this function always return `0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #423. I'm not sure how to handle empty byte strings yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that this is really better than fetching the data, provided that we always ignore what has been fetched.
Maybe it should be explicitly written that in the case of an empty byte string, the data will never be read from the source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be explicitly written that in the case of an empty byte string, the data will never be read from the source?
Then, it would be inconsistent with the Buffer
's "overload". These two functions already behave differently, but I'd like to keep them as close to each other as possible.
core/common/src/ByteStrings.kt
Outdated
@@ -85,6 +85,8 @@ public fun Source.readByteString(byteCount: Int): ByteString { | |||
* expands the source's buffer as necessary until [byteString] is found. This reads an unbounded number of | |||
* bytes into the buffer. Returns `-1` if the stream is exhausted before the requested bytes are found. | |||
* | |||
* For empty byte strings this function always return `0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that this is really better than fetching the data, provided that we always ignore what has been fetched.
Maybe it should be explicitly written that in the case of an empty byte string, the data will never be read from the source?
core/common/src/ByteStrings.kt
Outdated
* @param byteString the sequence of bytes to find within the buffer. | ||
* @param startIndex the index into the buffer to start searching from. | ||
* | ||
* @throws IllegalArgumentException if [startIndex] is negative or if it is greater of equal to buffer's [Buffer.size]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, this behavior is also inconsistent with CharSequence.indexOf
, which I'm considering maybe not as a paragon, but as something to be aligned with.
Closes #422