Replies: 1 comment
-
There are a few ways to do this. The cleanest I can think of is to replace enum AppSection {
#[br(magic = 0u32)] End,
Section { /* existing fields */ }
} Then you just check if it is the There are some other options I can think of but I don’t think any of them would be much less hacky than what you are doing already. The count thing certainly seems like a bug with the output ordering of the code generator. I have fixed this in a personal branch, but I am waiting to push things to the main repository because:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm trying to parse the binary format Valve uses for Steam's
appinfo.vdf
file as documented here (thanks to the folks over at SteamDB).The format is as follows:
The primary challenge I faced was that the format provides no count on how many "app sections" there are in a given
appinfo.vdf
file. Rather, it seems you're just expected to continue parsing until at one point you start parsing a new "app section" and encounter a u32 with value 0.I had some trouble expressing this in
binrw
. I have a solution, but it feels clunky and wrong. Currently, I do the following:As you can see, I've simply used
#[br(parse_with = until_exclusive(|section: &AppSection| section.appid == 0))]
to stop parsing when a parsedAppSection
has anappid
of 0. On top of that, I ignore parsing all other fields with#[br(if(appid != 0))]
if theappid
is 0. This feels a bit ugly, as I actually don't even want to attempt parsing anAppSection
when I encounter a u32 with value 0 at the start.To make matters worse, it seems the
count
directive takes precedence over theif
directive. Before I fixed this, the following code caused a panics:Why? I need to subtract 36 here because of some format quirk. But whenever
appid
is 0, thesize
field is not properly read (obviously), but thecount
directive is still executed. This results in0 - 36
being performed for a u32, which obviously panics. The ugly fix I had to make for this was to add a default value of 36 to thesize
field.All of this totally works, but it feels very wrong and hacky to me. My two questions are as follows:
until_exclusive
directive here? If so, what is the proper way of dealing with "parsing into you encounter byte X"?count
directive seems to take precedence over theif
directive?Thank you!
Beta Was this translation helpful? Give feedback.
All reactions