Skip to content

Increase code reuse for frame parsing with shared payload functions - #69

Merged
rijesha merged 4 commits into
mainfrom
copilot/reduce-code-duplication
Dec 4, 2025
Merged

Increase code reuse for frame parsing with shared payload functions#69
rijesha merged 4 commits into
mainfrom
copilot/reduce-code-duplication

Conversation

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor
  • Investigate current frame parser generator architecture
  • Design refactored approach to separate framing (sync bytes) from payload parsing
  • Add payload type base functions that can be reused across frame types
  • Modify Python generator to use shared payload parsers
  • Modify TypeScript generator to use shared payload parsers
  • Modify JavaScript generator to use shared payload parsers
  • Modify C generator to use shared payload parsers
  • Modify C++ generator to use shared payload parsers
  • Verify generated code compiles and tests pass
  • Run code review and address feedback
  • Run CodeQL security scan
  • Regenerate boilerplate files

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:

  1. Added shared payload parsing functions to the base utilities in all language generators:

    • validate_payload_with_crc() - Validates payloads with CRC checksums
    • validate_payload_minimal() - Validates minimal payloads (no CRC)
    • encode_payload_with_crc() - Encodes payloads with length field and CRC
    • encode_payload_minimal() - Encodes minimal payloads (no CRC)
  2. Modified frame format generators to use the shared functions in parse_byte(), encode(), and validate_packet() methods

  3. Added utility methods to FrameFormat class for identifying payload types

  4. 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:

  • TinyDefault: validate_payload_with_crc(buffer, HEADER_SIZE, 1, 1)
  • BasicDefault: validate_payload_with_crc(buffer, HEADER_SIZE, 1, 2)

All tests pass (37/41 - same as baseline, pre-existing issues)

Original prompt

This section details on the original issue you should resolve

<issue_title>Increase code reuse for frame parsing</issue_title>
<issue_description>The frame payloads parsing should be defined once and framing schemes should utilize the same base classes.

i.e TinyDefault and BasicDefault should call the same default parser once it has a full packet.

This will reduce the amount of code. The base parser should also be the same. The Tiny and Default Frame should call the same base parser. </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI and others added 2 commits December 4, 2025 20:11
…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
Copilot AI requested a review from rijesha December 4, 2025 20:22
@rijesha

rijesha commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

@copilot regenerate the boilerplate files

Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

@copilot regenerate the boilerplate files

Regenerated all 120 boilerplate files with the shared payload parsing functions in commit d7bdf07.

@rijesha rijesha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each framer doesnt need its own file. Further code reuse can occur by using classes, templates and typedefs.

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

Each framer doesnt need its own file. Further code reuse can occur by using classes, templates and typedefs.

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.

Copilot AI requested a review from rijesha December 4, 2025 21:33
@rijesha
rijesha marked this pull request as ready for review December 4, 2025 22:30
@rijesha
rijesha merged commit 9a166e7 into main Dec 4, 2025
1 check passed
@rijesha
rijesha deleted the copilot/reduce-code-duplication branch December 6, 2025 03:20
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.

Increase code reuse for frame parsing

2 participants