forked from swiftlang/swift-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonDecodableProtocols.swift
More file actions
485 lines (374 loc) · 22.9 KB
/
CommonDecodableProtocols.swift
File metadata and controls
485 lines (374 loc) · 22.9 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
/// A type that can decode itself from an external representation based on "common" data types.
public protocol CommonDecodable: ~Copyable {
/// Creates a new instance by decoding from the given decoder.
///
/// This initializer throws an error if reading from the decoder fails, or
/// if the data read is corrupted or otherwise invalid.
///
/// - Parameter decoder: The decoder to read data from.
static func decode(from decoder: inout some (CommonDecoder & ~Escapable)) throws(CodingError.Decoding) -> Self
}
public protocol CommonDecodableWithContext: ~Copyable {
associatedtype CommonDecodingContext: ~Copyable & ~Escapable
@_lifetime(decoder: copy decoder)
static func decode<D: CommonDecoder & ~Escapable>(from decoder: inout D, context: inout CommonDecodingContext) throws(CodingError.Decoding) -> Self
}
// Convenience for Copyable contexts - allows static member syntax
extension CommonDecodableWithContext where Self: ~Copyable, CommonDecodingContext: Copyable {
@inline(__always)
@_alwaysEmitIntoClient
@_lifetime(decoder: copy decoder)
public static func decode<D: CommonDecoder & ~Escapable>(from decoder: inout D, context: CommonDecodingContext) throws(CodingError.Decoding) -> Self {
var mutableContext = context
return try Self.decode(from: &decoder, context: &mutableContext)
}
}
public protocol CommonFieldDecoder: ~Escapable {
@inlinable
func decode<T: DecodingField>(_: T.Type) throws(CodingError.Decoding) -> T
@inlinable
func matches(_ field: some DecodingField) -> Bool
@inlinable
func matches(_ key: StaticString) -> Bool
}
public protocol CommonDecodingVisitor: DecodingBoolVisitor, DecodingNumberVisitor, DecodingStringVisitor, DecodingBytesVisitor, ~Copyable, ~Escapable {
@_lifetime(decoder: copy decoder)
func visit(decoder: inout some CommonStructDecoder & ~Escapable) throws(CodingError.Decoding) -> DecodedValue
@_lifetime(decoder: copy decoder)
func visit(decoder: inout some CommonArrayDecoder & ~Escapable) throws(CodingError.Decoding) -> DecodedValue
func visitNone() throws(CodingError.Decoding) -> DecodedValue
}
// TODO: Traditional Decodable support
/// A type that can decode values based on "common" data types from a native format
/// into in-memory representations.
public protocol CommonDecoder: ~Escapable {
associatedtype StructDecoder: CommonStructDecoder & ~Escapable
associatedtype DictionaryDecoder: CommonDictionaryDecoder & ~Escapable
associatedtype ArrayDecoder: CommonArrayDecoder & ~Escapable
associatedtype FieldDecoder: CommonFieldDecoder & ~Escapable
// TODO: This is an interesting idea in potentially allowing a decoder to provide a more optimized form of "Content" for things like alternative enum formats. It needs more thought though. In lieu of this, or maybe even with it, we may need a standard "Content" type for macro to use with `decodeAny()`.
// associatedtype CommonCodingPrimitive: ~Copyable = Never
// TODO: This overload is a workaround for the inability for decoder to dynamically cast particular Copyable types to T: CommonDecodable & ~Copyable. It has a default implementation that calls into the normal ~Copyable path.
@_lifetime(self: copy self)
mutating func decode<T: CommonDecodable>(_: T.Type) throws(CodingError.Decoding) -> T
@_lifetime(self: copy self)
mutating func decodeStruct<T: ~Copyable>(_ closure: (inout StructDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T
@_lifetime(self: copy self)
mutating func decodeDictionary<T: ~Copyable>( _ closure: (inout DictionaryDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T
@_lifetime(self: copy self)
mutating func decodeArray<T: ~Copyable>(_ closure: (inout ArrayDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T
// MARK: - Enum Decoding
/// Decodes an enum case with no associated values
@_lifetime(self: copy self)
mutating func decodeEnumCase<T: ~Copyable>(
_ closure: (inout FieldDecoder) throws(CodingError.Decoding) -> T
) throws(CodingError.Decoding) -> T
/// Decodes an enum case with associated values
@_lifetime(self: copy self)
mutating func decodeEnumCase<T: ~Copyable>(
_ closure: (_ caseName: inout FieldDecoder, _ associatedValues: inout StructDecoder) throws(CodingError.Decoding) -> T
) throws(CodingError.Decoding) -> T
@_lifetime(self: copy self)
mutating func decode<Key: CodingStringKeyRepresentable, Value: CommonDecodable>(_: [Key:Value].Type, sizeHint: Int) throws(CodingError.Decoding) -> [Key:Value]
@_lifetime(self: copy self)
mutating func decode<Element: CommonDecodable>(_: [Element].Type, sizeHint: Int) throws(CodingError.Decoding) -> [Element]
@_lifetime(self: copy self)
mutating func decode(_: Bool.Type) throws(CodingError.Decoding) -> Bool
@_lifetime(self: copy self)
mutating func decode(_ hint: Int.Type) throws(CodingError.Decoding) -> Int
@_lifetime(self: copy self)
mutating func decode(_ hint: Int8.Type) throws(CodingError.Decoding) -> Int8
@_lifetime(self: copy self)
mutating func decode(_ hint: Int16.Type) throws(CodingError.Decoding) -> Int16
@_lifetime(self: copy self)
mutating func decode(_ hint: Int32.Type) throws(CodingError.Decoding) -> Int32
@_lifetime(self: copy self)
mutating func decode(_ hint: Int64.Type) throws(CodingError.Decoding) -> Int64
@_lifetime(self: copy self)
mutating func decode(_ hint: Int128.Type) throws(CodingError.Decoding) -> Int128
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt.Type) throws(CodingError.Decoding) -> UInt
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt8.Type) throws(CodingError.Decoding) -> UInt8
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt16.Type) throws(CodingError.Decoding) -> UInt16
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt32.Type) throws(CodingError.Decoding) -> UInt32
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt64.Type) throws(CodingError.Decoding) -> UInt64
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt128.Type) throws(CodingError.Decoding) -> UInt128
@_lifetime(self: copy self)
mutating func decode(_ hint: Float.Type) throws(CodingError.Decoding) -> Float
@_lifetime(self: copy self)
mutating func decode(_ hint: Double.Type) throws(CodingError.Decoding) -> Double
@_lifetime(self: copy self)
mutating func decode(_: String.Type) throws(CodingError.Decoding) -> String
@_lifetime(self: copy self)
mutating func decodeString<V: DecodingStringVisitor & ~Copyable>(_ visitor: borrowing V) throws(CodingError.Decoding) -> V.DecodedValue
@_lifetime(self: copy self)
mutating func decodeNil() throws(CodingError.Decoding) -> Bool
@_lifetime(self: copy self)
mutating func decodeOptional(_ closure: (inout Self) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding)
// TODO: Require this, or just have `decodeAny` throw?
var supportsDecodeAny: Bool { get }
@_lifetime(self: copy self)
mutating func decodeAny<V: CommonDecodingVisitor>(_ visitor: V) throws(CodingError.Decoding) -> V.DecodedValue
// @_lifetime(self: copy self)
// mutating func decodePrimitive() throws(CodingError.Decoding) -> CommonCodingPrimitive
/// Decode a value using a visitor, with a hint that a collection of bytes is expected in the encoded data.
///
/// - parameter visitor: An instance of the type that will create the `DecodedValue`
/// from the bytes the decoder makes it visit.
/// - returns: The value created by the `visitor`.
/// - throws: TBD. An error thrown by the `visitor`. Others?
@_lifetime(self: copy self)
mutating func decodeBytes<V: DecodingBytesVisitor>(visitor: V) throws(CodingError.Decoding) -> V.DecodedValue
}
extension CommonDecoder where Self: ~Escapable {
@inline(__always)
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
public mutating func decode<T: CommonDecodable & ~Copyable>(_: T.Type) throws(CodingError.Decoding) -> T {
try T.decode(from: &self)
}
@inline(__always)
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
public mutating func decode<T: CommonDecodable>(_: T.Type) throws(CodingError.Decoding) -> T {
try T.decode(from: &self)
}
@inline(__always)
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
public mutating func decode<T: CommonDecodableWithContext & ~Copyable>(with context: inout T.CommonDecodingContext) throws(CodingError.Decoding) -> T {
try T.decode(from: &self, context: &context)
}
/// Convenience: decode using an explicit context (inout version for stateful contexts).
@inline(__always)
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
public mutating func decode<T: CommonDecodableWithContext & ~Copyable>(_ type: T.Type, context: inout T.CommonDecodingContext) throws(CodingError.Decoding) -> T {
try T.decode(from: &self, context: &context)
}
/// Convenience: decode using an explicit context (copyable version for static member syntax).
/// This enables clean syntax: `decoder.decode(Date.self, context: .iso8601)`
@inline(__always)
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
public mutating func decode<T: CommonDecodableWithContext & ~Copyable>(_ type: T.Type, context: T.CommonDecodingContext) throws(CodingError.Decoding) -> T where T.CommonDecodingContext: Copyable {
try T.decode(from: &self, context: context)
}
}
/// A decoder that allows a dictionary visitor to decode string-based keys and values
/// one at a time from an encoded dictionary.
public protocol CommonStructDecoder: ~Escapable {
associatedtype FieldDecoder: CommonFieldDecoder & ~Escapable
associatedtype ValueDecoder: CommonDecoder & ~Escapable
@_lifetime(self: copy self)
mutating func decodeExpectedOrderField(required: Bool, matchingClosure: (UTF8Span) -> Bool, andValue valueDecoderClosure: (inout ValueDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding) -> Bool
@_lifetime(self: copy self)
mutating func decodeEachField(_ fieldDecoderClosure: (inout FieldDecoder) throws(CodingError.Decoding) -> Void, andValue valueDecoderClosure: (inout ValueDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding)
@_lifetime(self: copy self)
mutating func decodeEachKeyAndValue(_ closure: (String, inout ValueDecoder) throws(CodingError.Decoding) -> Bool) throws(CodingError.Decoding)
var sizeHint: Int? { get }
}
public extension CommonStructDecoder where Self: ~Escapable {
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
mutating func decodeExpectedOrderField(matchingClosure: (UTF8Span) -> Bool, andValue valueDecoderClosure: (inout ValueDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding) -> Bool {
try decodeExpectedOrderField(required: true, matchingClosure: matchingClosure, andValue: valueDecoderClosure)
}
@_lifetime(self: copy self)
mutating func decodeEachKeyAndValue(_ closure: (String, inout ValueDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding) {
try self.decodeEachKeyAndValue { key, valueDecoder throws(CodingError.Decoding) in
try closure(key, &valueDecoder)
return false
}
}
}
public extension CommonStructDecoder where Self: ~Escapable {
var sizeHint: Int? { nil }
}
public protocol CommonDictionaryDecoder: ~Escapable {
associatedtype KeyDecoder: CommonDecoder & ~Escapable
associatedtype ValueDecoder: CommonDecoder & ~Escapable
@_lifetime(self: copy self)
mutating func decodeEachKey(_ keyDecodingClosure: (inout KeyDecoder) throws(CodingError.Decoding) -> Void, andValue valueDecoderClosure: (inout ValueDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding)
@_lifetime(self: copy self)
mutating func decodeKey(_ keyDecodingClosure: (inout KeyDecoder) throws(CodingError.Decoding) -> Void, andValue valueDecoderClosure: (inout ValueDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding) -> Bool
}
public protocol CommonArrayDecoder: ~Escapable {
associatedtype ElementDecoder: CommonDecoder & ~Escapable
@_lifetime(self: copy self)
mutating func decodeNext<T: ~Copyable>(_ closure: (inout ElementDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T?
@_lifetime(self: copy self)
mutating func decodeEachElement(_ closure: (inout ElementDecoder) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding)
var sizeHint: Int? { get }
}
public extension CommonArrayDecoder where Self: ~Escapable {
@_alwaysEmitIntoClient
@inline(__always)
@_lifetime(self: copy self)
mutating func decodeNext<T: CommonDecodable & ~Copyable>(_ t: T.Type) throws(CodingError.Decoding) -> T? {
try self.decodeNext { elementDecoder throws(CodingError.Decoding) in
try elementDecoder.decode(t)
}
}
@_alwaysEmitIntoClient
@inline(__always)
@_lifetime(self: copy self)
mutating func decodeRequiredNext<T: ~Copyable>(_ closure: (inout ElementDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T {
guard let result = try self.decodeNext(closure) else {
throw CodingError.valueNotFound(expectedType: T.self)
}
return result
}
@_alwaysEmitIntoClient
@inline(__always)
@_lifetime(self: copy self)
mutating func decodeRequiredNext<T: CommonDecodable & ~Copyable>(_ t: T.Type) throws(CodingError.Decoding) -> T {
return try decodeRequiredNext { elementDecoder throws(CodingError.Decoding) in
try elementDecoder.decode(t)
}
}
var sizeHint: Int? { nil }
}
public extension CommonDecoder where Self: ~Escapable {
@_lifetime(self: copy self)
mutating func decode<Key: CodingStringKeyRepresentable, Value: CommonDecodable>(_: [Key:Value].Type, sizeHint: Int) throws(CodingError.Decoding) -> [Key:Value] {
return try self.decodeDictionary { dictDecoder throws(CodingError.Decoding) in
var accumulatedDictionary = [Key:Value]()
accumulatedDictionary.reserveCapacity(sizeHint)
var key: Key? = nil
try dictDecoder.decodeEachKey { keyDecoder throws(CodingError.Decoding) in
key = try keyDecoder.decodeString(Key.codingStringKeyVisitor)
} andValue: { valueDecoder throws(CodingError.Decoding) in
let value = try valueDecoder.decode(Value.self)
accumulatedDictionary[key!] = value
}
return accumulatedDictionary
}
}
@_lifetime(self: copy self)
mutating func decode<Element: CommonDecodable>(_: [Element].Type, sizeHint: Int) throws(CodingError.Decoding) -> [Element] {
return try self.decodeArray { arrayDecoder throws(CodingError.Decoding) in
var accumulatedArray = [Element]()
accumulatedArray.reserveCapacity(sizeHint)
try arrayDecoder.decodeEachElement { elementDecoder throws(CodingError.Decoding) in
let element = try elementDecoder.decode(Element.self)
accumulatedArray.append(element)
}
return accumulatedArray
}
}
}
public extension CommonDecoder where Self: ~Escapable {
@_lifetime(self: copy self)
mutating func decodeStruct<T: ~Copyable>(_ closure: (inout StructDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T {
throw CodingError.unsupportedDecodingType("struct")
}
@_lifetime(self: copy self)
mutating func decodeDictionary<T: ~Copyable>( _ closure: (inout DictionaryDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T {
throw CodingError.unsupportedDecodingType("dictionary")
}
@_lifetime(self: copy self)
mutating func decodeArray<T: ~Copyable>(_ closure: (inout ArrayDecoder) throws(CodingError.Decoding) -> T) throws(CodingError.Decoding) -> T {
throw CodingError.unsupportedDecodingType("array")
}
// MARK: - Enum Decoding
@_lifetime(self: copy self)
mutating func decodeEnumCase<T: ~Copyable>(
_ closure: (inout FieldDecoder) throws(CodingError.Decoding) -> T
) throws(CodingError.Decoding) -> T {
throw CodingError.unsupportedDecodingType("enum")
}
@_lifetime(self: copy self)
mutating func decodeEnumCase<T: ~Copyable>(
_ closure: (_ caseName: inout FieldDecoder, _ associatedValues: inout StructDecoder) throws(CodingError.Decoding) -> T
) throws(CodingError.Decoding) -> T {
throw CodingError.unsupportedDecodingType("enum")
}
@_lifetime(self: copy self)
mutating func decode(_: Bool.Type) throws(CodingError.Decoding) -> Bool { throw CodingError.unsupportedDecodingType("boolean") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Int.Type) throws(CodingError.Decoding) -> Int { throw CodingError.unsupportedDecodingType("Int") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Int8.Type) throws(CodingError.Decoding) -> Int8 { throw CodingError.unsupportedDecodingType("Int8") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Int16.Type) throws(CodingError.Decoding) -> Int16 { throw CodingError.unsupportedDecodingType("Int16") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Int32.Type) throws(CodingError.Decoding) -> Int32 { throw CodingError.unsupportedDecodingType("Int32") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Int64.Type) throws(CodingError.Decoding) -> Int64 { throw CodingError.unsupportedDecodingType("Int64") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Int128.Type) throws(CodingError.Decoding) -> Int128 { throw CodingError.unsupportedDecodingType("Int128") }
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt.Type) throws(CodingError.Decoding) -> UInt { throw CodingError.unsupportedDecodingType("UInt") }
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt8.Type) throws(CodingError.Decoding) -> UInt8 { throw CodingError.unsupportedDecodingType("UInt8") }
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt16.Type) throws(CodingError.Decoding) -> UInt16 { throw CodingError.unsupportedDecodingType("UInt16") }
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt32.Type) throws(CodingError.Decoding) -> UInt32 { throw CodingError.unsupportedDecodingType("UInt32") }
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt64.Type) throws(CodingError.Decoding) -> UInt64 { throw CodingError.unsupportedDecodingType("UInt64") }
@_lifetime(self: copy self)
mutating func decode(_ hint: UInt128.Type) throws(CodingError.Decoding) -> UInt128 { throw CodingError.unsupportedDecodingType("UInt128") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Float.Type) throws(CodingError.Decoding) -> Float { throw CodingError.unsupportedDecodingType("Float") }
@_lifetime(self: copy self)
mutating func decode(_ hint: Double.Type) throws(CodingError.Decoding) -> Double { throw CodingError.unsupportedDecodingType("Double") }
@_lifetime(self: copy self)
mutating func decode(_: String.Type) throws(CodingError.Decoding) -> String { throw CodingError.unsupportedDecodingType("string") }
@_lifetime(self: copy self)
mutating func decodeString<V: DecodingStringVisitor>(_ visitor: V) throws(CodingError.Decoding) -> V.DecodedValue { throw CodingError.unsupportedDecodingType("string") }
@_lifetime(self: copy self)
mutating func decodeNil() throws(CodingError.Decoding) -> Bool { throw CodingError.unsupportedDecodingType("nil") }
@_lifetime(self: copy self)
mutating func decodeOptional(_ closure: (inout Self) throws(CodingError.Decoding) -> Void) throws(CodingError.Decoding) { throw CodingError.unsupportedDecodingType("optional") }
var supportsDecodeAny: Bool { false }
@_lifetime(self: copy self)
mutating func decodeAny<V: CommonDecodingVisitor>(_ visitor: V) throws(CodingError.Decoding) -> V.DecodedValue { throw CodingError.unsupportedDecodingType("any") }
// @_lifetime(self: copy self)
// mutating func decodePrimitive() throws(CodingError.Decoding) -> CommonCodingPrimitive { throw CodingError.unsupportedDecodingType("primitive") }
/// Decode a value using a visitor, with a hint that a collection of bytes is expected in the encoded data.
///
/// - parameter visitor: An instance of the type that will create the `DecodedValue`
/// from the bytes the decoder makes it visit.
/// - returns: The value created by the `visitor`.
/// - throws: TBD. An error thrown by the `visitor`. Others?
@_lifetime(self: copy self)
mutating func decodeBytes<V: DecodingBytesVisitor>(visitor: V) throws(CodingError.Decoding) -> V.DecodedValue { throw CodingError.unsupportedDecodingType("bytes") }
}
public extension CommonDecodingVisitor where Self: ~Copyable & ~Escapable {
@_lifetime(decoder: copy decoder)
func visit(decoder: inout some CommonStructDecoder & ~Escapable) throws(CodingError.Decoding) -> DecodedValue {
throw CodingError.unsupportedDecodingType("struct")
}
@_lifetime(decoder: copy decoder)
func visit(decoder: inout some CommonArrayDecoder & ~Escapable) throws(CodingError.Decoding) -> DecodedValue {
throw CodingError.unsupportedDecodingType("sequence")
}
func visitNone() throws(CodingError.Decoding) -> DecodedValue {
throw CodingError.unsupportedDecodingType("none")
}
// A conformer of just DecodingBytesVisitor or DecodingStringVisitor is expected to implement these methods, but a general CommonDecodingVisitor does not.
func visitUTF8Bytes(_ buffer: UTF8Span) throws(CodingError.Decoding) -> DecodedValue {
throw CodingError.unsupportedDecodingType("UTF8 string bytes")
}
func visitBytes(_ array: [UInt8]) throws(CodingError.Decoding) -> DecodedValue {
throw CodingError.unsupportedDecodingType("bytes")
}
}