-
Notifications
You must be signed in to change notification settings - Fork 0
Enum case matching by remaining buffer length #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for matching enum cases using remaining buffer length via a new @match(length:) macro. This enables binary format parsing where variants are determined by data length rather than discriminator byte patterns.
Key Changes:
- Added
@match(length:)macro for non-consuming length-based matching - Enforced mutual exclusivity between byte-based and length-based matching strategies
- Implemented
__matchLength(length:in:)utility function for buffer length checking
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| openspec/changes/add-match-length/proposal.md | Documents the rationale and impact of adding length-based enum matching |
| openspec/changes/add-match-length/specs/parse-enum/spec.md | Specifies requirements for length-based matching and mutual exclusivity validation |
| openspec/changes/add-match-length/tasks.md | Task breakdown for implementing the feature |
| Tests/BinaryParseKitTests/TestEnumParsing.swift | End-to-end tests covering length matching with various scenarios including default fallback |
| Tests/BinaryParseKitMacroTests/BinaryParseKitEnumTests.swift | Macro expansion tests for length matching and mixed strategy diagnostics |
| Sources/BinaryParseKit/BinaryParseKit.swift | Public macro declaration with comprehensive documentation and usage examples |
| Sources/BinaryParseKit/Utils/ParsingUtils.swift | Utility function implementation for non-consuming length checks |
| Sources/BinaryParseKitMacros/Macros/Supports/Constants.swift | Added constant for matchLength utility function |
| Sources/BinaryParseKitMacros/Macros/ParseEnum/ParseEnumMacroError.swift | Added error message for mixed matching strategies |
| Sources/BinaryParseKitMacros/Macros/ParseEnum/ParseEnumCase.swift | Validation logic to enforce matching strategy mutual exclusivity |
| Sources/BinaryParseKitMacros/Macros/ParseEnum/EnumCaseParseInfo.swift | Data structures supporting both byte and length matching targets |
| Sources/BinaryParseKitMacros/Macros/ParseEnum/ConsructParseEnumMacro.swift | Code generation for length-based matching conditions and printer intel |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
openspec/changes/archive/2025-12-23-add-match-length/specs/parse-enum/spec.md
Show resolved
Hide resolved
Sources/BinaryParseKitMacros/Macros/ParseEnum/EnumCaseParseInfo.swift
Outdated
Show resolved
Hide resolved
Sources/BinaryParseKitMacros/Macros/ParseEnum/ConsructParseEnumMacro.swift
Outdated
Show resolved
Hide resolved
Sources/BinaryParseKitMacros/Macros/ParseEnum/ConsructParseEnumMacro.swift
Outdated
Show resolved
Hide resolved
openspec/changes/archive/2025-12-23-add-match-length/specs/parse-enum/spec.md
Show resolved
Hide resolved
openspec/changes/archive/2025-12-23-add-match-length/specs/parse-enum/spec.md
Show resolved
Hide resolved
3620314 to
7be7bee
Compare
7be7bee to
0cb1b72
Compare
This PR adds support of matching enum case using remaining buffer length. This matching method is exclusive with byte matching.
The changes (implementation, test, and specs) are reviewed by the owner.