Skip to content
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

request: crc16 calculation in pattern editor #226

Open
dl1mx opened this issue Mar 12, 2024 · 2 comments
Open

request: crc16 calculation in pattern editor #226

dl1mx opened this issue Mar 12, 2024 · 2 comments

Comments

@dl1mx
Copy link

dl1mx commented Mar 12, 2024

I like to get the crc16 calculation available in the pattern editor. Only crc32 is available at the moment. Adding the follwing code to hash.pat is not working:
fn crc16(ref auto pattern, u16 init, u16 poly, u16 xorout, bool reflect_in, bool reflect_out) {
return builtin::std::hash::crc16(pattern, init, poly, xorout, reflect_in, reflect_out);
};

@dl1mx
Copy link
Author

dl1mx commented Mar 13, 2024

Seems that the code in project Pattern Language needs to be edited also with something like that in hash.cpp:

        /* crc16(pattern, init, poly, xorout, reflect_in, reflect_out) */
        runtime.addFunction(nsStdHash, "crc16", FunctionParameterCount::exactly(6), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
            wolv::util::unused(ctx);

            auto pattern = params[0].toPattern();
            auto init    = params[1].toUnsigned();
            auto poly    = params[2].toUnsigned();
            auto xorout  = params[3].toUnsigned();
            auto reflectIn  = params[4].toUnsigned();
            auto reflectOut = params[5].toUnsigned();

            wolv::hash::Crc<16> crc(poly, init, xorout, reflectIn, reflectOut);
            crc.process(pattern->getBytes());

            return u128(crc.getResult());
        });

@WerWolv
Copy link
Owner

WerWolv commented Mar 13, 2024

Thank you. Yeah currently there's only CRC32 available in the standard library. I can add the other ones later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants