-
-
Notifications
You must be signed in to change notification settings - Fork 159
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 BDAddr #81
Refactor BDAddr #81
Conversation
I definitely like the direction this is going, though do note that your current version is failing on macOS and Windows. I think you're fine to move on to UUID, though I did bring in #80 (as I'm about to do a quick point release to fix Windows UWP reads), but you can integrate that in as you need. The I don't think bringing in |
The A question of style: Do you prefer having bigger modules ( Once, I did a refactoring from For now I'll focus on refactoring UUIDs. |
Looks like everything built on the latest commit, so that's positive. And smaller modules, please! The big modules came in with the libraries I imported, I'm much more a fan of submodules and re-exporting. For the nom stuff, it's really hard to say how much that matters other than the conflicting dependencies, especially if we start looking toward dbus again for bluez. The RSSI is now important for me too (My library that depends on this now advertises RSSI relay capabilities, and yet, I have no RSSI here... >.> ), so hopefully that can be looked at soon. |
So first work on UUIDs is done. I decided that its most practical to use I can't guarantee that the Windows version still works or that I didn't introduce bugs. I tried to adapt what was possible but when I the need to reverse bytes here and there makes my head hurt. In addition, I have only a Linux machine to test, so I don't even know if it compiles. Is there a way to do (at least) a |
After the issues I had with the macOS read/write patches, I'll be testing this throughly across all platforms before landing, because it directly affects users of my libraries that depend on this. 👍 So far, according to CI it looks like the only thing catching you on windows is a &u16 to u32 miscast, so not too horrible? |
Yes the fixing errors caught by the pipelines is easy but I don't wanted to fix each error separately, push a single commit, wait for CI, iterate and so on. This also costs pipeline time, I think? What really bothers me is that I often read that Windows GUIDs are little endian and the |
Well, looks like you pass CI now at least. And I do all my development on windows (and the vast number of users of this library are also on windows, and probably don't know they're using this library), so like I said, I'll at least give it a runthru before landing. :) |
Actually, how about using eui48 for mac address? That crate seems pretty slim and seems to be treated as de-facto mac address crate in crate like tokio-postgres. |
@MattesWhite Hi! Any chance you could rebase the BDAddr changes against the latest dev branch? The diff is a bit hard to follow at the moment. I've done something a bit similar for UUIDs in #123, but using the type from the |
cde5f12
to
39000b2
Compare
I've rebased it on to the current |
39000b2
to
a1309d7
Compare
let b: [u8; 6] = uuid.as_bytes()[0..6].try_into().unwrap(); | ||
BDAddr::try_from(b).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of refactors that didn't quite survive the rebase was this. It may be worth reviewing as I ended up applying a dirty fix so that macOS/iOS would still build
Hi all, sorry for the late response. Lately I don't have much time to monitor the progress of Feel free to edit this PR as much as you like. I'm happy that at least some pieces of my code end up in the crate. If there are any questions I'll be happy to help. |
src/api/bdaddr.rs
Outdated
Ok(Self { address }) | ||
} | ||
/// Writes the address without delimiters. | ||
pub fn write_flat(&self, f: &mut impl fmt::Write) -> fmt::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually used anywhere? I'd be inclined to leave it and to_string_flat
out unless you have a usecase in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this was my initial motivation to write this PR (see #68 (comment)). I'm working on a 'Bluetooth gateway' where the BDAddr of devices is used as the identifier in a REST API. As the default :
in MAC addresses is also a valid separator in URIs I use this flat format. eui48
provides a similar format.
Don't know if this is enough to justify its existence in btleplug
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least I renamed it to _no_delim
instead of _flat
src/api/bdaddr.rs
Outdated
let mut address = [0; 6]; | ||
for i in (0..12).step_by(2) { | ||
let part = &s[i..i + 2]; | ||
address[i / 2] = u8::from_str_radix(part, 16).expect("Checked upfront"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than checking twice, remove the is_ascii_hexdigit
check above, and return the error here instead.
impl From<u64> for BDAddr { | ||
fn from(int: u64) -> Self { | ||
let mut cpy = [0; 6]; | ||
let slice = int.to_be_bytes(); // Reverse order to have MSB on index 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the top two bytes are 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a problem/error? Would you rather use TryFrom
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's better. Done this myself.
57fe4f6
to
65d4c8f
Compare
Corrected the inverse store order. Added more display and parse options.
Is replaced by general tests on BDAddr.
65d4c8f
to
19626ca
Compare
This PR follows the discussion of #68.
At last I found some time to work on this. For now I refactored
BDAddr
as a show case what I intend to do. If the implementation is approved I'll start working onUUID
. Of course I'll include the changed suggested in #80 as well.Initially, I wanted to write the parsers with
nom
but I recognized that there is a bunch ofnom v4
code in the crate so I settled for a 'hand-crafted' version. Another solution would be to useregex
but I didn't wanted to pull in another dependency without asking.