-
-
Notifications
You must be signed in to change notification settings - Fork 428
Expand file tree
/
Copy pathCustomStdioTransport.swift
More file actions
30 lines (22 loc) · 739 Bytes
/
CustomStdioTransport.swift
File metadata and controls
30 lines (22 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Foundation
import JSONRPC
import os.log
public class CustomDataTransport: DataTransport {
let nextTransport: DataTransport
var onWriteRequest: (JSONRPCRequest<JSONValue>) -> Void = { _ in }
init(nextTransport: DataTransport) {
self.nextTransport = nextTransport
}
public func write(_ data: Data) {
if let request = try? JSONDecoder().decode(JSONRPCRequest<JSONValue>.self, from: data) {
onWriteRequest(request)
}
nextTransport.write(data)
}
public func setReaderHandler(_ handler: @escaping ReadHandler) {
nextTransport.setReaderHandler(handler)
}
public func close() {
nextTransport.close()
}
}