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 LIBXR_FORCE_OPTIMIZE_O3 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 308 of file crc.hpp.

Constructor & Destructor Documentation

◆ CRC64()

LibXR::CRC64::CRC64 ( )
inline

Definition at line 319 of file crc.hpp.

319{}

Member Function Documentation

◆ Calculate()

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

计算数据的 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 352 of file crc.hpp.

353 {
354 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
355 if (!inited_)
356 {
358 }
359
360 uint64_t crc = INIT;
361 while (len--)
362 {
363 crc = tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8U);
364 }
365 return crc;
366 }
static const uint64_t INIT
CRC64 初始值 / CRC64 initial value.
Definition crc.hpp:311
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
Definition crc.hpp:316
static void GenerateTable()
生成 CRC64 查找表 / Generates the CRC64 lookup table
Definition crc.hpp:324
static uint64_t tab_[256]
CRC64 查找表 / CRC64 lookup table.
Definition crc.hpp:315

◆ GenerateTable()

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

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

Definition at line 324 of file crc.hpp.

325 {
326 uint64_t crc = 0;
327 for (int i = 0; i < 256; ++i)
328 {
329 crc = static_cast<uint64_t>(i);
330 for (int j = 0; j < 8; ++j)
331 {
332 if (crc & 1ULL)
333 {
334 crc = (crc >> 1U) ^ 0xC96C5795D7870F42ULL;
335 }
336 else
337 {
338 crc >>= 1U;
339 }
340 }
341 tab_[i] = crc;
342 }
343 inited_ = true;
344 }

Field Documentation

◆ INIT

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

CRC64 初始值 / CRC64 initial value.

Definition at line 311 of file crc.hpp.

◆ inited_

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

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

Definition at line 316 of file crc.hpp.

◆ tab_

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

CRC64 查找表 / CRC64 lookup table.

Definition at line 315 of file crc.hpp.


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