Skip to content

Commit 23d52ff

Browse files
committed
Update RFC 1123 Domain label serialization
1 parent fedc0a7 commit 23d52ff

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/RFC 1123/RFC_1123.Domain.Label.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ extension RFC_1123.Domain.Label: Hashable {
7474
// MARK: - Serializable
7575

7676
extension RFC_1123.Domain.Label: UInt8.ASCII.Serializable {
77-
// public static let serialize: @Sendable (Self) -> [UInt8] = [UInt8].init
77+
public static func serialize<Buffer: RangeReplaceableCollection>(
78+
ascii label: Self,
79+
into buffer: inout Buffer
80+
) where Buffer.Element == UInt8 {
81+
buffer.append(contentsOf: label.rawValue.utf8)
82+
}
7883

7984
/// Parses a host label from canonical byte representation (CANONICAL PRIMITIVE)
8085
///

Sources/RFC 1123/RFC_1123.Domain.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
public import INCITS_4_1986
9-
public import RFC_1035
9+
import RFC_1035
1010

1111
extension RFC_1123 {
1212
/// RFC 1123 compliant host name
@@ -94,6 +94,13 @@ extension RFC_1123.Domain: UInt8.ASCII.RawRepresentable {}
9494
extension RFC_1123.Domain: CustomStringConvertible {}
9595

9696
extension RFC_1123.Domain: UInt8.ASCII.Serializable {
97+
public static func serialize<Buffer: RangeReplaceableCollection>(
98+
ascii domain: Self,
99+
into buffer: inout Buffer
100+
) where Buffer.Element == UInt8 {
101+
buffer.append(contentsOf: domain.rawValue.utf8)
102+
}
103+
97104
/// Parses a host name from canonical byte representation (CANONICAL PRIMITIVE)
98105
///
99106
/// This is the primitive parser that works at the byte level.

0 commit comments

Comments
 (0)