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

taosdata / TDengine / #3781

31 Mar 2025 08:30AM UTC coverage: 2.494% (-9.5%) from 11.99%
#3781

push

travis-ci

happyguoxy
test:add case 2

1434 of 89904 branches covered (1.6%)

Branch coverage included in aggregate %.

2176 of 54847 relevant lines covered (3.97%)

1.58 hits per line

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

0.0
/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) {
×
39
  if (data == NULL) size = 0;
×
40
  pEncoder->data = data;
×
41
  pEncoder->size = size;
×
42
  pEncoder->pos = 0;
×
43
  pEncoder->mList = NULL;
×
44
  pEncoder->eStack = NULL;
×
45
}
×
46

47
void tEncoderClear(SEncoder* pCoder) {
×
48
  for (SCoderMem* pMem = pCoder->mList; pMem; pMem = pCoder->mList) {
×
49
    pCoder->mList = pMem->next;
×
50
    taosMemoryFree(pMem);
×
51
  }
52
  memset(pCoder, 0, sizeof(*pCoder));
×
53
}
×
54

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

63
void tDecoderClear(SDecoder* pCoder) {
×
64
  for (SCoderMem* pMem = pCoder->mList; pMem; pMem = pCoder->mList) {
×
65
    pCoder->mList = pMem->next;
×
66
    taosMemoryFree(pMem);
×
67
  }
68
  memset(pCoder, 0, sizeof(*pCoder));
×
69
}
×
70

71
int32_t tStartEncode(SEncoder* pCoder) {
×
72
  SEncoderNode* pNode;
73

74
  if (pCoder->data) {
×
75
    if (pCoder->size - pCoder->pos < sizeof(int32_t)) {
×
76
      TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
×
77
    }
78

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

84
    pNode->data = pCoder->data;
×
85
    pNode->pos = pCoder->pos;
×
86
    pNode->size = pCoder->size;
×
87

88
    pCoder->data = pNode->data + pNode->pos + sizeof(int32_t);
×
89
    pCoder->pos = 0;
×
90
    pCoder->size = pNode->size - pNode->pos - sizeof(int32_t);
×
91

92
    pNode->pNext = pCoder->eStack;
×
93
    pCoder->eStack = pNode;
×
94
  } else {
95
    pCoder->pos += sizeof(int32_t);
×
96
  }
97

98
  return 0;
×
99
}
100

101
void tEndEncode(SEncoder* pCoder) {
×
102
  SEncoderNode* pNode;
103
  int32_t       len;
104

105
  if (pCoder->data) {
×
106
    pNode = pCoder->eStack;
×
107
    pCoder->eStack = pNode->pNext;
×
108

109
    len = pCoder->pos;
×
110

111
    pCoder->data = pNode->data;
×
112
    pCoder->size = pNode->size;
×
113
    pCoder->pos = pNode->pos;
×
114

115
    int32_t ret = tEncodeI32(pCoder, len);
×
116

117
    pCoder->pos += len;
×
118
  }
119
}
×
120

121
int32_t tStartDecode(SDecoder* pCoder) {
×
122
  SDecoderNode* pNode;
123
  int32_t       len;
124

125
  TAOS_CHECK_RETURN(tDecodeI32(pCoder, &len));
×
126

127
  pNode = tDecoderMalloc(pCoder, sizeof(*pNode));
×
128
  if (pNode == NULL) {
×
129
    TAOS_RETURN(terrno);
×
130
  }
131

132
  pNode->data = pCoder->data;
×
133
  pNode->pos = pCoder->pos;
×
134
  pNode->size = pCoder->size;
×
135

136
  pCoder->data = pNode->data + pNode->pos;
×
137
  pCoder->size = len;
×
138
  pCoder->pos = 0;
×
139

140
  pNode->pNext = pCoder->dStack;
×
141
  pCoder->dStack = pNode;
×
142

143
  return 0;
×
144
}
145

146
void tEndDecode(SDecoder* pCoder) {
×
147
  SDecoderNode* pNode;
148

149
  pNode = pCoder->dStack;
×
150
  pCoder->dStack = pNode->pNext;
×
151

152
  pCoder->data = pNode->data;
×
153
  pCoder->pos = pCoder->size + pNode->pos;
×
154
  pCoder->size = pNode->size;
×
155
}
×
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