COMMON: Make most CRC functions const as they don't modify the object.

This commit is contained in:
Vladimir Serbinenko 2022-11-27 02:06:12 +01:00 committed by Eugene Sandulenko
parent ec9bb100e1
commit 8f6beba38f

View file

@ -49,8 +49,8 @@ public:
T processByte(byte byteVal, T remainder); T processByte(byte byteVal, T remainder);
T finalize(T remainder); T finalize(T remainder);
T crcSlow(byte const message[], int nBytes); T crcSlow(byte const message[], int nBytes) const;
T crcFast(byte const message[], int nBytes); T crcFast(byte const message[], int nBytes) const;
private: private:
T _poly; T _poly;
@ -65,10 +65,10 @@ private:
bool _inited; bool _inited;
uint32 reflect(uint32 data, byte nBits); uint32 reflect(uint32 data, byte nBits) const;
byte reflectData(byte x) { return _reflect ? (byte)reflect(x, 8) : x; } byte reflectData(byte x) const { return _reflect ? (byte)reflect(x, 8) : x; }
T reflectRemainder(T x) { return _reflect ? (T)reflect(x, _width) : x; } T reflectRemainder(T x) const { return _reflect ? (T)reflect(x, _width) : x; }
}; };
/********************************************************************* /*********************************************************************
@ -84,7 +84,7 @@ private:
* *
*********************************************************************/ *********************************************************************/
template<typename T> template<typename T>
uint32 CRC<T>::reflect(uint32 data, byte nBits) { uint32 CRC<T>::reflect(uint32 data, byte nBits) const {
uint32 reflection = 0x00000000; uint32 reflection = 0x00000000;
/* /*
@ -117,7 +117,7 @@ uint32 CRC<T>::reflect(uint32 data, byte nBits) {
* *
*********************************************************************/ *********************************************************************/
template<typename T> template<typename T>
T CRC<T>::crcSlow(byte const message[], int nBytes) { T CRC<T>::crcSlow(byte const message[], int nBytes) const {
T remainder = _init_remainder; T remainder = _init_remainder;
/* /*
@ -225,7 +225,7 @@ T CRC<T>::init() {
* *
*********************************************************************/ *********************************************************************/
template<typename T> template<typename T>
T CRC<T>::crcFast(byte const message[], int nBytes) { T CRC<T>::crcFast(byte const message[], int nBytes) const {
T remainder = _init_remainder; T remainder = _init_remainder;
if (!_inited) if (!_inited)