ashleyroll / crc_cpp Goto Github PK
View Code? Open in Web Editor NEWA Header only, constexpr / compile time small table based CRC library.
License: MIT License
A Header only, constexpr / compile time small table based CRC library.
License: MIT License
Modify the traits to support different bit sizes to allow users to trade space for speed.
First of all, I went to your talk (virtually) at cppcon and I really enjoyed it and this library is really great. I have many legacy IOT message formats that use really "unique" polynomials and starting values, so often it is a real pain to use other libraries. Yours was very easy to specialize for our CRCs.
The issue I am running into is that I can't use the crc
class in a constant expression. This seems to be a simple oversight, since to fix it I just mark all the functions in that class constexpr
. I can also see how it was missed because all my code worked until this morning! I have no idea what changed, I just renamed some files, but now it won't compile unless I make those functions contexpr.
Here is a minimal example godbolt:
#include <https://raw.githubusercontent.com/AshleyRoll/crc_cpp/main/include/crc_cpp.h>
#include <span>
constexpr bool check_message(std::span<const uint8_t> data, const uint8_t expected) {
// CRC for upper half is header + first 4 sats and is in byte 14
crc_cpp::crc8 crc;
for(const auto b : data) {
crc.update(b);
}
return expected == crc.final();
}
compiler output:
<source>: In function 'constexpr bool check_message(std::span<const unsigned char>, uint8_t)':
<source>:10:33: error: call to non-'constexpr' function 'crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::final() [with TAlgorithm = crc_cpp::impl::crc_algorithm<unsigned char, 7, 0, 0, false>; crc_cpp::table_size TABLE_SIZE = crc_cpp::table_size::small; crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type = unsigned char]'
https://raw.githubusercontent.com/AshleyRoll/crc_cpp/main/include/crc_cpp.h:410:44: note: 'crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::final() [with TAlgorithm = crc_cpp::impl::crc_algorithm<unsigned char, 7, 0, 0, false>; crc_cpp::table_size TABLE_SIZE = crc_cpp::table_size::small; crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type = unsigned char]' declared here
Compiler returned: 1
Add include guards into the header file.
Create a new release and update the Conan package with a new release after the CMake changes from PR #18
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.