-
Notifications
You must be signed in to change notification settings - Fork 7
Added support for returning Unions #6
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: dev
Are you sure you want to change the base?
Conversation
Can you explain what exactly are you trying to parse? I think we could add support for Regarding Also, I think you have missed this section in the README You can simply define your own type overrides, both for reading and writing, and they can be different so it should be enough for your use-case. For example here, I am only defining |
Well, regarding hooks, you are completely right, I could have add it there, but seems like a quality-of-life thing, when dealing with custom data coming from files that with a small tweak more people could use it In my case, when decoding a protobuf from a singular data-frame, it might result in a lot of different structs, or array of structs, and for me the best way to handle them is to get them into a union, and then just receive a value on the JS side. I'm gonna mark here that I'm doing my project as a starting point in zig, as I never used any low level language, so that might not make sense, but thought that someone might use this Union support. In |
Ok, can you change the PR to point into the |
Removed u8, comment and changed do dev branch |
Hm, I just noticed you are not using the union tag anywhere in the result. This is a problem, suppose you have struct like this:
and now if you try to pass it to the JS-side (so your new I think this is a reason why I did not include the Union impl in the first place, I wanted to have some thinking about it first. What we do, must be reversible, so what I'd suggest is probably encoding the value with "prefix" field for the tag:
|
Sounds good, I'll try to implement it |
We should also support parsing, it will be trickier, so I can do it myself, but if you feel into it here's what's needed:
|
Ill try during the weekend |
I'm making a JS parser for Counter-Strike 2 demo files, and there are a lot of different protobufs and structs that might be returned, so for ease of DX I added support of Unions for defaultWrite.