refactor(macos): extract gateway payload decoding

This commit is contained in:
Peter Steinberger committed 2025-12-12 22:27:18 +00:00
1 parent 14e3b34a8e
commit c7bd4b5c1d
3 files changed
+19 -9

No files matched your search

@@ -0,0 +1,16 @@
import ClawdisProtocol
import Foundation
enum GatewayPayloadDecoding {
static func decode<T: Decodable>(_ payload: ClawdisProtocol.AnyCodable, as _: T.Type = T.self) throws -> T {
let data = try JSONEncoder().encode(payload)
return try JSONDecoder().decode(T.self, from: data)
}
static func decodeIfPresent<T: Decodable>(_ payload: ClawdisProtocol.AnyCodable?, as _: T.Type = T.self) throws
-> T?
{
guard let payload else { return nil }
return try decode(payload, as: T.self)
}
}