@@ -7,13 +7,15 @@ extension _CBORDecoder {
77 var data : ArraySlice < UInt8 >
88 var index : Data . Index
99 let options : CodableCBORDecoder . _Options
10+ let currentDepth : Int
1011
11- init ( data: ArraySlice < UInt8 > , codingPath: [ CodingKey ] , userInfo: [ CodingUserInfoKey : Any ] , options: CodableCBORDecoder . _Options ) {
12+ init ( data: ArraySlice < UInt8 > , codingPath: [ CodingKey ] , userInfo: [ CodingUserInfoKey : Any ] , options: CodableCBORDecoder . _Options , currentDepth : Int = 0 ) {
1213 self . codingPath = codingPath
1314 self . userInfo = userInfo
1415 self . data = data
1516 self . index = self . data. startIndex
1617 self . options = options
18+ self . currentDepth = currentDepth
1719 }
1820
1921 func checkCanDecode< T> ( _ type: T . Type , format: UInt8 ) throws {
@@ -32,7 +34,7 @@ extension _CBORDecoder {
3234
3335extension _CBORDecoder . SingleValueContainer : SingleValueDecodingContainer {
3436 func decodeNil( ) -> Bool {
35- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
37+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
3638 return false
3739 }
3840 switch cbor {
@@ -42,7 +44,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
4244 }
4345
4446 func decode( _ type: Bool . Type ) throws -> Bool {
45- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
47+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
4648 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
4749 throw DecodingError . dataCorrupted ( context)
4850 }
@@ -55,7 +57,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
5557 }
5658
5759 func decode( _ type: String . Type ) throws -> String {
58- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
60+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
5961 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
6062 throw DecodingError . dataCorrupted ( context)
6163 }
@@ -68,7 +70,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
6870 }
6971
7072 func decode( _ type: Double . Type ) throws -> Double {
71- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
73+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
7274 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
7375 throw DecodingError . dataCorrupted ( context)
7476 }
@@ -83,7 +85,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
8385 }
8486
8587 func decode( _ type: Float . Type ) throws -> Float {
86- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
88+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
8789 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
8890 throw DecodingError . dataCorrupted ( context)
8991 }
@@ -97,7 +99,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
9799 }
98100
99101 func decode( _ type: Int . Type ) throws -> Int {
100- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
102+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
101103 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
102104 throw DecodingError . dataCorrupted ( context)
103105 }
@@ -111,7 +113,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
111113 }
112114
113115 func decode( _ type: Int8 . Type ) throws -> Int8 {
114- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
116+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
115117 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
116118 throw DecodingError . dataCorrupted ( context)
117119 }
@@ -125,7 +127,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
125127 }
126128
127129 func decode( _ type: Int16 . Type ) throws -> Int16 {
128- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
130+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
129131 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
130132 throw DecodingError . dataCorrupted ( context)
131133 }
@@ -139,7 +141,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
139141 }
140142
141143 func decode( _ type: Int32 . Type ) throws -> Int32 {
142- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
144+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
143145 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
144146 throw DecodingError . dataCorrupted ( context)
145147 }
@@ -153,7 +155,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
153155 }
154156
155157 func decode( _ type: Int64 . Type ) throws -> Int64 {
156- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
158+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
157159 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
158160 throw DecodingError . dataCorrupted ( context)
159161 }
@@ -167,7 +169,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
167169 }
168170
169171 func decode( _ type: UInt . Type ) throws -> UInt {
170- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
172+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
171173 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
172174 throw DecodingError . dataCorrupted ( context)
173175 }
@@ -180,7 +182,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
180182 }
181183
182184 func decode( _ type: UInt8 . Type ) throws -> UInt8 {
183- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
185+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
184186 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
185187 throw DecodingError . dataCorrupted ( context)
186188 }
@@ -193,7 +195,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
193195 }
194196
195197 func decode( _ type: UInt16 . Type ) throws -> UInt16 {
196- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
198+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
197199 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
198200 throw DecodingError . dataCorrupted ( context)
199201 }
@@ -206,7 +208,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
206208 }
207209
208210 func decode( _ type: UInt32 . Type ) throws -> UInt32 {
209- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
211+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
210212 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
211213 throw DecodingError . dataCorrupted ( context)
212214 }
@@ -219,7 +221,7 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
219221 }
220222
221223 func decode( _ type: UInt64 . Type ) throws -> UInt64 {
222- guard let cbor = try ? CBOR . decode ( self . data. map { $0 } ) else {
224+ guard let cbor = try ? CBOR . decode ( self . data. map { $0 } , options : self . options . toCBOROptions ( ) ) else {
223225 let context = DecodingError . Context ( codingPath: self . codingPath, debugDescription: " Invalid format: \( self . data) " )
224226 throw DecodingError . dataCorrupted ( context)
225227 }
@@ -232,7 +234,9 @@ extension _CBORDecoder.SingleValueContainer: SingleValueDecodingContainer {
232234 }
233235
234236 func decode< T: Decodable > ( _ type: T . Type ) throws -> T {
235- let decoder = _CBORDecoder ( data: self . data, options: self . options)
237+ let decoder = _CBORDecoder ( data: self . data, options: self . options, currentDepth: self . currentDepth + 1 )
238+ decoder. codingPath = self . codingPath
239+ decoder. userInfo = self . userInfo
236240 let value = try T ( from: decoder)
237241 if let nextIndex = decoder. container? . index {
238242 self . index = nextIndex
0 commit comments