-
Notifications
You must be signed in to change notification settings - Fork 7
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
Question: Easiest Path to using fastcrc with crc-rs CUSTOM_ALG functionality #2
Comments
Thanks for creating the issue. Currently, since crc-rs requires algorithms to be provided at compile time (see mrhooray/crc-rs#68), I think fastcrc cannot support dynamic algorithms for the time being. There may be other solutions, but since I'm so short on time right now, it may take a while to explore if there are other solutions. Also I would like to ask what kind of algorithm do you need now, and if it's a fixed algorithm, I'll be happy to add it and release a new version. |
@overcat Thank you for taking the time to respond!
Thanks for confirming what I suspected. As far as I understand the calculation tables get initialized a compiletime which makes the calculation as fast as it is, while having minimal codesize(~700kiBiByte) atm, because no python wrapping is needed for this data.
Yes they are fixed, with an exotic init, but this is already perfectly abstracted by fastcrc. For Naming I would use what the Wikipedia Article on CRC puts forward for these polynomials, so that someone elese might find them, while I don't know if they are specified in any norming documents with other names. const CRC_16_IBM_REFIN: Algorithm<u16> = Algorithm {
width: 16,
poly: 0x8005,
init: 0xf0f0,
refin: true,
refout: false,
xorout: 0x0000
}; const CRC_32K_REVERSED_RECIPROCAL_REFIN: Algorithm<u32> = Algorithm {
width: 32,
poly: 0xba0dc66b,
init: 0xf0f0f0f0,
refin: true,
refout: false,
xorout: 0x0000
}; I would propose that, if someone experienced with Rust would need a similar functionality, that an interface for runtime generating additional calculation tables gets added, which can then be passed into the library as an argument to a unqiue calculation function like the following: fastcrc.crc16.custom_crc_algorithm(data, configuration_with_calculation_table)
fastcrc.crc32.custom_crc_algorithm(data, configuration_with_calculation_table)
fastcrc.crc64.custom_crc_algorithm(data, configuration_with_calculation_table) This would give the flexibility of adding custom definitions, sacrificing a little on performance, while not increasing memory footprint for everyone with loads of unneeded algos. Thank you very much for your efforts and the great library you are providing! |
I've released a new version that adds the above two functions, you can install it with the following command, you'd better lock the version in the dependencies file.
Example: from fastcrc import crc16, crc32
data = b"123456789"
print(f"crc16: {crc16.ibm_refin(data)}")
print(f"crc16: {crc16.ibm_refin(b'6789', crc16.ibm_refin(b'12345'))}")
print(f"crc32: {crc32.reversed_reciprocal_refin(data)}") I'll keep this PR open until I have time to find a better way. |
Thank you very much for all your effort! Is there any way I could contribute monetarily to this project (Do you have a kind of "Buy me a coffee" Link)? I will use this code on two plattforms, one of which worked fine already with the stable versions wheel. |
Hi @gaiuscosades, I am not going to accept any donations. It's a tiny project, one of the reasons I built it was to try out PyO3, I'm happy to have users using it and giving feedback, thank you again for your kind words. Currently I'm using maturin-action to build wheels for multiple platforms, but I'm having some trouble now that it doesn't recognize the Python installed via actions/setup-python@v1 on Linux platforms, I'll see if I can build wheels for as many platforms as possible tomorrow. You can view existing wheels here https://pypi.org/project/fastcrc/0.2.1.dev5/#files |
Let me know if it changes, as I suspect that this project could get some traction in the future ;D
I suspected something like this while monitoring pypi. Will be great when most platforms get supported all out of the box. Calculating crc's without overhead is especially an issue on all the arm based embedded platforms out there. I already tested 0.2.1.dev4-cp310-none-win_amd64 without any noticable issues! |
slight correction: Koopman/Wikipedia calls this polynomial: CRC_32K_REVERSED_RECIPROCAL
|
Fixed In addition, I added the build for the update 0.2.1.dev6 released. |
I have now been able to integrate everything into my codebase and it runs perfectly with lightning speed! Only one legacy embedded platform I am running does not find compatible wheels.
|
Can you try upgrading pip(>= 20.3 required) to the latest version first and try again? |
After some troubles I was able to update pip on this platform also, which enabled me to use the wheels you already built! I am able to run everything on my windows test environment, also in combination with my complete codebase.
Do you have any idea why line fastcrc/crc16.py:6 is valid code on one platform and not on the other? |
I'm at work, and when I get off work, I'll try to create an ARM virtual machine for testing. |
Wow thx. ;D |
Hi @gaiuscosades, I think it may be due to not reading the import sysconfig
sysconfig.get_config_var("EXT_SUFFIX") Also which wheel from the list are you currently using? fastcrc-0.2.1.dev6-cp38-cp38-manylinux_2_24_armv7l.whl? |
Yes fastcrc-0.2.1.dev6-cp38-cp38-manylinux_2_24_armv7l.whl gets selected and installed. |
What is included in |
Can you help me test if this wheel works on your platform?
|
Perfect, works with the provided artifact!
|
Thanks for your feedback! I'm going to release v0.2.1-dev.7 now, and if everything works fine, I'll release v0.2.1 today. |
slight bug: The initial value for the two algorithms that I provided should be 0x00000000 |
Thank you, I will test the release once it's up on pypi! |
fixed in v0.2.1-dev.8 |
I tested v0.2.1-dev.8 using both of my setups. Everything I can tell seems fine and working reliably, as of now. Thank you very much! |
v0.2.1 published. |
Thank you for providing this great library!
I think I will be not alone wondering, what the easiest ways of using this library with a custom CRC algorithm definition would be.
Is it true that inserting all the necessary definitions directly into crc-rs and rebuilding crc-rs from scratch while extending this library by the newly defined algorithms is the only way?
Sorry for the beginner question, but I have never used anything relying on Rust before.
Thank you very much.
The text was updated successfully, but these errors were encountered: