Coverage Report

Created: 2026-06-09 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tdengine/include/util/tchecksum.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15
16
#ifndef _TD_UTIL_CHECKSUM_H_
17
#define _TD_UTIL_CHECKSUM_H_
18
19
#include "tcrc32c.h"
20
21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24
25
typedef uint32_t TSCKSUM;
26
27
0
static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) {
28
0
  return (*crc32c)(csi, stream, (size_t)ssize);
29
0
}
30
31
0
static FORCE_INLINE int32_t taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
32
0
  if (ssize < sizeof(TSCKSUM)) return TSDB_CODE_INVALID_PARA;
33
0
34
0
  *((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM)));
35
0
36
0
  return 0;
37
0
}
38
39
0
static FORCE_INLINE int32_t taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
40
0
  return (checksum != (*crc32c)(0, stream, (size_t)ssize));
41
0
}
42
43
0
static FORCE_INLINE int32_t taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
44
0
  if (ssize < sizeof(TSCKSUM)) return 0;
45
0
46
0
#if (_WIN64)
47
0
  return 1;
48
0
#else
49
0
  return *((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) == (*crc32c)(0, stream, (size_t)(ssize - sizeof(TSCKSUM)));
50
0
#endif
51
0
}
52
53
#ifdef __cplusplus
54
}
55
#endif
56
57
#endif /*_TD_UTIL_CHECKSUM_H_*/