Skip to content

Conversation

@FlickerSoul
Copy link
Owner

@FlickerSoul FlickerSoul commented Dec 23, 2025

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.

Copilot AI review requested due to automatic review settings December 23, 2025 03:22
Copy link

Copilot AI left a 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.

@FlickerSoul FlickerSoul force-pushed the feat/enum-match-by-length branch from 3620314 to 7be7bee Compare December 23, 2025 11:51
@FlickerSoul FlickerSoul force-pushed the feat/enum-match-by-length branch from 7be7bee to 0cb1b72 Compare December 23, 2025 11:52
@FlickerSoul FlickerSoul enabled auto-merge (squash) December 23, 2025 12:10
@FlickerSoul FlickerSoul merged commit d8da52a into main Dec 23, 2025
2 checks passed
@FlickerSoul FlickerSoul deleted the feat/enum-match-by-length branch December 23, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants