Skip to content

Commit 79053a3

Browse files
committed
The platform-specific handling for conforming Array to LMDBData is still required.
1 parent d83f8f9 commit 79053a3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Sources/SwiftDocC/Utility/LMDB/LMDB.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,24 @@ extension String: LMDBData {
8989
}
9090
}
9191

92-
extension Array: LMDBData where Element: FixedWidthInteger {}
92+
// This is required for macOS, for Linux the default implementation works as expected.
93+
extension Array: LMDBData where Element: FixedWidthInteger {
94+
95+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
96+
public init?(data: UnsafeRawBufferPointer) {
97+
var array = Array<Element>(repeating: 0, count: data.count / MemoryLayout<Element>.stride)
98+
_ = array.withUnsafeMutableBytes { data.copyBytes(to: $0) }
99+
self = array
100+
}
101+
102+
public func read<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
103+
let data = self.withUnsafeBufferPointer { Data(buffer: $0) }
104+
return try data.read(body)
105+
}
106+
#endif
107+
108+
}
109+
93110
extension Bool: LMDBData {}
94111
extension Int: LMDBData {}
95112
extension Int8: LMDBData {}

0 commit comments

Comments
 (0)