     }
 
     @_inlineable @_versioned
-    mutating func _set<S: Sequence>(bytes: S, at index: Index) -> Capacity where S.Element == UInt8 {
+    mutating func _set<S: Sequence>(bytes: S, at index: _Index) -> _Capacity where S.Element == UInt8 {
         assert(!([Array<S.Element>.self, StaticString.self, ContiguousArray<S.Element>.self, UnsafeRawBufferPointer.self, UnsafeBufferPointer<UInt8>.self].contains(where: { (t: Any.Type) -> Bool in t == type(of: bytes) })),
                "called the slower set<S: Sequence> function even though \(S.self) is a ContiguousCollection")
         func ensureCapacityAndReturnStorageBase(capacity: Int) -> UnsafeMutablePointer<UInt8> {
-            self._ensureAvailableCapacity(Capacity(capacity), at: index)
+            self._ensureAvailableCapacity(_Capacity(capacity), at: index)
             return self._storage.bytes.advanced(by: Int(self._slice.lowerBound + index)).assumingMemoryBound(to: UInt8.self)
         }
         let underestimatedByteCount = bytes.underestimatedCount
-        let newPastEndIndex: Index = index + _toIndex(underestimatedByteCount)
+        let newPastEndIndex: _Index = index + _toIndex(underestimatedByteCount)
         if !isKnownUniquelyReferenced(&self._storage) {
             let extraCapacity = newPastEndIndex > self._slice.upperBound ? newPastEndIndex - self._slice.upperBound : 0
             self._copyStorageAndRebase(extraCapacity: extraCapacity)

    }

    @_inlineable @_versioned
    mutating func _moveWriterIndex(to newIndex: Index) {
        assert(newIndex >= 0 && newIndex <= _toCapacity(self._slice.count))
        self._writerIndex = newIndex
    }

public struct ByteBuffer {
    typealias Slice = _ByteBufferSlice
    typealias Allocator = ByteBufferAllocator
    // these two type aliases should be made `@usableFromInline internal` for
    // the 2.0 release when we can drop Swift 4.0 & 4.1 support. The reason they
    // must be public is because Swift 4.0 and 4.1 don't support attributes for
    // typealiases and Swift 4.2 warns if those attributes aren't present and
    // the type is internal.
    public typealias _Index = UInt32
    public typealias _Capacity = UInt32

    @_versioned private(set) var _storage: _Storage
    @_versioned private(set) var _readerIndex: _Index = 0
    @_versioned private(set) var _writerIndex: _Index = 0
    @_versioned private(set) var _slice: Slice

    // MARK: Internal _Storage for CoW
    @_versioned final class _Storage {
        private(set) var capacity: _Capacity
        @_versioned private(set) var bytes: UnsafeMutableRawPointer
        private(set) var fullSlice: Slice
        private let allocator: ByteBufferAllocator

        public init(bytesNoCopy: UnsafeMutableRawPointer, capacity: _Capacity, allocator: ByteBufferAllocator) {
            self.bytes = bytesNoCopy
            self.capacity = capacity
            self.allocator = allocator
