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

change IsoTPConfig into builder pattern #72

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

pd0wm
Copy link
Contributor

@pd0wm pd0wm commented Sep 3, 2024

Before:

    let mut isotp_config = IsoTPConfig::new(0, Identifier::Standard(0x7a1));
    isotp_config.padding = config.padding;
    isotp_config.fd = config.fd;
    isotp_config.ext_address = config.ext_address;
    isotp_config.timeout = std::time::Duration::from_millis(1000);
    isotp_config.max_dlen = config.max_dlen;

After:

  let isotp_config = IsoTPConfig::default()
        .tx(Identifier::Standard(0x7a1))
        .padding(config.padding)
        .fd(config.fd)
        .ext_address(config.ext_address)
        .max_dlen(config.max_dlen);

Maybe use separate builder type containing the offset? This would mean you always have to call .build() to finish the type. Now you could try setting the offset before the tx id, or the rx id before the tx id, and it would't work. E.g. the following fails silently:

  let isotp_config = IsoTPConfig::default()
        .offset(8)
        .tx(Identifier::Standard(0x7a1))

or

  let isotp_config = IsoTPConfig::default()
        .rx(Identifier::Standard(0x123))
        .tx(Identifier::Standard(0x7a1))

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.

1 participant