Increase code reuse for frame parsing with shared payload functions - #69
Merged
Conversation
…cript generators Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Increase code reuse for frame parsing
Increase code reuse for frame parsing with shared payload functions
Dec 4, 2025
Contributor
|
@copilot regenerate the boilerplate files |
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Contributor
Author
rijesha
requested changes
Dec 4, 2025
rijesha
left a comment
Contributor
There was a problem hiding this comment.
Each framer doesnt need its own file. Further code reuse can occur by using classes, templates and typedefs.
Contributor
Author
That's a good suggestion for further consolidation. Would you like me to implement this in the current PR, or should this be tracked as a separate follow-up issue? The current implementation adds shared payload parsing functions that frame formats call, but consolidating into fewer files using classes/templates would be a larger architectural change. |
rijesha
marked this pull request as ready for review
December 4, 2025 22:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the frame parser generators to increase code reuse by implementing shared payload parsing functions that can be used across different framing schemes (Tiny/Basic/None).
Changes:
Added shared payload parsing functions to the base utilities in all language generators:
validate_payload_with_crc()- Validates payloads with CRC checksumsvalidate_payload_minimal()- Validates minimal payloads (no CRC)encode_payload_with_crc()- Encodes payloads with length field and CRCencode_payload_minimal()- Encodes minimal payloads (no CRC)Modified frame format generators to use the shared functions in
parse_byte(),encode(), andvalidate_packet()methodsAdded utility methods to FrameFormat class for identifying payload types
Regenerated all 120 boilerplate files with the updated generators
How it works:
Previously, TinyDefault and BasicDefault had completely duplicated payload parsing logic. Now they both call the same shared function with different CRC start offsets:
validate_payload_with_crc(buffer, HEADER_SIZE, 1, 1)validate_payload_with_crc(buffer, HEADER_SIZE, 1, 2)All tests pass (37/41 - same as baseline, pre-existing issues)
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.