libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::CRC64 Class Reference

64 位循环冗余校验(CRC-64)计算类 / CRC-64 checksum computation class More...

#include <crc.hpp>

Static Public Member Functions

static void GenerateTable ()
 生成 CRC64 查找表 / Generates the CRC64 lookup table
 
static uint64_t Calculate (const void *raw, size_t len)
 计算数据的 CRC64 校验码 / Computes the CRC64 checksum for the given data
 

Static Public Attributes

static uint64_t tab_ [256]
 CRC64 查找表 / CRC64 lookup table.
 
static bool inited_
 查找表是否已初始化 / Whether the lookup table is initialized
 

Static Private Attributes

static const uint64_t INIT
 CRC64 初始值 / CRC64 initial value.
 

Detailed Description

64 位循环冗余校验(CRC-64)计算类 / CRC-64 checksum computation class

该类实现了 CRC-64 校验算法,支持计算数据的 64 位校验值。 This class implements the CRC-64 checksum algorithm and supports computing 64-bit checksums for input data.

Definition at line 264 of file crc.hpp.

Constructor & Destructor Documentation

◆ CRC64()

LibXR::CRC64::CRC64 ( )
inline

Definition at line 275 of file crc.hpp.

275{}

Member Function Documentation

◆ Calculate()

uint64_t LibXR::CRC64::Calculate ( const void * raw,
size_t len )
static

计算数据的 CRC64 校验码 / Computes the CRC64 checksum for the given data

Parameters
raw输入数据指针 / Pointer to input data
len数据长度 / Length of the data
Returns
计算得到的 CRC64 值 / Computed CRC64 value

Definition at line 51 of file crc_o3.cpp.

52{
53 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
54 if (!inited_)
55 {
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 const uint64_t INIT
CRC64 初始值 / CRC64 initial value.
Definition crc.hpp:267
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
Definition crc.hpp:272
static void GenerateTable()
生成 CRC64 查找表 / Generates the CRC64 lookup table
Definition crc.hpp:280
static uint64_t tab_[256]
CRC64 查找表 / CRC64 lookup table.
Definition crc.hpp:271

◆ GenerateTable()

static void LibXR::CRC64::GenerateTable ( )
inlinestatic

生成 CRC64 查找表 / Generates the CRC64 lookup table

Definition at line 280 of file crc.hpp.

281 {
282 uint64_t crc = 0;
283 for (int i = 0; i < 256; ++i)
284 {
285 crc = static_cast<uint64_t>(i);
286 for (int j = 0; j < 8; ++j)
287 {
288 if (crc & 1ULL)
289 {
290 crc = (crc >> 1U) ^ 0xC96C5795D7870F42ULL;
291 }
292 else
293 {
294 crc >>= 1U;
295 }
296 }
297 tab_[i] = crc;
298 }
299 inited_ = true;
300 }

Field Documentation

◆ INIT

const uint64_t LibXR::CRC64::INIT
staticprivate
Initial value:
=
0xFFFFFFFFFFFFFFFFULL

CRC64 初始值 / CRC64 initial value.

Definition at line 267 of file crc.hpp.

◆ inited_

bool LibXR::CRC64::inited_
inlinestatic
Initial value:
=
false

查找表是否已初始化 / Whether the lookup table is initialized

Definition at line 272 of file crc.hpp.

◆ tab_

uint64_t LibXR::CRC64::tab_[256]
inlinestatic

CRC64 查找表 / CRC64 lookup table.

Definition at line 271 of file crc.hpp.


The documentation for this class was generated from the following files: