okio
okio copied to clipboard
Zero-copy ByteString.slice(offset, length)
I have a format represented in-memory as a ByteString and I want to expose parts of that elsewhere in the codebase without causing needless copies.
I believe SegmentedByteString behaves like what you describe by sharing segments when calling substring() and just recalculating start and end points. If a similar enhancement was added to ByteString for substring() , would that fit your use case?
It would, but that behavior may surprise people (for the same reason it used to in String.substring). That's why I proposed a separate method which defines it's behavior as a view into the original bytes.