Skip to content

Commit ba8b914

Browse files
committed
Use more typesafe parsing
1 parent 4ab6bf6 commit ba8b914

File tree

65 files changed

+3968
-4296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3968
-4296
lines changed

Sources/SwiftNASR/Distribution/ArchiveDataDistribution.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public final class ArchiveDataDistribution: Distribution {
134134
_ = try archive.extract(entry, bufferSize: chunkSize, skipCRC32: false, progress: nil) {
135135
data in
136136
Task { @MainActor in progress.completedUnitCount += Int64(data.count) }
137-
continuation.yield(data)
137+
// Force a copy to avoid ZIPFoundation buffer reuse issues
138+
continuation.yield(Data(data))
138139
}
139140
continuation.finish()
140141
} catch {

Sources/SwiftNASR/Distribution/ArchiveFileDistribution.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public final class ArchiveFileDistribution: Distribution {
155155
_ = try archive.extract(entry, bufferSize: chunkSize, skipCRC32: true, progress: nil) {
156156
data in
157157
Task { @MainActor in progress.completedUnitCount += Int64(data.count) }
158-
continuation.yield(data)
158+
// Force a copy to avoid ZIPFoundation buffer reuse issues
159+
continuation.yield(Data(data))
159160
}
160161
continuation.finish()
161162
} catch {

Sources/SwiftNASR/Models/Records/ATSAirway.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public struct ATSAirway: Record, Identifiable {
8181
public enum PointType: String, RecordEnum, CaseIterable, Equatable, Hashable, Codable, Sendable {
8282
case waypoint = "WAY-PT"
8383
case reportingPoint = "REP-PT"
84-
case VORDME = "VOR/DME"
84+
case VOR_DME = "VOR/DME"
8585
case VORTAC = "VORTAC"
86-
case NDBDME = "NDB/DME"
86+
case NDB_DME = "NDB/DME"
8787
case NDB = "NDB"
8888
case VOR = "VOR"
8989
case DME = "DME"
@@ -93,9 +93,9 @@ public struct ATSAirway: Record, Identifiable {
9393
switch self {
9494
case .waypoint: return "Waypoint"
9595
case .reportingPoint: return "Reporting Point"
96-
case .VORDME: return "VOR/DME"
96+
case .VOR_DME: return "VOR/DME"
9797
case .VORTAC: return "VORTAC"
98-
case .NDBDME: return "NDB/DME"
98+
case .NDB_DME: return "NDB/DME"
9999
case .NDB: return "NDB"
100100
case .VOR: return "VOR"
101101
case .DME: return "DME"

Sources/SwiftNASR/Models/Records/DepartureArrivalProcedure.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public struct DepartureArrivalProcedure: Record, Identifiable {
8282
case navaidAirport = "NA"
8383

8484
/// Navaid - VOR with DME
85-
case navaidVORDME = "ND"
85+
case navaidVOR_DME = "ND"
8686

8787
/// Navaid - DME only
8888
case navaidDMEOnly = "NO"
@@ -105,11 +105,11 @@ public struct DepartureArrivalProcedure: Record, Identifiable {
105105
/// Navaid - LFR
106106
case navaidLFR = "N7"
107107

108-
/// Navaid - VHFRBN
109-
case navaidVHFRBN1 = "N8"
108+
/// Navaid - VHF RBN
109+
case navaidVHF_RBN1 = "N8"
110110

111-
/// Navaid - VHFRBN (alternate)
112-
case navaidVHFRBN2 = "N9"
111+
/// Navaid - VHF RBN (alternate)
112+
case navaidVHF_RBN2 = "N9"
113113

114114
/// Waypoint
115115
case waypoint = "P"

Sources/SwiftNASR/Models/Records/ILS.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ public struct ILS: ParentRecord {
107107
case LDA = "LDA"
108108

109109
/// ILS with Distance Measuring Equipment.
110-
case ILSDME = "ILS/DME"
110+
case ILS_DME = "ILS/DME"
111111

112112
/// SDF with Distance Measuring Equipment.
113-
case SDFDME = "SDF/DME"
113+
case SDF_DME = "SDF/DME"
114114

115115
/// Localizer with Distance Measuring Equipment.
116-
case LOCDME = "LOC/DME"
116+
case LOC_DME = "LOC/DME"
117117

118118
/// Localizer with Glide Slope.
119-
case LOCGS = "LOC/GS"
119+
case LOC_GS = "LOC/GS"
120120

121121
/// LDA with Distance Measuring Equipment.
122-
case LDADME = "LDA/DME"
122+
case LDA_DME = "LDA/DME"
123123

124124
/// Local Area Augmentation System (GBAS).
125125
case LAAS = "LAAS"
@@ -128,10 +128,13 @@ public struct ILS: ParentRecord {
128128
[
129129
"LS": .ILS,
130130
"LD": .LDA,
131-
"LG": .LOCGS,
132-
"LE": .ILSDME,
131+
"LG": .LOC_GS,
132+
"LE": .ILS_DME,
133133
"SD": .SDF,
134-
"LC": .localizer
134+
"SF": .SDF, // Alternative CSV code for SDF
135+
"LC": .localizer,
136+
"DD": .LOC_DME, // CSV code for LOC/DME
137+
"LA": .LAAS // CSV code for LAAS/GBAS
135138
]
136139
}
137140
}

Sources/SwiftNASR/Models/Records/LocationIdentifier.swift

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,51 @@ public struct LocationIdentifier: Record, Identifiable {
108108
/// The group code for location identifiers.
109109
public enum GroupCode: String, RecordEnum, CaseIterable, Equatable, Hashable, Codable, Sendable {
110110
/// United States locations
111-
case usa = "USA"
111+
case USA = "USA"
112112

113113
/// Department of Defense overseas locations
114-
case dod = "DOD"
114+
case DOD = "DOD"
115115

116116
/// Canadian locations
117-
case can = "CAN"
117+
case canada = "CAN"
118+
119+
/// Marshall Islands locations
120+
case marshallIslands = "MH"
121+
122+
/// Palau locations
123+
case palau = "PW"
124+
125+
/// Bermuda locations
126+
case bermuda = "BM"
127+
128+
/// Bahamas locations
129+
case bahamas = "BS"
130+
131+
/// Turks and Caicos Islands locations
132+
case turksAndCaicos = "TC"
133+
134+
/// Federated States of Micronesia locations
135+
case micronesia = "FM"
136+
137+
/// US Minor Outlying Islands (Johnston Atoll, etc.)
138+
case USMinorOutlyingIslands = "TQ"
139+
140+
/// Azores/Portugal DOD facilities
141+
case azores = "PO"
118142

119143
public var description: String {
120144
switch self {
121-
case .usa: return "United States"
122-
case .dod: return "DOD Overseas"
123-
case .can: return "Canada"
145+
case .USA: return "United States"
146+
case .DOD: return "DOD Overseas"
147+
case .canada: return "Canada"
148+
case .marshallIslands: return "Marshall Islands"
149+
case .palau: return "Palau"
150+
case .bermuda: return "Bermuda"
151+
case .bahamas: return "Bahamas"
152+
case .turksAndCaicos: return "Turks and Caicos Islands"
153+
case .micronesia: return "Federated States of Micronesia"
154+
case .USMinorOutlyingIslands: return "US Minor Outlying Islands"
155+
case .azores: return "Azores"
124156
}
125157
}
126158
}
@@ -165,6 +197,9 @@ public struct LocationIdentifier: Record, Identifiable {
165197
/// Combined Center/Radar Approach Control
166198
case CERAP = "CERAP"
167199

200+
/// Military Base Operations
201+
case baseOps = "BASE OPS"
202+
168203
public var description: String { rawValue }
169204
}
170205

Sources/SwiftNASR/Models/Records/Navaid.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public struct Navaid: ParentRecord {
180180

181181
/// True if this navaid is a VOR, VOR/DME, or VORTAC.
182182
public var isVOR: Bool {
183-
type == .VOR || type == .VORDME || type == .VORTAC
183+
type == .VOR || type == .VOR_DME || type == .VORTAC
184184
}
185185

186186
/**
@@ -190,7 +190,7 @@ public struct Navaid: ParentRecord {
190190
automatic direction finder (ADF) set.
191191
*/
192192
public var isNDB: Bool {
193-
type == .NDB || type == .NDBDME
193+
type == .NDB || type == .NDB_DME
194194
}
195195

196196
init(
@@ -320,7 +320,7 @@ public struct Navaid: ParentRecord {
320320
case VORTAC = "VORTAC"
321321

322322
/// A VOR and associated DME facility.
323-
case VORDME = "VOR/DME"
323+
case VOR_DME = "VOR/DME"
324324

325325
/// A localizer marker beacon with an elongated reception cone.
326326
case fanMarker = "FAN MARKER"
@@ -333,7 +333,7 @@ public struct Navaid: ParentRecord {
333333
case marineNDB = "MARINE NDB"
334334

335335
/// An NDB/DME for marine use.
336-
case marineNDBDME = "MARINE NDB/DME"
336+
case marineNDB_DME = "MARINE NDB/DME"
337337

338338
/// A VOR operational test facility. This is a VOR that transmits a
339339
/// fixed bearing signal of 180 TO, for purposes of testing receivers.
@@ -343,14 +343,14 @@ public struct Navaid: ParentRecord {
343343
case NDB = "NDB"
344344

345345
/// An NDB and associated DME facility.
346-
case NDBDME = "NDB/DME"
346+
case NDB_DME = "NDB/DME"
347347

348348
/// A tactical air navigation facility, similar to a VOR but
349349
/// transmitting on UHF frequencies and intended for military use.
350350
case TACAN = "TACAN"
351351

352352
/// An NDB that transmits on UHF frequencies.
353-
case UHFNDB = "UHF/NDB"
353+
case UHF_NDB = "UHF/NDB"
354354

355355
/// A VHF omnidirectional range; a facility that transmits two phased
356356
/// signals for accurately determining bearing.
@@ -367,18 +367,18 @@ public struct Navaid: ParentRecord {
367367
// Single-character codes used in some NASR files (HPF, FSS, FIX, etc.)
368368
public static let synonyms: [String: Self] = [
369369
"C": .VORTAC,
370-
"D": .VORDME,
370+
"D": .VOR_DME,
371371
"F": .fanMarker,
372372
"K": .consolan,
373373
"L": .LFR,
374374
"M": .marineNDB,
375-
"MD": .marineNDBDME,
375+
"MD": .marineNDB_DME,
376376
"O": .VOT,
377377
"OD": .DME,
378378
"R": .NDB,
379-
"RD": .NDBDME,
379+
"RD": .NDB_DME,
380380
"T": .TACAN,
381-
"U": .UHFNDB,
381+
"U": .UHF_NDB,
382382
"V": .VOR
383383
]
384384
}

Sources/SwiftNASR/Models/Records/Record.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,15 @@ extension RecordEnum {
3030
}
3131
}
3232

33+
extension RecordEnum where RawValue == String {
34+
/// Returns the enum value for the raw string, throwing if not found.
35+
static func require(_ raw: String) throws -> Self {
36+
guard let value = Self.for(raw) else {
37+
throw ParserError.unknownRecordEnumValue(raw)
38+
}
39+
return value
40+
}
41+
}
42+
3343
/// Protocol representing fields that remarks can be applied to.
3444
public protocol RemarkField: Codable, Sendable, CaseIterable, Hashable {}

Sources/SwiftNASR/Models/Records/TerminalCommFacility.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ public struct TerminalCommFacility: ParentRecord {
261261
case UHF = "UHF"
262262

263263
/// VHF and UHF direction finding.
264-
case VHFUHF = "VHF/UHF"
264+
case VHF_UHF = "VHF/UHF"
265265

266266
/// Doppler VHF direction finding.
267267
case dopplerVHF = "DOPPLER VHF"
268268

269269
/// Doppler VHF and UHF direction finding.
270-
case dopplerVHFUHF = "DOPPLER VHF/UHF"
270+
case dopplerVHF_UHF = "DOPPLER VHF/UHF"
271271
}
272272

273273
/// Radar service types.

Sources/SwiftNASR/Models/Records/WeatherReportingLocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public struct WeatherReportingLocation: Record, Identifiable {
8787
case SPECI = "SPECI"
8888

8989
/// Transcribed Weather Broadcast Synopses
90-
case TWBSynopses = "SYNS"
90+
case TWEBSynopses = "SYNS"
9191

9292
/// Aviation Terminal Forecast (ICAO)
9393
case TAF = "TAF"

0 commit comments

Comments
 (0)