nickbabcock / jomini

Parses Paradox files into javascript objects
MIT License
78 stars 9 forks source link

Binary format #101

Closed jerzakm closed 1 year ago

jerzakm commented 1 year ago

Do you plan to maybe add bindings for parsing binary files? Autosaves for some (all?) games are forced into binary format and it'd be very convenient to not have to manually use the rust lib.

nickbabcock commented 1 year ago

Do you have an API example in mind of how the binary format would be represented and used if exposed?

jerzakm commented 1 year ago

What if it was similar to the existing parseText?

import { Jomini } from "jomini";
const data = // binary data, read from autosave.v3 for example
const parser = await Jomini.initialize();

variant 1 - everything happens in 1 step. Binary to js object

const out = parser.parseBinary(data);

variant 2 - 2 steps. First binary to text, then text to js object

const text = parser.parseBinary(data);
//or
const text = parser.binaryToText(data);
//or - consistent with rakaly naming
const text = parser.meltBinary(data);

const out = parser.parseText(data);

binaryToText might be the clearest one, I think parseBinary implies that the save gets parsed all the way like in variant 1.

I'm not super familiar with Rust and wasm binding gotchas when it comes to this stuff, so please don't spend too much time on something like this on my account :) If it requires more than adding simple bindings then maybe this is the excuse I needed to finally dip more into rust-world.

nickbabcock commented 1 year ago

The biggest hurdle is that many keys of binary objects are numbers. The number->string key mapping changes per game and per patch and paradox said no last time I asked if I could release this map. So in order to implement melting, the api would need to accept a user supplied map, which seems like a pretty big hurdle. So I've been wary of adding it with a big caveat

jerzakm commented 1 year ago

I wasn't aware of the binary mapping issue, thanks for explaining. I think I'll just hack in rakaly-cli and call it good enough for now.

nickbabcock commented 1 year ago

Sounds good, let me know if there's more I can do to assist.