-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathAPNSJSONDecoder.swift
31 lines (28 loc) · 1.08 KB
/
APNSJSONDecoder.swift
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
29
30
31
//===----------------------------------------------------------------------===//
//
// This source file is part of the APNSwift open source project
//
// Copyright (c) 2022 the APNSwift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of APNSwift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Foundation
import NIOCore
import NIOFoundationCompat
/// A protocol that is similar to the `JSONDecoder`. This allows users of APNSwift to customize the decoder used
/// for decoding the APNS response bodies.
public protocol APNSJSONDecoder: Sendable {
func decode<T: Decodable>(_ type: T.Type, from buffer: ByteBuffer) throws -> T
}
extension JSONDecoder: APNSJSONDecoder {
public func decode<T: Decodable>(_ type: T.Type, from buffer: ByteBuffer) throws -> T {
var copy = buffer
let data = copy.readData(length: buffer.readableBytes)!
return try self.decode(type, from: data)
}
}