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 = 0xFFFFFFFFFFFFFFFFULL
 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 301 of file crc.hpp.

Constructor & Destructor Documentation

◆ CRC64()

LibXR::CRC64::CRC64 ( )
inline

Definition at line 311 of file crc.hpp.

311{}

Member Function Documentation

◆ Calculate()

static 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 344 of file crc.hpp.

345 {
346 const uint8_t* buf = reinterpret_cast<const uint8_t*>(raw);
347 if (!inited_)
348 {
350 }
351
352 uint64_t crc = INIT;
353 while (len--)
354 {
355 crc = tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8U);
356 }
357 return crc;
358 }
static const uint64_t INIT
CRC64 初始值 / CRC64 initial value.
Definition crc.hpp:304
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
Definition crc.hpp:308
static void GenerateTable()
生成 CRC64 查找表 / Generates the CRC64 lookup table
Definition crc.hpp:316
static uint64_t tab_[256]
CRC64 查找表 / CRC64 lookup table.
Definition crc.hpp:307

◆ GenerateTable()

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

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

Definition at line 316 of file crc.hpp.

317 {
318 uint64_t crc = 0;
319 for (int i = 0; i < 256; ++i)
320 {
321 crc = static_cast<uint64_t>(i);
322 for (int j = 0; j < 8; ++j)
323 {
324 if (crc & 1ULL)
325 {
326 crc = (crc >> 1U) ^ 0xC96C5795D7870F42ULL;
327 }
328 else
329 {
330 crc >>= 1U;
331 }
332 }
333 tab_[i] = crc;
334 }
335 inited_ = true;
336 }

Field Documentation

◆ INIT

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

CRC64 初始值 / CRC64 initial value.

Definition at line 304 of file crc.hpp.

◆ inited_

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

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

Definition at line 308 of file crc.hpp.

◆ tab_

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

CRC64 查找表 / CRC64 lookup table.

Definition at line 307 of file crc.hpp.


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