Skip to content
Snippets Groups Projects

Use codable models in API

1 file
+ 6
3
Compare changes
  • Side-by-side
  • Inline
import Bindings
import Bindings
public struct MessageSender {
public struct MessageSender {
public var send: (Int, Data) throws -> Data
public var send: (Int, Data) throws -> MessageSendReport
public func callAsFunction(
public func callAsFunction(
messageType: Int,
messageType: Int,
payload: Data
payload: Data
) throws -> Data {
) throws -> MessageSendReport {
try send(messageType, payload)
try send(messageType, payload)
}
}
}
}
@@ -28,7 +28,10 @@ extension MessageSender {
@@ -28,7 +28,10 @@ extension MessageSender {
sendE2E: @escaping (Int, Data) throws -> Data
sendE2E: @escaping (Int, Data) throws -> Data
) -> MessageSender {
) -> MessageSender {
MessageSender { messageType, payload in
MessageSender { messageType, payload in
try sendE2E(messageType, payload)
let reportData = try sendE2E(messageType, payload)
 
let decoder = JSONDecoder()
 
let report = try decoder.decode(MessageSendReport.self, from: reportData)
 
return report
}
}
}
}
}
}
Loading