ソースを参照

refactor readchar to use readbyte

Yeo Kheng Meng 9 年 前
コミット
5536368ba7
1 ファイル変更6 行追加17 行削除
  1. 6 17
      Sources/SwiftSerial.swift

+ 6 - 17
Sources/SwiftSerial.swift

@@ -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