refactor readchar to use readbyte

This commit is contained in:
Yeo Kheng Meng
2017-06-24 17:40:49 +08:00
parent e2063420e9
commit 5536368ba7

View File

@@ -446,23 +446,6 @@ extension SerialPort {
return try readUntilChar(newlineChar)
}
public func readChar() throws -> UnicodeScalar {
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 1)
defer {
buffer.deallocate(capacity: 1)
}
while true {
let bytesRead = try readBytes(into: buffer, size: 1)
if bytesRead > 0 {
let character = UnicodeScalar(buffer[0])
return character
}
}
}
public func readByte() throws -> UInt8 {
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 1)
@@ -479,6 +462,12 @@ extension SerialPort {
}
}
public func readChar() throws -> UnicodeScalar {
let byteRead = readByte()
let character = UnicodeScalar(buffer[0])
return character
}
}
// MARK: Transmitting