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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 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

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

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

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

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

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

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

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

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

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

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

UNCOV
98
  return 0;
×
99
}
100

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

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

UNCOV
109
    len = pCoder->pos;
×
110

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

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

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

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

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

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

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

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

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

UNCOV
143
  return 0;
×
144
}
145

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

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

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