Explorar el Código

refactor readchar to use readbyte

Yeo Kheng Meng hace 9 años
padre
commit
5536368ba7
Se han modificado 1 ficheros con 6 adiciones y 17 borrados
  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