-
Notifications
You must be signed in to change notification settings - Fork 47
Dynamically deserialize networktables structs #225
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
Conversation
Leaving this comment here to let you know that this is on my list of things to review, it's just a lot of changes and will take a bit of time to go through, I should have some time next week Excellent work though, I'm very impressed with the implementation! |
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.
Sorry for taking so long to get to this!
I'm very impressed that you were able to get this implemented! In the past I've avoided adding struct decoding since it felt out of scope with Elastic, but with more recent (and planned) struct integration throughout WPILib it would make sense to have the ability to display (but not edit) individual struct fields.
That being said though, there's still some things I would like to have changed/fixed. Firstly, I'm a bit confused between the difference between NT4StructMeta
and DynStructSchema
. I'm also not sure if it entirely makes sense to have the widgets store the entire schema in its json, since it means that any time a struct field widget is created, it will assume that the schema has never changed. For example, if a widget is created with a struct schema for some type of Swerve State, but then the dashboard connects to a robot with a different struct that has the same name, the widget will always assume that it's the same which can cause invalid values to be displayed. It might make sense to instead store the name of the struct and its field, and have it looked up whenever a new value comes in.
Lastly, I would want to have unit tests for the schema parsing, decoding, and displaying. Right now that might not be easy to add since there's a lot of stuff still being changed around, but I would definitely want lots of these new features in unit tests before being merged. They can be a pain to write, but they've saved me from breaking a lot of important features.
Thanks for reviewing it and sorry for the late reply. Comps keep me busy! DynStructSchema is a data class that contains the schema of the struct (i.e. fields and field names) NT4StructMeta contains a NT path to the root value (containing the entire struct and all of its data), a path to the subvalue (e.g. I'm 80% sure the code as it stands will bail out by showing raw bytes if the schemas don't line up for some reason. |
I went ahead and removed ntStructMeta from the multitopic widgets |
I just rebased this branch since the merges were getting very messy. I think I preserved the proper changes but I'm not entirely sure. Let me know when you would like me to re-review this, since I'd like to add this into the 2026 beta. |
i was in the middle of adding typechecking to nt types so I committed those changes too. im going to mark this as a draft until i finish fixing tests |
Also there's a problem where widgets in list layouts are too small. Dunno why that's happening; afaik I didn't change anything relating to that |
i successfully managed to rebase this onto the new formatter branch |
Thanks for finishing this up! Before I can do another full review, could you undo the formatting changes? For a PR of this size it's much easier to review when the formatting remains the same since there's a lot of changes unrelated to the PR |
- Remove schema to/from json - Store schema name - Use getter for type
- fromJson methods - startByte getter - old commented out code
- Text display no longer displays "null" - Fix error when struct path is invalid - Don't display "Intance of 'NTStruct'" - Change display value when editing struct meta
- Fixes map lookup error when updating subscriptions
- Also add more clarifying comments
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.
After a lot of work and reworking, this PR is now ready to be merged into main. Thank you for adding this feature. Although a lot of the code was changed, the initial implementation was a huge part of the PR.
Here's a list of the major changes that have been made:
- Unit tests for everything
- Modifying struct parsing and decoding to match WPILib's struct spec
- Better error handling for edge cases
- Several fixes relating to edge cases, saving/loading schemas, and handling user edits
- Removing NTStructValue, instead using a dynamic type
- Make
SchemaManager
an instance variable forNTConnection
There's several other minor changes that were also made, if you're interested, you can look through all of the commits made.
I do expect for there to be some issues that will pop up during beta, but the feature has been very stable throughout testing.
Very simply, we get struct information by listening for all announced topics and if it is has type
structschema
, we store it and parse as-needed into aDynStructSchema
(lib/services/struct_schemas/dyn_struct.dart
). When we subscribe to or get data from a topic that uses a schema, we provideDynStructSchema
along with theUint8List
toDynStruct
which recursively parses struct fields and values.I also made saving actually save to a file