Skip to content
Snippets Groups Projects
Commit 358df51e authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add ServiceProcessor

parent 5be84eb4
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Bindings
import XCTestDynamicOverlay
public struct ServiceProcessor {
public typealias Process = (
_ message: Data,
_ receptionId: Data,
_ ephemeralId: Int64,
_ roundId: Int64
) -> Void
public init(serviceTag: String, process: @escaping Process) {
self.serviceTag = serviceTag
self.process = process
}
public var serviceTag: String
public var process: Process
}
extension ServiceProcessor {
public static let unimplemented = ServiceProcessor(
serviceTag: "unimplemented",
process: XCTUnimplemented("\(Self.self).process")
)
}
extension ServiceProcessor {
func makeBindingsProcessor() -> BindingsProcessorProtocol {
class Processor: NSObject, BindingsProcessorProtocol {
init(_ serviceProcessor: ServiceProcessor) {
self.serviceProcessor = serviceProcessor
}
let serviceProcessor: ServiceProcessor
func process(_ message: Data?, receptionId: Data?, ephemeralId: Int64, roundId: Int64) {
guard let message = message else {
fatalError("BindingsProcessor.process received `nil` message")
}
guard let receptionId = receptionId else {
fatalError("BindingsProcessor.process received `nil` receptionId")
}
serviceProcessor.process(message, receptionId, ephemeralId, roundId)
}
func string() -> String {
serviceProcessor.serviceTag
}
}
return Processor(self)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment