@@ -170,7 +170,7 @@ open class ReerJSONDecoder {
170170 ///
171171 /// - parameter type: The type of the value to decode.
172172 /// - parameter data: The data to decode from.
173- /// - parameter path: The decoding container path.
173+ /// - parameter path: The decoding container path, `["user", "info"]`
174174 /// - returns: A value of the requested type.
175175 /// - throws: `DecodingError.dataCorrupted` if values requested from the payload are corrupted, or if the given data is not valid JSON.
176176 /// - throws: An error if any value throws an error during decoding.
@@ -204,34 +204,16 @@ open class ReerJSONDecoder {
204204 ///
205205 /// - parameter type: The type of the value to decode.
206206 /// - parameter data: The data to decode from.
207- /// - parameter keyPath : The decoding container path, "user.info".
207+ /// - parameter path : The decoding container path, ` "user.info"`
208208 /// - returns: A value of the requested type.
209209 /// - throws: `DecodingError.dataCorrupted` if values requested from the payload are corrupted, or if the given data is not valid JSON.
210210 /// - throws: An error if any value throws an error during decoding.
211- open func decode< T: Decodable > ( _ type: T . Type , from data: Data , keyPath: String ) throws -> T {
212- let doc = data. withUnsafeBytes {
213- yyjson_read (
214- $0. bindMemory ( to: CChar . self) . baseAddress,
215- data. count,
216- YYJSON_READ_NUMBER_AS_RAW
217- )
218- }
219- guard let doc else {
220- return try decodeWithFoundationDecoder ( type, from: data)
221- }
222-
223- defer {
224- yyjson_doc_free ( doc)
225- }
226-
227- var pointer = yyjson_doc_get_root ( doc)
228- for key in keyPath. components ( separatedBy: CharacterSet ( charactersIn: " . " ) ) {
229- pointer = key. withCString { yyjson_obj_get ( pointer, $0) }
230- }
231-
232- let json = JSON ( pointer: pointer)
233- let impl = JSONDecoderImpl ( json: json, userInfo: userInfo, codingPathNode: . root, options: options)
234- return try impl. unbox ( json, as: type, for: . root, _CodingKey? . none)
211+ open func decode< T: Decodable > ( _ type: T . Type , from data: Data , path: String ) throws -> T {
212+ return try decode (
213+ type,
214+ from: data,
215+ path: path. components ( separatedBy: CharacterSet ( charactersIn: " . " ) )
216+ )
235217 }
236218
237219 func decodeWithFoundationDecoder< T : Decodable > ( _ type: T . Type , from data: Data ) throws -> T {
0 commit comments