JaiaBot
2.0.0
JaiaBot micro-AUV software
Loading...
Searching...
No Matches
crc32.h
Go to the documentation of this file.
1
2
#ifndef JAIABOT_CORE_SRC_LIB_CRC_CRC32_H
3
#define JAIABOT_CORE_SRC_LIB_CRC_CRC32_H
4
5
#include <stdint.h>
6
#include <stdlib.h>
7
8
using namespace
std;
9
10
namespace
crc
11
{
12
class
CRC32Table
13
{
14
public
:
15
uint32_t
table
[256];
16
17
CRC32Table
() {
generate_table
(); }
18
19
void
generate_table
()
20
{
21
uint32_t polynomial = 0xEDB88320;
22
for
(uint32_t i = 0; i < 256; i++)
23
{
24
uint32_t c = i;
25
for
(
size_t
j = 0; j < 8; j++)
26
{
27
if
(c & 1)
28
{
29
c = polynomial ^ (c >> 1);
30
}
31
else
32
{
33
c >>= 1;
34
}
35
}
36
table
[i] = c;
37
}
38
}
39
};
40
41
const
CRC32Table
crc32_table
;
42
43
uint32_t
calculate_crc32
(
const
void
* buf,
size_t
len, uint32_t initial = 0)
44
{
45
const
uint32_t* table =
crc32_table
.
table
;
46
47
uint32_t c = initial ^ 0xFFFFFFFF;
48
const
uint8_t* u =
static_cast<
const
uint8_t*
>
(buf);
49
for
(
size_t
i = 0; i < len; ++i) { c = table[(c ^ u[i]) & 0xFF] ^ (c >> 8); }
50
return
c ^ 0xFFFFFFFF;
51
}
52
};
// namespace crc
53
54
#endif
crc::CRC32Table
Definition
crc32.h:13
crc::CRC32Table::CRC32Table
CRC32Table()
Definition
crc32.h:17
crc::CRC32Table::generate_table
void generate_table()
Definition
crc32.h:19
crc::CRC32Table::table
uint32_t table[256]
Definition
crc32.h:15
crc
Definition
crc32.h:11
crc::calculate_crc32
uint32_t calculate_crc32(const void *buf, size_t len, uint32_t initial=0)
Definition
crc32.h:43
crc::crc32_table
const CRC32Table crc32_table
Definition
crc32.h:41
jaiabot
crc
crc32.h
Generated by
1.9.8