refactor(swift): dedupe AnyCodable

This commit is contained in:
Peter Steinberger
2026-02-15 20:00:40 +00:00
parent 8ccbd00e1b
commit a3419e48ab
3 changed files with 47 additions and 111 deletions

View File

@@ -2,14 +2,6 @@ import OpenClawProtocol
import Foundation
public enum GatewayPayloadDecoding {
public static func decode<T: Decodable>(
_ payload: OpenClawProtocol.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 decode<T: Decodable>(
_ payload: AnyCodable,
as _: T.Type = T.self) throws -> T
@@ -18,14 +10,6 @@ public enum GatewayPayloadDecoding {
return try JSONDecoder().decode(T.self, from: data)
}
public static func decodeIfPresent<T: Decodable>(
_ payload: OpenClawProtocol.AnyCodable?,
as _: T.Type = T.self) throws -> T?
{
guard let payload else { return nil }
return try self.decode(payload, as: T.self)
}
public static func decodeIfPresent<T: Decodable>(
_ payload: AnyCodable?,
as _: T.Type = T.self) throws -> T?