Add tests and validate Data and DispatchData as sequences

This commit is contained in:
Philippe Hausler
2019-05-13 10:12:31 -07:00
parent 02c55f372c
commit 8a751bd4de
2 changed files with 35 additions and 2 deletions

View File

@@ -43,9 +43,11 @@ extension NSData : DataProtocol {
@nonobjc
public subscript(position: Int) -> UInt8 {
var byte = UInt8(0)
var offset = position
enumerateBytes { (ptr, range, stop) in
if range.location <= position && position < range.upperBound {
byte = ptr.load(fromByteOffset: range.location - position, as: UInt8.self)
offset -= range.lowerBound
if range.contains(position) {
byte = ptr.load(fromByteOffset: offset, as: UInt8.self)
stop.pointee = true
}
}