-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDataCoder.swift
More file actions
28 lines (22 loc) · 865 Bytes
/
DataCoder.swift
File metadata and controls
28 lines (22 loc) · 865 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
import Foundation
/// A encoder suited to encode to Data
public protocol DataEncoder {
func encode<T: Encodable>(_ value: T) throws -> Data
}
/// A decoder suited to decode Data
public protocol DataDecoder {
func decode<T: Decodable>(_ type: T.Type, from: Data) throws -> T
}
/// A `DataEncoder` providing a `ContentType`
public protocol ContentDataEncoder: DataEncoder {
/// a http content type
static var contentType: HTTPContentType { get }
}
/// A `DataDecoder` providing a `ContentType`
public protocol ContentDataDecoder: DataDecoder {
/// a http content type
static var contentType: HTTPContentType { get }
}
/// A function converting data when a http error occur into a custom error
public typealias DataErrorDecoder = (Data) throws -> Error
public typealias ContentDataErrorDecoder = (Data, HTTPContentType) throws -> Error