mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
Motivation: The exisiting ByteBuffer`s `capacity` property exposes the number of addressable bytes in the buffer (that is, the difference between its upper and lower bound). This value can be significantly different than the number of bytes allocated to the buffer's underlying storage. For example, when constructing of COW slice from the original buffer the underlying storage maybe tens of thousands of bytes while the slice's capacity is 1. To avoid any ambiguitity, a new property - `storageCapacity` - will be added. Modifications: Added new `storageCapacity` property to expose the capacity of the buffer (or derived COW slice) underlying storage (that is allocated to the buffer). This property is part of public interface ans is typed as an Int. Updated unit tests to verify `storedCapacity` remains constant when slicing the ByteBuffer and also to account for the addition of the new property in the CustomStringConvertible desciption. Result: The `storageCapacity` of a buffer and a COW slice taken from that buffer with remain the same data is written to the slice. Co-authored-by: Graeme Jenkinson <gcjenkinson@Graemes-MacBook-Pro.local> Co-authored-by: Cory Benfield <lukasa@apple.com>