keichi / binary-parser

A blazing-fast declarative parser builder for binary data
MIT License
857 stars 133 forks source link

Choice keyString returns entire string #209

Closed shaynem closed 1 year ago

shaynem commented 2 years ago

Choices seem to be broken in some instances, even though tag is int8

I have not fully tested, however I think it may have something to do with strict mode.

Working replacement

 Object.keys(options.choices).forEach(async (keyid) => {
            const key = parseInt(keyid, 10);
            const value = key
            if (isNaN(key)) {
                console.log(`Choice key "${keyid}" is not a number.`);
            }
            if (typeof value === "string" &&
                !aliasRegistry.has(value) &&
                !(value in PRIMITIVE_SIZES)) {
                throw new Error(`Choice type "${value}" is unkown.`);
            }
        })

keyString returns entire object, not just the index ID.

for (const keyString in options.choices) {
            const key = parseInt(keyString, 10);
            const value = options.choices[key];
            if (isNaN(key)) {
                throw new Error(`Choice key "${keyString}" is not a number.`);
            }
            if (typeof value === "string" &&
                !aliasRegistry.has(value) &&
                !(value in PRIMITIVE_SIZES)) {
                throw new Error(`Choice type "${value}" is unkown.`);
            }
keichi commented 2 years ago

Could you describe how it's broken and provide a minimal reproducible example?

keichi commented 1 year ago

Closing due to inactivity.