Skip to content

Increase code reuse with GenericFrameParser base classes - #71

Merged
rijesha merged 3 commits into
mainfrom
copilot/increase-code-reuse
Dec 4, 2025
Merged

Increase code reuse with GenericFrameParser base classes#71
rijesha merged 3 commits into
mainfrom
copilot/increase-code-reuse

Conversation

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

Each frame format was generating nearly identical parser code. This refactors to use configuration-based generic parsers, reducing per-format code by ~78%.

Changes

  • TypeScript/JavaScript: Added GenericFrameParser class, FrameParserConfig interface, and createFrameParserClass() factory
  • Python: Added GenericFrameParser class, FrameParserConfig dataclass, and create_frame_parser_class() factory
  • Generators: Updated frame_parser_ts_gen.py and frame_parser_py_gen.py to emit configuration-based code
  • Boilerplate: Regenerated all 120 boilerplate files

Before/After

Before (~160 lines per format):

export class BasicDefault {
    static readonly START_BYTE1 = 0x90;
    static readonly START_BYTE2 = 0x71;
    // ... 150+ lines of parsing/encoding logic
}

After (~35 lines per format):

export const BasicDefaultConfig: FrameParserConfig = {
    name: 'BasicDefault',
    startBytes: [0x90, 0x71],
    headerSize: 4,
    footerSize: 2,
    hasLength: true,
    lengthBytes: 1,
    hasCrc: true,
};

export const BasicDefault = createFrameParserClass(BasicDefaultConfig);

C/C++ already use shared inline functions from frame_base.h, which is the idiomatic approach for those languages.

Original prompt

This section details on the original issue you should resolve

<issue_title>Increase Code reuse</issue_title>
<issue_description>
Each framer doesnt need its own file. Further code reuse can occur by using classes, templates and typedefs.
Ensure that boilerplate code is regenerated.</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 4, 2025 22:42
…pt, and Python

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] Refactor code to increase reuse with classes and templates Increase code reuse with GenericFrameParser base classes Dec 4, 2025
Copilot AI requested a review from rijesha December 4, 2025 22:48
@rijesha
rijesha marked this pull request as ready for review December 4, 2025 22:52
@rijesha
rijesha merged commit 17b19fc into main Dec 4, 2025
@rijesha
rijesha deleted the copilot/increase-code-reuse 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

2 participants