2026-01-30 03:15:10 +01:00
|
|
|
import OpenClawProtocol
|
2026-01-19 05:44:36 +00:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
public enum GatewayPayloadDecoding {
|
2026-01-19 06:22:01 +00:00
|
|
|
public static func decode<T: Decodable>(
|
|
|
|
|
_ payload: AnyCodable,
|
|
|
|
|
as _: T.Type = T.self) throws -> T
|
|
|
|
|
{
|
|
|
|
|
let data = try JSONEncoder().encode(payload)
|
|
|
|
|
return try JSONDecoder().decode(T.self, from: data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func decodeIfPresent<T: Decodable>(
|
|
|
|
|
_ payload: AnyCodable?,
|
|
|
|
|
as _: T.Type = T.self) throws -> T?
|
|
|
|
|
{
|
|
|
|
|
guard let payload else { return nil }
|
|
|
|
|
return try self.decode(payload, as: T.self)
|
|
|
|
|
}
|
2026-01-19 05:44:36 +00:00
|
|
|
}
|