···5First build the package in release mode with the fuzzer and address checkers on:
67```bash
8-swift build -c release --sanitize fuzzer,address
9```
1011Then run it:
···5First build the package in release mode with the fuzzer and address checkers on:
67```bash
8+swift build -c release --sanitize fuzzer
9```
1011Then run it:
···68 }
69 }
7071+ /// Decodes multiple instances of the given type from CBOR binary data.
72+ ///
73+ /// Some BLOBs are made up of multiple CBOR-encoded datas concatenated without valid CBOR dividers (eg in an array
74+ /// container). This method decodes that kind of data. It will attempt to decode an instance of the given type,
75+ /// once done, if there's more data, it will continue to attempt to decode more instances.
76+ ///
77+ /// - Parameters:
78+ /// - type: The decodable type to deserialize.
79+ /// - data: The CBOR data to decode from.
80+ /// - Returns: An instance of the decoded type.
81+ /// - Throws: A ``DecodingError`` with context and a debug description for a failed deserialization operation.
82+ public func decodeMultiple<T: Decodable>(_ type: T.Type, from data: Data) throws -> [T] {
83+ do {
84+ return try data.withUnsafeBytes {
85+ let data = $0[...]
86+ let reader = DataReader(data: data)
87+ let scanner = CBORScanner(data: reader, options: options)
88+ let results = try scanner.scan()
89+90+ guard !results.isEmpty else {
91+ throw ScanError.unexpectedEndOfData
92+ }
93+94+ let context = DecodingContext(options: options, results: results)
95+ var nextRegion: DataRegion? = results.load(at: 0)
96+97+ var accumulator: [T] = []
98+99+ while let region = nextRegion {
100+ let value = try SingleValueCBORDecodingContainer(context: context, data: region).decode(T.self)
101+ accumulator.append(value)
102+ let nextMapIndex = results.siblingIndex(region.mapOffset)
103+ if nextMapIndex < results.count {
104+ nextRegion = results.load(at: results.siblingIndex(region.mapOffset))
105+ } else {
106+ nextRegion = nil
107+ }
108+ }
109+110+ return accumulator
111+ }
112+ } catch {
113+ if let error = error as? ScanError {
114+ try throwScanError(error)
115+ } else {
116+ throw error
117+ }
118+ }
119+ }
120+121 private func throwScanError(_ error: ScanError) throws -> Never {
122 switch error {
123 case .unexpectedEndOfData: