优化IOS

This commit is contained in:
zhy200308
2026-08-19 09:31:21 +08:00
parent 7023062b45
commit eae24000e9
29 changed files with 4025 additions and 377 deletions
+17
View File
@@ -5,6 +5,23 @@ func sha256Hex(_ data: Data) -> String {
SHA256.hash(data: data).map { String(format: "%02x", $0) }.joined()
}
extension Data {
/// 十六进制字符串转字节。只在测试里造光学清单时用。
init?(hexString: String) {
guard hexString.count % 2 == 0 else { return nil }
var bytes = [UInt8]()
bytes.reserveCapacity(hexString.count / 2)
var index = hexString.startIndex
while index < hexString.endIndex {
let next = hexString.index(index, offsetBy: 2)
guard let byte = UInt8(hexString[index..<next], radix: 16) else { return nil }
bytes.append(byte)
index = next
}
self.init(bytes)
}
}
/// 从管道里读一行,带超时。用来等 MockPCServer 打印 `READY <port>`。
func readReadyLine(from handle: FileHandle, timeout: TimeInterval) -> String? {
let deadline = Date().addingTimeInterval(timeout)