• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3534

21 Nov 2024 07:36AM UTC coverage: 60.825% (+2.0%) from 58.848%
#3534

push

travis-ci

web-flow
Merge pull request #28810 from taosdata/ehn/add-sync-heartbeat-sent-time-to-log

ehn:add-sync-heartbeat-sent-time-to-log

120023 of 252376 branches covered (47.56%)

Branch coverage included in aggregate %.

43 of 47 new or added lines in 3 files covered. (91.49%)

2254 existing lines in 162 files now uncovered.

200876 of 275203 relevant lines covered (72.99%)

16110754.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.71
/source/util/src/tencode.c
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
#define _DEFAULT_SOURCE
17
#include "tencode.h"
18

19
#if __STDC_VERSION__ >= 201112LL
20
static_assert(sizeof(float) == sizeof(uint32_t), "sizeof(float) must equal to sizeof(uint32_t)");
21
static_assert(sizeof(double) == sizeof(uint64_t), "sizeof(double) must equal to sizeof(uint64_t)");
22
#endif
23

24
struct SEncoderNode {
25
  SEncoderNode* pNext;
26
  uint8_t*      data;
27
  uint32_t      size;
28
  uint32_t      pos;
29
};
30

31
struct SDecoderNode {
32
  SDecoderNode* pNext;
33
  uint8_t*      data;
34
  uint32_t      size;
35
  uint32_t      pos;
36
};
37

38
void tEncoderInit(SEncoder* pEncoder, uint8_t* data, uint32_t size) {
141,100,855✔
39
  if (data == NULL) size = 0;
141,100,855✔
40
  pEncoder->data = data;
141,100,855✔
41
  pEncoder->size = size;
141,100,855✔
42
  pEncoder->pos = 0;
141,100,855✔
43
  pEncoder->mList = NULL;
141,100,855✔
44
  pEncoder->eStack = NULL;
141,100,855✔
45
}
141,100,855✔
46

47
void tEncoderClear(SEncoder* pCoder) {
141,204,027✔
48
  for (SCoderMem* pMem = pCoder->mList; pMem; pMem = pCoder->mList) {
221,829,634✔
49
    pCoder->mList = pMem->next;
80,595,131✔
50
    taosMemoryFree(pMem);
80,595,131✔
51
  }
52
  memset(pCoder, 0, sizeof(*pCoder));
141,234,503✔
53
}
141,234,503✔
54

55
void tDecoderInit(SDecoder* pDecoder, uint8_t* data, uint32_t size) {
114,328,070✔
56
  pDecoder->data = data;
114,328,070✔
57
  pDecoder->size = size;
114,328,070✔
58
  pDecoder->pos = 0;
114,328,070✔
59
  pDecoder->mList = NULL;
114,328,070✔
60
  pDecoder->dStack = NULL;
114,328,070✔
61
}
114,328,070✔
62

63
void tDecoderClear(SDecoder* pCoder) {
116,565,947✔
64
  for (SCoderMem* pMem = pCoder->mList; pMem; pMem = pCoder->mList) {
298,931,489✔
65
    pCoder->mList = pMem->next;
182,297,735✔
66
    taosMemoryFree(pMem);
182,297,735✔
67
  }
68
  memset(pCoder, 0, sizeof(*pCoder));
116,633,754✔
69
}
116,633,754✔
70

71
int32_t tStartEncode(SEncoder* pCoder) {
160,776,007✔
72
  SEncoderNode* pNode;
73

74
  if (pCoder->data) {
160,776,007✔
75
    if (pCoder->size - pCoder->pos < sizeof(int32_t)) {
80,523,474!
76
      TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
×
77
    }
78

79
    pNode = tEncoderMalloc(pCoder, sizeof(*pNode));
80,629,634✔
80
    if (pNode == NULL) {
80,629,634!
UNCOV
81
      TAOS_RETURN(terrno);
×
82
    }
83

84
    pNode->data = pCoder->data;
80,629,634✔
85
    pNode->pos = pCoder->pos;
80,629,634✔
86
    pNode->size = pCoder->size;
80,629,634✔
87

88
    pCoder->data = pNode->data + pNode->pos + sizeof(int32_t);
80,629,634✔
89
    pCoder->pos = 0;
80,629,634✔
90
    pCoder->size = pNode->size - pNode->pos - sizeof(int32_t);
80,629,634✔
91

92
    pNode->pNext = pCoder->eStack;
80,629,634✔
93
    pCoder->eStack = pNode;
80,629,634✔
94
  } else {
95
    pCoder->pos += sizeof(int32_t);
80,252,533✔
96
  }
97

98
  return 0;
160,882,167✔
99
}
100

101
void tEndEncode(SEncoder* pCoder) {
160,936,856✔
102
  SEncoderNode* pNode;
103
  int32_t       len;
104

105
  if (pCoder->data) {
160,936,856✔
106
    pNode = pCoder->eStack;
80,581,786✔
107
    pCoder->eStack = pNode->pNext;
80,581,786✔
108

109
    len = pCoder->pos;
80,581,786✔
110

111
    pCoder->data = pNode->data;
80,581,786✔
112
    pCoder->size = pNode->size;
80,581,786✔
113
    pCoder->pos = pNode->pos;
80,581,786!
114

115
    int32_t ret = tEncodeI32(pCoder, len);
80,581,786✔
116

117
    pCoder->pos += len;
80,581,786✔
118
  }
119
}
160,936,856✔
120

121
int32_t tStartDecode(SDecoder* pCoder) {
140,115,599✔
122
  SDecoderNode* pNode;
123
  int32_t       len;
124

125
  TAOS_CHECK_RETURN(tDecodeI32(pCoder, &len));
140,138,547✔
126

127
  pNode = tDecoderMalloc(pCoder, sizeof(*pNode));
140,253,386✔
128
  if (pNode == NULL) {
140,253,386!
UNCOV
129
    TAOS_RETURN(terrno);
×
130
  }
131

132
  pNode->data = pCoder->data;
140,253,386✔
133
  pNode->pos = pCoder->pos;
140,253,386✔
134
  pNode->size = pCoder->size;
140,253,386✔
135

136
  pCoder->data = pNode->data + pNode->pos;
140,253,386✔
137
  pCoder->size = len;
140,253,386✔
138
  pCoder->pos = 0;
140,253,386✔
139

140
  pNode->pNext = pCoder->dStack;
140,253,386✔
141
  pCoder->dStack = pNode;
140,253,386✔
142

143
  return 0;
140,253,386✔
144
}
145

146
void tEndDecode(SDecoder* pCoder) {
140,129,580✔
147
  SDecoderNode* pNode;
148

149
  pNode = pCoder->dStack;
140,129,580✔
150
  pCoder->dStack = pNode->pNext;
140,129,580✔
151

152
  pCoder->data = pNode->data;
140,129,580✔
153
  pCoder->pos = pCoder->size + pNode->pos;
140,129,580✔
154
  pCoder->size = pNode->size;
140,129,580✔
155
}
140,129,580✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc