Skip to content
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

Refactor ERD encode/decode methods #4

Open
ajmarks opened this issue Nov 29, 2020 · 0 comments
Open

Refactor ERD encode/decode methods #4

ajmarks opened this issue Nov 29, 2020 · 0 comments
Assignees

Comments

@ajmarks
Copy link
Owner

ajmarks commented Nov 29, 2020

Many of the ERD code values are represented by Enums, NamedTuples, or similar. Currently, translation between those occurs in a bunch of tiny functions in erd_utils.py. This is gross and cumbersome. Rather, we should have a protocol like

class ErdValueP(Generic[T]):
    def erd_encode(self, value: T) -> bytes: ...
    def erd_decode(self, raw_value: bytes) -> T: ...

and have each of those special types implement the protocol. Unencodable values can simply raise a NotImplementedError or similar. The Appliance.{encode/decode}_erd_value methods can then be updated to simply dispatch to the correct object's method.

We'll also probably need a register_erd_type(erd_code: ErdType) decorator to set up dispatch to the correct decoded.

@ajmarks ajmarks self-assigned this Nov 29, 2020
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

No branches or pull requests

1 participant