Skip to content

Commit

Permalink
decoder wrapping fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Aug 8, 2019
1 parent 714aa98 commit 03e1e6b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/MySQLKit/MySQLDataDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ private struct DecoderUnwrapper: Decodable {
self.decoder = decoder
}
}

private struct Wrapper<D>: Decodable where D: Decodable {
var value: D

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.value = try container.decode(D.self)
}
}

private struct DoJSON: Error { }

public struct MySQLDataDecoder {
Expand All @@ -15,7 +25,7 @@ public struct MySQLDataDecoder {
where T: Decodable
{
do {
return try T.init(from: _Decoder(data: data))
return try Wrapper<T>.init(from: _Decoder(data: data)).value
} catch is DoJSON {
guard let value = try data.json(as: T.self) else {
throw DecodingError.typeMismatch(T.self, DecodingError.Context.init(
Expand Down

0 comments on commit 03e1e6b

Please sign in to comment.