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

How to support repeated structs? #16

Open
aholtzma-am opened this issue Feb 9, 2022 · 4 comments
Open

How to support repeated structs? #16

aholtzma-am opened this issue Feb 9, 2022 · 4 comments

Comments

@aholtzma-am
Copy link
Contributor

We are looking at adding the NavSat message, but it there doesn't seem to be a way to support repeated structs. Is there a way to do this or is it just not supported yet?

@aholtzma-am aholtzma-am changed the title How to support repeated types? How to support repeated structs? Feb 9, 2022
@lkolbly
Copy link
Collaborator

lkolbly commented Feb 10, 2022

Yeah, there isn't really currently a great way to support NavSat-style repeated messages.

I think the way to do it (and I can look into adding the necessary infrastructure, probably this weekend or next) would be to extend the derive macros to have an explicit notion of arrays, and then the field accessor function could take an index, something like this:

navsat_packet.num_svs(); // Number of SVs
navsat_packet.svs(5).gnssId(); // Get the gnssId of space vehicle 5

although, you'd want to be able to catch if the user passed an invalid index, so maybe it should look more like:

navsat_packet.svs(5).unwrap().gnss_id();

and I imagine a common operation is iterating over the SVs... so maybe it could just return an iterator. Something like:

for sv in navsat_packet.svs() {
    sv.gnss_id();
}

and, of course, you the end user would still be able to select the nth navsat by using the nth function:

navsat_packet.svs().nth(5).unwrap().gnss_id();

Does that seem like a reasonable API to you?

@aholtzma-am
Copy link
Contributor Author

This would work 100% for us.

@aholtzma-am
Copy link
Contributor Author

You might want to take a look over at:

connectedcars#1

They have added vec<> types to the code generator among other things. Not sure if they plan to upstream it.

@lkolbly
Copy link
Collaborator

lkolbly commented Feb 16, 2022

Awesome, thanks, I will definitely keep tabs on that.

It turns out that implementing NavSat wasn't as hard as I thought it'd be, or at least to cobble something together which I've pushed to master. I'm still working on CI stuff, but it works with my device.

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

2 participants