mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
Add support for encoding/decoding binary data
This commit is contained in:
1 parent
5aaca631da
commit
b797a6ff50
11 files changed
+211
-12
No files matched your search
@@ -11,6 +11,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
import Foundation
|
||||
import StructuredHeaders
|
||||
|
||||
public struct StructuredFieldDecoder {
|
||||
@@ -58,7 +59,15 @@ extension StructuredFieldDecoder {
|
||||
let parser = StructuredFieldParser(data)
|
||||
let decoder = _StructuredFieldDecoder(parser, keyDecodingStrategy: self.keyDecodingStrategy)
|
||||
try decoder.parseItemField()
|
||||
return try type.init(from: decoder)
|
||||
|
||||
// An escape hatch here for top-level data: if we don't do this, it'll ask for
|
||||
// an unkeyed container and get very confused.
|
||||
if type is Data.Type {
|
||||
let container = try decoder.singleValueContainer()
|
||||
return try container.decode(Data.self) as! StructuredField
|
||||
} else {
|
||||
return try type.init(from: decoder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user