Created
June 21, 2017 05:17
-
-
Save hisui/6954c16aab6a2c7d4d05b26ecf1fb735 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import ObjectMapper | |
enum Event { | |
case ringing | |
case incomingSound(instant: Int64, samples: Data) | |
case outgoingSound(instant: Int64, samples: Data) | |
case hangUp | |
} | |
extension Event : ImmutableMappable { | |
init(map: Map) throws { | |
switch try map.value("kind") as String { | |
case "ringing": | |
self = .ringing | |
case "hangUp": | |
self = .hangUp | |
case "incomingSound": | |
self = .incomingSound( | |
instant: try map.value("instant"), | |
samples: try map.value("samples") | |
) | |
case "outgoingSound": | |
self = .outgoingSound( | |
instant: try map.value("instant"), | |
samples: try map.value("samples") | |
) | |
default: | |
throw NSError() | |
} | |
} | |
mutating func mapping(map: Map) { | |
switch self { | |
case .ringing: | |
"ringing" >>> map["kind"] | |
case .hangUp: | |
"hangUp" >>> map["kind"] | |
case let .incomingSound(instant: instant, samples: samples): | |
"incomingSound" >>> map["kind"] | |
instant >>> map["instant"] | |
samples >>> map["samples"] | |
case let .outgoingSound(instant: instant, samples: samples): | |
"outgoingSound" >>> map["kind"] | |
instant >>> map["instant"] | |
samples >>> map["samples"] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment