Skip to content

Commit 16f9897

Browse files
committed
Test product
1 parent 787c870 commit 16f9897

File tree

5 files changed

+476
-4
lines changed

5 files changed

+476
-4
lines changed

Sources/BinaryParseKit/CustomExtensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ extension Int: EndianParsable {
8888
}
8989
}
9090

91+
// MARK: - MatchableRawValue
92+
93+
public extension MatchableRawRepresentable where Self.RawValue == UInt8 {
94+
func bytesToMatch() -> [UInt8] {
95+
[rawValue]
96+
}
97+
}
98+
9199
// MARK: - RawRepresentable
92100

93101
//

Sources/BinaryParseKit/ParsableProtocols.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,7 @@ public extension SizedParsable {
142142
self = result
143143
}
144144
}
145+
146+
public protocol MatchableRawRepresentable: RawRepresentable {
147+
func bytesToMatch() -> [UInt8]
148+
}

Sources/BinaryParseKitMacros/Macros/ParseEnum/ConsructParseEnumMacro.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ public struct ConstructEnumParseMacro: ExtensionMacro {
4242
let toBeMatched = if let matchBytes = caseParseInfo.matchAction.matchBytes {
4343
matchBytes
4444
} else {
45-
ExprSyntax("[\(type).\(caseParseInfo.caseElementName).rawValue]") // TODO: add UInt8 __match
45+
ExprSyntax(
46+
"(\(type).\(caseParseInfo.caseElementName) as MatchableRawRepresentable) .bytesToMatch()",
47+
)
4648
}
4749

4850
try IfExprSyntax(
4951
"if \(raw: Constants.UtilityFunctions.matchBytes)(\(toBeMatched), in: &span)",
5052
) {
5153
if caseParseInfo.matchAction.matchPolicy == .matchAndTake {
52-
"try input.seek(toRelativeOffset: \(toBeMatched).count)"
54+
"try span.seek(toRelativeOffset: \(toBeMatched).count)"
5355
}
5456

5557
var arguments: OrderedDictionary<TokenSyntax, EnumCaseParameterParseInfo> = [:]

Tests/BinaryParseKitMacroTests/BinaryParseKitEnumTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ extension BinaryParseKitMacroTests {
208208
extension TestEnum: BinaryParseKit.Parsable {
209209
init(parsing span: inout BinaryParsing.ParserSpan) throws(BinaryParsing.ThrownParsingError) {
210210
if BinaryParseKit.__match([0x01], in: &span) {
211-
try input.seek(toRelativeOffset: [0x01].count)
211+
try span.seek(toRelativeOffset: [0x01].count)
212212
self = .a
213213
return
214214
}
@@ -247,7 +247,7 @@ extension BinaryParseKitMacroTests {
247247
extension TestEnum: BinaryParseKit.Parsable {
248248
init(parsing span: inout BinaryParsing.ParserSpan) throws(BinaryParsing.ThrownParsingError) {
249249
if BinaryParseKit.__match([0x01], in: &span) {
250-
try input.seek(toRelativeOffset: [0x01].count)
250+
try span.seek(toRelativeOffset: [0x01].count)
251251
self = .a
252252
return
253253
}

0 commit comments

Comments
 (0)