-
Notifications
You must be signed in to change notification settings - Fork 47
Refactor Parser #163
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
base: develop
Are you sure you want to change the base?
Refactor Parser #163
Conversation
| return PARSER_INCOMPLETE; | ||
| } | ||
|
|
||
| parser_return_state_t parse_sever_settings_message(snapcast_custom_parser_t *parser, |
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.
You could put all those variables passed to the functions in a struct/union combination.
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.
Yes! I will do this, once the parser is simplified. I think I will be able to remove a lot of parameters corresponding to internal parser state first.
|
Before you continue your effort maybe we should check if netconn api is really the best thing to use. There have been some packet delivery issues on my last tests and I am uncertain where this comes from. Also espressif says netconn is less resource intensive but when asking chatGPT I get this for an answer So I am abit confused now and I think a comparison of the two should be done by logging max heap usage while reception. Maybe we can integrate this into http_task and just drop all the data and do the same using sockets |
|
With the new connection component, I was able to drastically simplify the parser. I know this isn't perfect yet and I'll probably spend some more time cleaning this up. Some thoughts:
Let me know if you have feedback! |
| #include "player.h" // needed for coded_type_t | ||
|
|
||
|
|
||
| #define BASE_MESSAGE_STATE 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.
Make this an enum or maybe even a type
There is a function
I agree, netconn gives you a buffer on which we operate dirtectly with its size, so maybe a function that gets the current buffer pointer and remaining size would be better.
I like this, this will improve portability quite a bit. |
|
@blattm what are your plans for this PR? There have been some changes so you need to adapt to those. I am asking because I like your changes a lot but I wanted to rework the task communication/synchronization. So I could do that based on the current dev branch (then you would need to include these changes as well) or wait until your work is done. If you are planing to finish it soon I would prefer to wait. |
|
Hey everyone, and happy new year! Sorry for the long silence on my side. I initially had fairly ambitious plans to build an extremely clean solution, restructuring almost everything touched by this PR. But that turned out to be a bit more than I can realistically handle right now. My suggestion would be to merge the PR as it is (or with only minimal changes required for code quality) and take care of any newer commits on the dev branch. That would allow me to get back to feature work and bug fixes and possibly revisit the refactoring later, when it’s less of a burden. I’m currently ill and won’t be able to actively work on this for the next one or two weeks. Feel free to wrap this up and merge it on your side. Otherwise, I’ll take care of it once I’m back. Thanks again for all your work and keeping things moving :) |
|
Happy new year, and get well soon! @CarlosDerSeher do you think this is in a state where it could be merged (after solving all the conflicts from UI and time message changes)? I am not sure if I have time, but I might give it a try. If solving the conflicts is all that is needed. Did not look into details yet. |
|
Last time I checked it looked quite mature to me. There has been one minor thing, the passing of a lot of different parameters to the functions. Those could be aggregated into a single struct. It's been a while I had a look though.l, maybe there is more ro be done. |
|
Another thing, I don't like the name of the component |
|
Alright, I'm back :) |
|
Use develop as it most up to date |
…using local scope
|
I’ve significantly reduced the number of parameters passed to These values now live in much smaller scopes: either directly inside Strongly reducing the parameter count further would likely mean grouping values with little semantic connection into a shared struct. I’m not sure that would improve readability or maintainability. But I may also be missing what kind of refactoring you have in mind. If you’d like me to continue in this direction, a concrete example of the struct or grouping you’re thinking of would really help. Let me know if the current state works for you. If so, I’ll resolve the conflicts and get things wrapped up 🙂 |
|
Thank you. Hopefully I'll find some time to review soon. Maybe someone else will jump in sooner? |
|
I just had a look at the conflicts and it's ... a lot. Maybe it makes sense to postpone the review until the conflicts are resolved? I'm not sure. But I guess I'll already start working toward resolving the conflicts, because this will only get worse the more |
Hi!
This PR aims to improve the readability of
main.cby separating parsing logic from message handling.Although the code is already separated, it's not perfect, and there is still work to be done. There are, for example, too many variables being passed in function calls for my taste.
I'm planning to write a
read_bytefunction that the parser can call. If would fetch data from the network when the buffer is empty. This would allow us to eliminate theswitch/caseand make many variables locally scoped. I would use error codes to detect whether a reset (corresponding to the outermost while loop of the ´http_get_task`) is necessary.It might also make sense to further modularize the message-handling side (e.g., splitting out time sync, codecs, etc.), but that can easily be done in a later PR.