Created
January 5, 2023 16:33
-
-
Save fitomad/25389bed158679fc4768ffe14f4f08fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class VoyagerMessageHandler: MessageHandler { | |
var nextHandler: MessageHandler? | |
func process(_ message: String) throws { | |
let regex = #/^VYYR\s{1,4}(?<id>\d{1})\s{1,4}(?<distance>\d{1,}\.\d{1,3})\s{1,}/# | |
let match = try regex.firstMatch(in: message) | |
if let match { | |
print("🛸 La sonda Voyager \(match.id) se encuentra a \(match.distance) millones de kilómetros") | |
} else if let nextHandler { | |
try nextHandler.process(message) | |
} else { | |
throw MessageError.unknown | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment