libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
crc_o3.cpp
1#include "crc.hpp"
2
3uint8_t LibXR::CRC8::Calculate(const void* raw, size_t len)
4{
5 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
6 if (!inited_)
7 {
9 }
10
11 uint8_t crc = INIT;
12 while (len-- > 0)
13 {
14 crc = tab_[(crc ^ *buf++) & 0xff];
15 }
16 return crc;
17}
18
19uint16_t LibXR::CRC16::Calculate(const void* raw, size_t len)
20{
21 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
22 if (!inited_)
23 {
24 GenerateTable();
25 }
26
27 uint16_t crc = INIT;
28 while (len--)
29 {
30 crc = tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8);
31 }
32 return crc;
33}
34
35uint32_t LibXR::CRC32::Calculate(const void* raw, size_t len)
36{
37 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
38 if (!inited_)
39 {
40 GenerateTable();
41 }
42
43 uint32_t crc = INIT;
44 while (len--)
45 {
46 crc = tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8);
47 }
48 return crc;
49}
50
51uint64_t LibXR::CRC64::Calculate(const void* raw, size_t len)
52{
53 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
54 if (!inited_)
55 {
56 GenerateTable();
57 }
58
59 uint64_t crc = INIT;
60 while (len--)
61 {
62 crc = tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8U);
63 }
64 return crc;
65}
static uint16_t Calculate(const void *raw, size_t len)
计算数据的 CRC16 校验码 / Computes the CRC16 checksum for the given data
Definition crc_o3.cpp:19
static uint32_t Calculate(const void *raw, size_t len)
计算数据的 CRC32 校验码 / Computes the CRC32 checksum for the given data
Definition crc_o3.cpp:35
static uint64_t Calculate(const void *raw, size_t len)
计算数据的 CRC64 校验码 / Computes the CRC64 checksum for the given data
Definition crc_o3.cpp:51
static const uint8_t INIT
CRC8 初始值 / CRC8 initial value.
Definition crc.hpp:22
static void GenerateTable()
生成 CRC8 查找表 / Generates the CRC8 lookup table
Definition crc.hpp:34
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
Definition crc.hpp:26
static uint8_t Calculate(const void *raw, size_t len)
计算数据的 CRC8 校验码 / Computes the CRC8 checksum for the given data
Definition crc_o3.cpp:3
static uint8_t tab_[256]
CRC8 查找表 / CRC8 lookup table.
Definition crc.hpp:25