tmsg.c 186.1 KB
Newer Older
D
dapan1121 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
common  
Shengliang Guan 已提交
16
#define _DEFAULT_SOURCE
H
Hongze Cheng 已提交
17
#include "tmsg.h"
D
dapan1121 已提交
18

H
Hongze Cheng 已提交
19 20 21 22 23
#undef TD_MSG_NUMBER_
#undef TD_MSG_DICT_
#define TD_MSG_INFO_
#undef TD_MSG_SEG_CODE_
#include "tmsgdef.h"
D
dapan1121 已提交
24

H
Hongze Cheng 已提交
25 26 27 28
#undef TD_MSG_NUMBER_
#undef TD_MSG_INFO_
#define TD_MSG_DICT_
#undef TD_MSG_SEG_CODE_
H
Hongze Cheng 已提交
29
#include "tmsgdef.h"
C
Cary Xu 已提交
30

L
Liu Jicong 已提交
31
int32_t tInitSubmitMsgIter(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) {
C
Cary Xu 已提交
32 33 34 35 36 37
  if (pMsg == NULL) {
    terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
    return -1;
  }

  pIter->totalLen = htonl(pMsg->length);
C
Cary Xu 已提交
38
  pIter->numOfBlocks = htonl(pMsg->numOfBlocks);
C
Cary Xu 已提交
39 40 41 42 43 44 45 46 47 48 49
  ASSERT(pIter->totalLen > 0);
  pIter->len = 0;
  pIter->pMsg = pMsg;
  if (pIter->totalLen <= sizeof(SSubmitReq)) {
    terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
    return -1;
  }

  return 0;
}

C
Cary Xu 已提交
50
int32_t tGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
C
Cary Xu 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  ASSERT(pIter->len >= 0);

  if (pIter->len == 0) {
    pIter->len += sizeof(SSubmitReq);
  } else {
    if (pIter->len >= pIter->totalLen) {
      ASSERT(0);
    }

    pIter->len += (sizeof(SSubmitBlk) + pIter->dataLen + pIter->schemaLen);
    ASSERT(pIter->len > 0);
  }

  if (pIter->len > pIter->totalLen) {
    terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
    *pPBlock = NULL;
    return -1;
  }

  if (pIter->len == pIter->totalLen) {
    *pPBlock = NULL;
  } else {
    *pPBlock = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
    pIter->uid = htobe64((*pPBlock)->uid);
    pIter->suid = htobe64((*pPBlock)->suid);
    pIter->sversion = htonl((*pPBlock)->sversion);
    pIter->dataLen = htonl((*pPBlock)->dataLen);
    pIter->schemaLen = htonl((*pPBlock)->schemaLen);
    pIter->numOfRows = htons((*pPBlock)->numOfRows);
  }
  return 0;
}

C
Cary Xu 已提交
84
int32_t tInitSubmitBlkIter(SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
C
Cary Xu 已提交
85 86 87 88 89 90 91
  if (pMsgIter->dataLen <= 0) return -1;
  pIter->totalLen = pMsgIter->dataLen;
  pIter->len = 0;
  pIter->row = (STSRow *)(pBlock->data + pMsgIter->schemaLen);
  return 0;
}

C
Cary Xu 已提交
92
STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
C
Cary Xu 已提交
93 94 95 96 97 98 99 100 101 102 103 104
  STSRow *row = pIter->row;

  if (pIter->len >= pIter->totalLen) {
    return NULL;
  } else {
    pIter->len += TD_ROW_LEN(row);
    if (pIter->len < pIter->totalLen) {
      pIter->row = POINTER_SHIFT(row, TD_ROW_LEN(row));
    }
    return row;
  }
}
C
Cary Xu 已提交
105

H
Hongze Cheng 已提交
106
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq *pReq, STSchema *pTschema) {
L
Liu Jicong 已提交
107
  SSubmitMsgIter msgIter = {0};
L
Liu Jicong 已提交
108
  if (tInitSubmitMsgIter(pReq, &msgIter) < 0) return -1;
L
Liu Jicong 已提交
109 110
  while (true) {
    SSubmitBlk *pBlock = NULL;
L
Liu Jicong 已提交
111
    if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
L
Liu Jicong 已提交
112 113
    if (pBlock == NULL) break;
    SSubmitBlkIter blkIter = {0};
L
Liu Jicong 已提交
114
    tInitSubmitBlkIter(&msgIter, pBlock, &blkIter);
L
Liu Jicong 已提交
115 116 117
    STSRowIter rowIter = {0};
    tdSTSRowIterInit(&rowIter, pTschema);
    STSRow *row;
L
Liu Jicong 已提交
118
    while ((row = tGetSubmitBlkNext(&blkIter)) != NULL) {
L
Liu Jicong 已提交
119 120 121 122 123 124
      tdSRowPrint(row, pTschema, "stream");
    }
  }
  return 0;
}

H
Hongze Cheng 已提交
125
int32_t tEncodeSEpSet(SEncoder *pEncoder, const SEpSet *pEp) {
S
Shengliang Guan 已提交
126 127 128 129
  if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
  if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; i++) {
    if (tEncodeU16(pEncoder, pEp->eps[i].port) < 0) return -1;
130
    if (tEncodeCStrWithLen(pEncoder, pEp->eps[i].fqdn, TSDB_FQDN_LEN) < 0) return -1;
S
Shengliang Guan 已提交
131 132 133 134
  }
  return 0;
}

H
Hongze Cheng 已提交
135
int32_t tDecodeSEpSet(SDecoder *pDecoder, SEpSet *pEp) {
S
Shengliang Guan 已提交
136 137 138 139 140 141 142 143 144
  if (tDecodeI8(pDecoder, &pEp->inUse) < 0) return -1;
  if (tDecodeI8(pDecoder, &pEp->numOfEps) < 0) return -1;
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; i++) {
    if (tDecodeU16(pDecoder, &pEp->eps[i].port) < 0) return -1;
    if (tDecodeCStrTo(pDecoder, pEp->eps[i].fqdn) < 0) return -1;
  }
  return 0;
}

H
Hongze Cheng 已提交
145
int32_t tEncodeSQueryNodeAddr(SEncoder *pEncoder, SQueryNodeAddr *pAddr) {
D
dapan1121 已提交
146 147 148 149 150
  if (tEncodeI32(pEncoder, pAddr->nodeId) < 0) return -1;
  if (tEncodeSEpSet(pEncoder, &pAddr->epSet) < 0) return -1;
  return 0;
}

D
dapan1121 已提交
151 152 153 154 155 156
int32_t tEncodeSQueryNodeLoad(SEncoder *pEncoder, SQueryNodeLoad *pLoad) {
  if (tEncodeSQueryNodeAddr(pEncoder, &pLoad->addr) < 0) return -1;
  if (tEncodeU64(pEncoder, pLoad->load) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
157
int32_t tDecodeSQueryNodeAddr(SDecoder *pDecoder, SQueryNodeAddr *pAddr) {
D
dapan1121 已提交
158 159 160 161 162
  if (tDecodeI32(pDecoder, &pAddr->nodeId) < 0) return -1;
  if (tDecodeSEpSet(pDecoder, &pAddr->epSet) < 0) return -1;
  return 0;
}

D
dapan1121 已提交
163 164 165 166 167 168
int32_t tDecodeSQueryNodeLoad(SDecoder *pDecoder, SQueryNodeLoad *pLoad) {
  if (tDecodeSQueryNodeAddr(pDecoder, &pLoad->addr) < 0) return -1;
  if (tDecodeU64(pDecoder, &pLoad->load) < 0) return -1;
  return 0;
}

S
Shengliang Guan 已提交
169 170 171 172 173 174 175 176 177 178 179
int32_t taosEncodeSEpSet(void **buf, const SEpSet *pEp) {
  int32_t tlen = 0;
  tlen += taosEncodeFixedI8(buf, pEp->inUse);
  tlen += taosEncodeFixedI8(buf, pEp->numOfEps);
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; i++) {
    tlen += taosEncodeFixedU16(buf, pEp->eps[i].port);
    tlen += taosEncodeString(buf, pEp->eps[i].fqdn);
  }
  return tlen;
}

180
void *taosDecodeSEpSet(const void *buf, SEpSet *pEp) {
S
Shengliang Guan 已提交
181 182 183 184 185 186
  buf = taosDecodeFixedI8(buf, &pEp->inUse);
  buf = taosDecodeFixedI8(buf, &pEp->numOfEps);
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; i++) {
    buf = taosDecodeFixedU16(buf, &pEp->eps[i].port);
    buf = taosDecodeStringTo(buf, pEp->eps[i].fqdn);
  }
187
  return (void *)buf;
S
Shengliang Guan 已提交
188 189
}

H
Hongze Cheng 已提交
190
static int32_t tSerializeSClientHbReq(SEncoder *pEncoder, const SClientHbReq *pReq) {
S
Shengliang Guan 已提交
191
  if (tEncodeSClientHbKey(pEncoder, &pReq->connKey) < 0) return -1;
L
Liu Jicong 已提交
192

D
dapan1121 已提交
193
  if (pReq->connKey.connType == CONN_TYPE__QUERY) {
D
dapan1121 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206
    if (tEncodeI64(pEncoder, pReq->app.appId) < 0) return -1;
    if (tEncodeI32(pEncoder, pReq->app.pid) < 0) return -1;
    if (tEncodeCStr(pEncoder, pReq->app.name) < 0) return -1;
    if (tEncodeI64(pEncoder, pReq->app.startTime) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.numOfInsertsReq) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.numOfInsertRows) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.insertElapsedTime) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.insertBytes) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.fetchBytes) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.queryElapsedTime) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.numOfSlowQueries) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.totalRequests) < 0) return -1;
    if (tEncodeU64(pEncoder, pReq->app.summary.currentRequests) < 0) return -1;
X
Xiaoyu Wang 已提交
207

D
dapan1121 已提交
208 209 210 211 212
    int32_t queryNum = 0;
    if (pReq->query) {
      queryNum = 1;
      if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
      if (tEncodeU32(pEncoder, pReq->query->connId) < 0) return -1;
213

D
dapan1121 已提交
214 215
      int32_t num = taosArrayGetSize(pReq->query->queryDesc);
      if (tEncodeI32(pEncoder, num) < 0) return -1;
216

D
dapan1121 已提交
217 218 219 220 221 222 223
      for (int32_t i = 0; i < num; ++i) {
        SQueryDesc *desc = taosArrayGet(pReq->query->queryDesc, i);
        if (tEncodeCStr(pEncoder, desc->sql) < 0) return -1;
        if (tEncodeU64(pEncoder, desc->queryId) < 0) return -1;
        if (tEncodeI64(pEncoder, desc->useconds) < 0) return -1;
        if (tEncodeI64(pEncoder, desc->stime) < 0) return -1;
        if (tEncodeI64(pEncoder, desc->reqRid) < 0) return -1;
224
        if (tEncodeI8(pEncoder, desc->stableQuery) < 0) return -1;
D
dapan1121 已提交
225 226 227 228 229 230 231 232
        if (tEncodeCStr(pEncoder, desc->fqdn) < 0) return -1;
        if (tEncodeI32(pEncoder, desc->subPlanNum) < 0) return -1;

        int32_t snum = desc->subDesc ? taosArrayGetSize(desc->subDesc) : 0;
        if (tEncodeI32(pEncoder, snum) < 0) return -1;
        for (int32_t m = 0; m < snum; ++m) {
          SQuerySubDesc *sDesc = taosArrayGet(desc->subDesc, m);
          if (tEncodeI64(pEncoder, sDesc->tid) < 0) return -1;
233
          if (tEncodeCStr(pEncoder, sDesc->status) < 0) return -1;
D
dapan1121 已提交
234 235 236 237 238 239
        }
      }
    } else {
      if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
    }
  }
240

L
Liu Jicong 已提交
241
  int32_t kvNum = taosHashGetSize(pReq->info);
S
Shengliang Guan 已提交
242
  if (tEncodeI32(pEncoder, kvNum) < 0) return -1;
S
Shengliang Guan 已提交
243
  void *pIter = taosHashIterate(pReq->info, NULL);
L
Liu Jicong 已提交
244
  while (pIter != NULL) {
S
Shengliang Guan 已提交
245 246
    SKv *kv = pIter;
    if (tEncodeSKv(pEncoder, kv) < 0) return -1;
L
Liu Jicong 已提交
247
    pIter = taosHashIterate(pReq->info, pIter);
L
Liu Jicong 已提交
248
  }
S
Shengliang Guan 已提交
249 250

  return 0;
L
Liu Jicong 已提交
251 252
}

H
Hongze Cheng 已提交
253
static int32_t tDeserializeSClientHbReq(SDecoder *pDecoder, SClientHbReq *pReq) {
S
Shengliang Guan 已提交
254
  if (tDecodeSClientHbKey(pDecoder, &pReq->connKey) < 0) return -1;
L
Liu Jicong 已提交
255

D
dapan1121 已提交
256
  if (pReq->connKey.connType == CONN_TYPE__QUERY) {
D
dapan1121 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270
    if (tDecodeI64(pDecoder, &pReq->app.appId) < 0) return -1;
    if (tDecodeI32(pDecoder, &pReq->app.pid) < 0) return -1;
    if (tDecodeCStrTo(pDecoder, pReq->app.name) < 0) return -1;
    if (tDecodeI64(pDecoder, &pReq->app.startTime) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.numOfInsertsReq) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.numOfInsertRows) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.insertElapsedTime) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.insertBytes) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.fetchBytes) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.queryElapsedTime) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.numOfSlowQueries) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.totalRequests) < 0) return -1;
    if (tDecodeU64(pDecoder, &pReq->app.summary.currentRequests) < 0) return -1;

D
dapan1121 已提交
271 272 273 274 275 276 277 278 279 280 281 282
    int32_t queryNum = 0;
    if (tDecodeI32(pDecoder, &queryNum) < 0) return -1;
    if (queryNum) {
      pReq->query = taosMemoryCalloc(1, sizeof(*pReq->query));
      if (NULL == pReq->query) return -1;
      if (tDecodeU32(pDecoder, &pReq->query->connId) < 0) return -1;

      int32_t num = 0;
      if (tDecodeI32(pDecoder, &num) < 0) return -1;
      if (num > 0) {
        pReq->query->queryDesc = taosArrayInit(num, sizeof(SQueryDesc));
        if (NULL == pReq->query->queryDesc) return -1;
283

D
dapan1121 已提交
284 285 286 287 288 289 290
        for (int32_t i = 0; i < num; ++i) {
          SQueryDesc desc = {0};
          if (tDecodeCStrTo(pDecoder, desc.sql) < 0) return -1;
          if (tDecodeU64(pDecoder, &desc.queryId) < 0) return -1;
          if (tDecodeI64(pDecoder, &desc.useconds) < 0) return -1;
          if (tDecodeI64(pDecoder, &desc.stime) < 0) return -1;
          if (tDecodeI64(pDecoder, &desc.reqRid) < 0) return -1;
X
Xiaoyu Wang 已提交
291
          if (tDecodeI8(pDecoder, (int8_t *)&desc.stableQuery) < 0) return -1;
D
dapan1121 已提交
292 293 294 295 296 297 298 299
          if (tDecodeCStrTo(pDecoder, desc.fqdn) < 0) return -1;
          if (tDecodeI32(pDecoder, &desc.subPlanNum) < 0) return -1;

          int32_t snum = 0;
          if (tDecodeI32(pDecoder, &snum) < 0) return -1;
          if (snum > 0) {
            desc.subDesc = taosArrayInit(snum, sizeof(SQuerySubDesc));
            if (NULL == desc.subDesc) return -1;
300

D
dapan1121 已提交
301 302 303
            for (int32_t m = 0; m < snum; ++m) {
              SQuerySubDesc sDesc = {0};
              if (tDecodeI64(pDecoder, &sDesc.tid) < 0) return -1;
304
              if (tDecodeCStrTo(pDecoder, sDesc.status) < 0) return -1;
D
dapan1121 已提交
305 306 307 308 309 310 311 312 313 314
              taosArrayPush(desc.subDesc, &sDesc);
            }
          }

          taosArrayPush(pReq->query->queryDesc, &desc);
        }
      }
    }
  }

S
Shengliang Guan 已提交
315 316
  int32_t kvNum = 0;
  if (tDecodeI32(pDecoder, &kvNum) < 0) return -1;
L
Liu Jicong 已提交
317 318 319
  if (pReq->info == NULL) {
    pReq->info = taosHashInit(kvNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
  }
S
Shengliang Guan 已提交
320
  if (pReq->info == NULL) return -1;
S
Shengliang Guan 已提交
321
  for (int32_t i = 0; i < kvNum; i++) {
S
Shengliang Guan 已提交
322 323
    SKv kv = {0};
    if (tDecodeSKv(pDecoder, &kv) < 0) return -1;
D
dapan1121 已提交
324
    taosHashPut(pReq->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
L
Liu Jicong 已提交
325 326
  }

S
Shengliang Guan 已提交
327
  return 0;
L
Liu Jicong 已提交
328 329
}

H
Hongze Cheng 已提交
330
static int32_t tSerializeSClientHbRsp(SEncoder *pEncoder, const SClientHbRsp *pRsp) {
S
Shengliang Guan 已提交
331 332 333
  if (tEncodeSClientHbKey(pEncoder, &pRsp->connKey) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->status) < 0) return -1;

D
dapan1121 已提交
334 335 336
  int32_t queryNum = 0;
  if (pRsp->query) {
    queryNum = 1;
337
    if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
D
dapan1121 已提交
338 339 340 341 342 343
    if (tEncodeU32(pEncoder, pRsp->query->connId) < 0) return -1;
    if (tEncodeU64(pEncoder, pRsp->query->killRid) < 0) return -1;
    if (tEncodeI32(pEncoder, pRsp->query->totalDnodes) < 0) return -1;
    if (tEncodeI32(pEncoder, pRsp->query->onlineDnodes) < 0) return -1;
    if (tEncodeI8(pEncoder, pRsp->query->killConnection) < 0) return -1;
    if (tEncodeSEpSet(pEncoder, &pRsp->query->epSet) < 0) return -1;
D
dapan1121 已提交
344 345 346 347 348 349
    int32_t num = taosArrayGetSize(pRsp->query->pQnodeList);
    if (tEncodeI32(pEncoder, num) < 0) return -1;
    for (int32_t i = 0; i < num; ++i) {
      SQueryNodeLoad *pLoad = taosArrayGet(pRsp->query->pQnodeList, i);
      if (tEncodeSQueryNodeLoad(pEncoder, pLoad) < 0) return -1;
    }
D
dapan1121 已提交
350
  } else {
351
    if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
D
dapan1121 已提交
352
  }
353

D
dapan1121 已提交
354
  int32_t kvNum = taosArrayGetSize(pRsp->info);
S
Shengliang Guan 已提交
355
  if (tEncodeI32(pEncoder, kvNum) < 0) return -1;
S
Shengliang Guan 已提交
356
  for (int32_t i = 0; i < kvNum; i++) {
S
Shengliang Guan 已提交
357 358
    SKv *kv = taosArrayGet(pRsp->info, i);
    if (tEncodeSKv(pEncoder, kv) < 0) return -1;
D
dapan1121 已提交
359
  }
S
Shengliang Guan 已提交
360 361

  return 0;
L
Liu Jicong 已提交
362
}
S
Shengliang Guan 已提交
363

H
Hongze Cheng 已提交
364
static int32_t tDeserializeSClientHbRsp(SDecoder *pDecoder, SClientHbRsp *pRsp) {
S
Shengliang Guan 已提交
365 366 367
  if (tDecodeSClientHbKey(pDecoder, &pRsp->connKey) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->status) < 0) return -1;

D
dapan1121 已提交
368 369 370 371 372 373 374 375 376 377 378
  int32_t queryNum = 0;
  if (tDecodeI32(pDecoder, &queryNum) < 0) return -1;
  if (queryNum) {
    pRsp->query = taosMemoryCalloc(1, sizeof(*pRsp->query));
    if (NULL == pRsp->query) return -1;
    if (tDecodeU32(pDecoder, &pRsp->query->connId) < 0) return -1;
    if (tDecodeU64(pDecoder, &pRsp->query->killRid) < 0) return -1;
    if (tDecodeI32(pDecoder, &pRsp->query->totalDnodes) < 0) return -1;
    if (tDecodeI32(pDecoder, &pRsp->query->onlineDnodes) < 0) return -1;
    if (tDecodeI8(pDecoder, &pRsp->query->killConnection) < 0) return -1;
    if (tDecodeSEpSet(pDecoder, &pRsp->query->epSet) < 0) return -1;
D
dapan1121 已提交
379 380 381 382 383 384 385 386 387
    int32_t pQnodeNum = 0;
    if (tDecodeI32(pDecoder, &pQnodeNum) < 0) return -1;
    if (pQnodeNum > 0) {
      pRsp->query->pQnodeList = taosArrayInit(pQnodeNum, sizeof(SQueryNodeLoad));
      if (NULL == pRsp->query->pQnodeList) return -1;
      SQueryNodeLoad load = {0};
      if (tDecodeSQueryNodeLoad(pDecoder, &load) < 0) return -1;
      taosArrayPush(pRsp->query->pQnodeList, &load);
    }
D
dapan1121 已提交
388 389
  }

D
dapan1121 已提交
390
  int32_t kvNum = 0;
S
Shengliang Guan 已提交
391
  if (tDecodeI32(pDecoder, &kvNum) < 0) return -1;
D
dapan1121 已提交
392
  pRsp->info = taosArrayInit(kvNum, sizeof(SKv));
S
Shengliang Guan 已提交
393
  if (pRsp->info == NULL) return -1;
S
Shengliang Guan 已提交
394
  for (int32_t i = 0; i < kvNum; i++) {
D
dapan1121 已提交
395
    SKv kv = {0};
S
Shengliang Guan 已提交
396
    tDecodeSKv(pDecoder, &kv);
D
dapan1121 已提交
397 398
    taosArrayPush(pRsp->info, &kv);
  }
S
Shengliang Guan 已提交
399

S
Shengliang Guan 已提交
400
  return 0;
L
Liu Jicong 已提交
401 402
}

S
Shengliang Guan 已提交
403
int32_t tSerializeSClientHbBatchReq(void *buf, int32_t bufLen, const SClientHbBatchReq *pBatchReq) {
H
Hongze Cheng 已提交
404 405
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
406 407 408 409

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pBatchReq->reqId) < 0) return -1;

L
Liu Jicong 已提交
410
  int32_t reqNum = taosArrayGetSize(pBatchReq->reqs);
S
Shengliang Guan 已提交
411
  if (tEncodeI32(&encoder, reqNum) < 0) return -1;
S
Shengliang Guan 已提交
412 413
  for (int32_t i = 0; i < reqNum; i++) {
    SClientHbReq *pReq = taosArrayGet(pBatchReq->reqs, i);
S
Shengliang Guan 已提交
414
    if (tSerializeSClientHbReq(&encoder, pReq) < 0) return -1;
L
Liu Jicong 已提交
415
  }
S
Shengliang Guan 已提交
416 417 418
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
419
  tEncoderClear(&encoder);
L
Liu Jicong 已提交
420 421 422
  return tlen;
}

S
Shengliang Guan 已提交
423
int32_t tDeserializeSClientHbBatchReq(void *buf, int32_t bufLen, SClientHbBatchReq *pBatchReq) {
H
Hongze Cheng 已提交
424 425
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
426 427 428 429 430 431

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pBatchReq->reqId) < 0) return -1;

  int32_t reqNum = 0;
  if (tDecodeI32(&decoder, &reqNum) < 0) return -1;
D
dapan1121 已提交
432
  if (reqNum > 0) {
S
Shengliang Guan 已提交
433
    pBatchReq->reqs = taosArrayInit(reqNum, sizeof(SClientHbReq));
D
dapan1121 已提交
434
    if (NULL == pBatchReq->reqs) return -1;
L
Liu Jicong 已提交
435
  }
S
Shengliang Guan 已提交
436
  for (int32_t i = 0; i < reqNum; i++) {
L
Liu Jicong 已提交
437
    SClientHbReq req = {0};
S
Shengliang Guan 已提交
438
    tDeserializeSClientHbReq(&decoder, &req);
L
Liu Jicong 已提交
439 440
    taosArrayPush(pBatchReq->reqs, &req);
  }
S
Shengliang Guan 已提交
441 442

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
443
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
444
  return 0;
L
Liu Jicong 已提交
445 446
}

S
Shengliang Guan 已提交
447
int32_t tSerializeSClientHbBatchRsp(void *buf, int32_t bufLen, const SClientHbBatchRsp *pBatchRsp) {
H
Hongze Cheng 已提交
448 449
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
450 451 452 453 454 455 456 457

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pBatchRsp->reqId) < 0) return -1;
  if (tEncodeI64(&encoder, pBatchRsp->rspId) < 0) return -1;

  int32_t rspNum = taosArrayGetSize(pBatchRsp->rsps);
  if (tEncodeI32(&encoder, rspNum) < 0) return -1;
  for (int32_t i = 0; i < rspNum; i++) {
S
Shengliang Guan 已提交
458
    SClientHbRsp *pRsp = taosArrayGet(pBatchRsp->rsps, i);
S
Shengliang Guan 已提交
459
    if (tSerializeSClientHbRsp(&encoder, pRsp) < 0) return -1;
L
Liu Jicong 已提交
460
  }
S
Shengliang Guan 已提交
461 462 463
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
464
  tEncoderClear(&encoder);
L
Liu Jicong 已提交
465 466 467
  return tlen;
}

S
Shengliang Guan 已提交
468
int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchRsp *pBatchRsp) {
H
Hongze Cheng 已提交
469 470
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
471 472 473 474 475 476 477 478

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pBatchRsp->reqId) < 0) return -1;
  if (tDecodeI64(&decoder, &pBatchRsp->rspId) < 0) return -1;

  int32_t rspNum = 0;
  if (tDecodeI32(&decoder, &rspNum) < 0) return -1;
  if (pBatchRsp->rsps == NULL) {
L
Liu Jicong 已提交
479
    pBatchRsp->rsps = taosArrayInit(rspNum, sizeof(SClientHbRsp));
S
Shengliang Guan 已提交
480 481
  }
  for (int32_t i = 0; i < rspNum; i++) {
L
Liu Jicong 已提交
482
    SClientHbRsp rsp = {0};
S
Shengliang Guan 已提交
483
    tDeserializeSClientHbRsp(&decoder, &rsp);
L
Liu Jicong 已提交
484 485
    taosArrayPush(pBatchRsp->rsps, &rsp);
  }
S
Shengliang Guan 已提交
486 487

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
488
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
489
  return 0;
L
Liu Jicong 已提交
490 491
}

S
Shengliang Guan 已提交
492
int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq) {
H
Hongze Cheng 已提交
493 494
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
495

S
Shengliang Guan 已提交
496 497 498
  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
X
Xiaoyu Wang 已提交
499 500 501 502
  if (tEncodeI64(&encoder, pReq->delay1) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->delay2) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->watermark1) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->watermark2) < 0) return -1;
S
sma  
Shengliang Guan 已提交
503
  if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
S
Shengliang Guan 已提交
504 505
  if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->numOfTags) < 0) return -1;
S
Shengliang Guan 已提交
506
  if (tEncodeI32(&encoder, pReq->numOfFuncs) < 0) return -1;
S
sma  
Shengliang Guan 已提交
507
  if (tEncodeI32(&encoder, pReq->commentLen) < 0) return -1;
508 509
  if (tEncodeI32(&encoder, pReq->ast1Len) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->ast2Len) < 0) return -1;
S
Shengliang Guan 已提交
510 511 512

  for (int32_t i = 0; i < pReq->numOfColumns; ++i) {
    SField *pField = taosArrayGet(pReq->pColumns, i);
S
Shengliang Guan 已提交
513
    if (tEncodeI8(&encoder, pField->type) < 0) return -1;
S
Shengliang Guan 已提交
514
    if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
S
Shengliang Guan 已提交
515 516
    if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
    if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
S
Shengliang Guan 已提交
517 518 519 520
  }

  for (int32_t i = 0; i < pReq->numOfTags; ++i) {
    SField *pField = taosArrayGet(pReq->pTags, i);
S
Shengliang Guan 已提交
521
    if (tEncodeI8(&encoder, pField->type) < 0) return -1;
S
Shengliang Guan 已提交
522
    if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
S
Shengliang Guan 已提交
523 524
    if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
    if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
S
Shengliang Guan 已提交
525 526 527 528 529
  }

  for (int32_t i = 0; i < pReq->numOfFuncs; ++i) {
    const char *pFunc = taosArrayGet(pReq->pFuncs, i);
    if (tEncodeCStr(&encoder, pFunc) < 0) return -1;
S
sma  
Shengliang Guan 已提交
530 531 532
  }

  if (pReq->commentLen > 0) {
S
Shengliang Guan 已提交
533
    if (tEncodeCStr(&encoder, pReq->pComment) < 0) return -1;
S
sma  
Shengliang Guan 已提交
534
  }
535 536 537 538 539 540
  if (pReq->ast1Len > 0) {
    if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1;
  }
  if (pReq->ast2Len > 0) {
    if (tEncodeBinary(&encoder, pReq->pAst2, pReq->ast2Len) < 0) return -1;
  }
D
dapan1121 已提交
541

S
Shengliang Guan 已提交
542 543 544
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
545
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
546 547 548
  return tlen;
}

S
Shengliang Guan 已提交
549
int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq) {
H
Hongze Cheng 已提交
550 551
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
552 553 554 555

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
X
Xiaoyu Wang 已提交
556 557 558 559
  if (tDecodeI64(&decoder, &pReq->delay1) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->delay2) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->watermark1) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->watermark2) < 0) return -1;
S
sma  
Shengliang Guan 已提交
560
  if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
S
Shengliang Guan 已提交
561 562
  if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->numOfTags) < 0) return -1;
S
Shengliang Guan 已提交
563
  if (tDecodeI32(&decoder, &pReq->numOfFuncs) < 0) return -1;
S
sma  
Shengliang Guan 已提交
564
  if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1;
565 566
  if (tDecodeI32(&decoder, &pReq->ast1Len) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->ast2Len) < 0) return -1;
S
Shengliang Guan 已提交
567 568 569

  pReq->pColumns = taosArrayInit(pReq->numOfColumns, sizeof(SField));
  pReq->pTags = taosArrayInit(pReq->numOfTags, sizeof(SField));
S
Shengliang Guan 已提交
570 571
  pReq->pFuncs = taosArrayInit(pReq->numOfFuncs, TSDB_FUNC_NAME_LEN);
  if (pReq->pColumns == NULL || pReq->pTags == NULL || pReq->pFuncs == NULL) {
S
Shengliang Guan 已提交
572
    terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
573
    return -1;
S
Shengliang Guan 已提交
574 575 576 577
  }

  for (int32_t i = 0; i < pReq->numOfColumns; ++i) {
    SField field = {0};
S
Shengliang Guan 已提交
578
    if (tDecodeI8(&decoder, &field.type) < 0) return -1;
S
Shengliang Guan 已提交
579
    if (tDecodeI8(&decoder, &field.flags) < 0) return -1;
S
Shengliang Guan 已提交
580 581
    if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
    if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
S
Shengliang Guan 已提交
582 583
    if (taosArrayPush(pReq->pColumns, &field) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
584
      return -1;
S
Shengliang Guan 已提交
585 586 587 588 589
    }
  }

  for (int32_t i = 0; i < pReq->numOfTags; ++i) {
    SField field = {0};
S
Shengliang Guan 已提交
590
    if (tDecodeI8(&decoder, &field.type) < 0) return -1;
S
Shengliang Guan 已提交
591
    if (tDecodeI8(&decoder, &field.flags) < 0) return -1;
S
Shengliang Guan 已提交
592 593
    if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
    if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
S
Shengliang Guan 已提交
594 595
    if (taosArrayPush(pReq->pTags, &field) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
596
      return -1;
S
Shengliang Guan 已提交
597 598 599
    }
  }

S
Shengliang Guan 已提交
600 601 602 603 604 605 606 607 608
  for (int32_t i = 0; i < pReq->numOfFuncs; ++i) {
    char pFunc[TSDB_FUNC_NAME_LEN] = {0};
    if (tDecodeCStrTo(&decoder, pFunc) < 0) return -1;
    if (taosArrayPush(pReq->pFuncs, pFunc) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
  }

S
sma  
Shengliang Guan 已提交
609
  if (pReq->commentLen > 0) {
S
Shengliang Guan 已提交
610 611 612
    pReq->pComment = taosMemoryMalloc(pReq->commentLen + 1);
    if (pReq->pComment == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->pComment) < 0) return -1;
S
sma  
Shengliang Guan 已提交
613 614
  }

615 616 617 618 619 620 621 622 623 624 625 626
  if (pReq->ast1Len > 0) {
    pReq->pAst1 = taosMemoryMalloc(pReq->ast1Len);
    if (pReq->pAst1 == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->pAst1) < 0) return -1;
  }

  if (pReq->ast2Len > 0) {
    pReq->pAst2 = taosMemoryMalloc(pReq->ast2Len);
    if (pReq->pAst2 == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->pAst2) < 0) return -1;
  }

S
Shengliang Guan 已提交
627
  tEndDecode(&decoder);
H
Hongze Cheng 已提交
628
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
629
  return 0;
S
Shengliang Guan 已提交
630
}
S
Shengliang Guan 已提交
631

S
Shengliang Guan 已提交
632 633 634
void tFreeSMCreateStbReq(SMCreateStbReq *pReq) {
  taosArrayDestroy(pReq->pColumns);
  taosArrayDestroy(pReq->pTags);
S
Shengliang Guan 已提交
635 636
  taosArrayDestroy(pReq->pFuncs);
  taosMemoryFreeClear(pReq->pComment);
637 638
  taosMemoryFreeClear(pReq->pAst1);
  taosMemoryFreeClear(pReq->pAst2);
S
Shengliang Guan 已提交
639 640
}

S
Shengliang Guan 已提交
641
int32_t tSerializeSMDropStbReq(void *buf, int32_t bufLen, SMDropStbReq *pReq) {
H
Hongze Cheng 已提交
642 643
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
644

S
Shengliang Guan 已提交
645 646 647 648
  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
  tEndEncode(&encoder);
S
Shengliang Guan 已提交
649

S
Shengliang Guan 已提交
650
  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
651
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
652 653 654
  return tlen;
}

S
Shengliang Guan 已提交
655
int32_t tDeserializeSMDropStbReq(void *buf, int32_t bufLen, SMDropStbReq *pReq) {
H
Hongze Cheng 已提交
656 657
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
658

S
Shengliang Guan 已提交
659 660 661 662
  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
  tEndDecode(&decoder);
S
Shengliang Guan 已提交
663

H
Hongze Cheng 已提交
664
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
665 666
  return 0;
}
S
Shengliang Guan 已提交
667

S
Shengliang Guan 已提交
668
int32_t tSerializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq) {
H
Hongze Cheng 已提交
669 670
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
671

S
Shengliang Guan 已提交
672 673 674
  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->alterType) < 0) return -1;
675 676
  if (tEncodeI32(&encoder, pReq->tagVer) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->colVer) < 0) return -1;
S
Shengliang Guan 已提交
677
  if (tEncodeI32(&encoder, pReq->numOfFields) < 0) return -1;
S
Shengliang Guan 已提交
678 679
  for (int32_t i = 0; i < pReq->numOfFields; ++i) {
    SField *pField = taosArrayGet(pReq->pFields, i);
S
Shengliang Guan 已提交
680 681 682
    if (tEncodeI8(&encoder, pField->type) < 0) return -1;
    if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
    if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
S
Shengliang Guan 已提交
683
  }
X
Xiaoyu Wang 已提交
684 685 686 687 688
  if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->commentLen) < 0) return -1;
  if (pReq->commentLen > 0) {
    if (tEncodeCStr(&encoder, pReq->comment) < 0) return -1;
  }
S
Shengliang Guan 已提交
689
  tEndEncode(&encoder);
S
Shengliang Guan 已提交
690

S
Shengliang Guan 已提交
691
  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
692
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
693 694 695
  return tlen;
}

S
Shengliang Guan 已提交
696
int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq) {
H
Hongze Cheng 已提交
697 698
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
699

S
Shengliang Guan 已提交
700 701 702
  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->alterType) < 0) return -1;
703 704
  if (tDecodeI32(&decoder, &pReq->tagVer) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->colVer) < 0) return -1;
S
Shengliang Guan 已提交
705
  if (tDecodeI32(&decoder, &pReq->numOfFields) < 0) return -1;
S
Shengliang Guan 已提交
706 707 708
  pReq->pFields = taosArrayInit(pReq->numOfFields, sizeof(SField));
  if (pReq->pFields == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
709
    return -1;
S
Shengliang Guan 已提交
710 711 712 713
  }

  for (int32_t i = 0; i < pReq->numOfFields; ++i) {
    SField field = {0};
S
Shengliang Guan 已提交
714 715 716
    if (tDecodeI8(&decoder, &field.type) < 0) return -1;
    if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
    if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
S
Shengliang Guan 已提交
717 718
    if (taosArrayPush(pReq->pFields, &field) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
719
      return -1;
S
Shengliang Guan 已提交
720 721 722
    }
  }

X
Xiaoyu Wang 已提交
723 724 725
  if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1;
  if (pReq->commentLen > 0) {
wmmhello's avatar
wmmhello 已提交
726
    pReq->comment = taosMemoryMalloc(pReq->commentLen + 1);
X
Xiaoyu Wang 已提交
727 728 729 730
    if (pReq->comment == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1;
  }

S
Shengliang Guan 已提交
731
  tEndDecode(&decoder);
H
Hongze Cheng 已提交
732
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
733 734 735
  return 0;
}

S
Shengliang Guan 已提交
736
void tFreeSMAltertbReq(SMAlterStbReq *pReq) {
S
Shengliang Guan 已提交
737 738
  taosArrayDestroy(pReq->pFields);
  pReq->pFields = NULL;
739
  taosMemoryFreeClear(pReq->comment);
S
Shengliang Guan 已提交
740
}
741 742

int32_t tSerializeSEpSet(void *buf, int32_t bufLen, const SEpSet *pEpset) {
H
Hongze Cheng 已提交
743 744
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
dengyihao's avatar
dengyihao 已提交
745
  if (tStartEncode(&encoder) < 0) return -1;
746
  if (tEncodeSEpSet(&encoder, pEpset) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
747

dengyihao's avatar
dengyihao 已提交
748 749
  tEndEncode(&encoder);
  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
750
  tEncoderClear(&encoder);
dengyihao's avatar
dengyihao 已提交
751 752
  return tlen;
}
753 754

int32_t tDeserializeSEpSet(void *buf, int32_t bufLen, SEpSet *pEpset) {
H
Hongze Cheng 已提交
755 756
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
dengyihao's avatar
dengyihao 已提交
757
  if (tStartDecode(&decoder) < 0) return -1;
758
  if (tDecodeSEpSet(&decoder, pEpset) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
759 760

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
761
  tDecoderClear(&decoder);
dengyihao's avatar
dengyihao 已提交
762 763
  return 0;
}
S
Shengliang Guan 已提交
764

S
Shengliang Guan 已提交
765
int32_t tSerializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq) {
H
Hongze Cheng 已提交
766 767
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
768 769 770 771 772 773 774 775

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->stb) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->intervalUnit) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->slidingUnit) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->timezone) < 0) return -1;
S
sma  
Shengliang Guan 已提交
776
  if (tEncodeI32(&encoder, pReq->dstVgId) < 0) return -1;
S
Shengliang Guan 已提交
777 778 779
  if (tEncodeI64(&encoder, pReq->interval) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->offset) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->sliding) < 0) return -1;
780 781
  if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->maxDelay) < 0) return -1;
S
Shengliang Guan 已提交
782
  if (tEncodeI32(&encoder, pReq->exprLen) < 0) return -1;
S
sma  
Shengliang Guan 已提交
783 784 785
  if (tEncodeI32(&encoder, pReq->tagsFilterLen) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->sqlLen) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->astLen) < 0) return -1;
S
Shengliang Guan 已提交
786 787 788 789 790 791
  if (pReq->exprLen > 0) {
    if (tEncodeBinary(&encoder, pReq->expr, pReq->exprLen) < 0) return -1;
  }
  if (pReq->tagsFilterLen > 0) {
    if (tEncodeBinary(&encoder, pReq->tagsFilter, pReq->tagsFilterLen) < 0) return -1;
  }
S
sma  
Shengliang Guan 已提交
792 793 794 795 796 797
  if (pReq->sqlLen > 0) {
    if (tEncodeBinary(&encoder, pReq->sql, pReq->sqlLen) < 0) return -1;
  }
  if (pReq->astLen > 0) {
    if (tEncodeBinary(&encoder, pReq->ast, pReq->astLen) < 0) return -1;
  }
S
Shengliang Guan 已提交
798 799 800
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
801
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
802 803 804 805
  return tlen;
}

int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq) {
H
Hongze Cheng 已提交
806 807
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
808 809 810 811 812 813 814 815

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->stb) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->intervalUnit) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->slidingUnit) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->timezone) < 0) return -1;
S
sma  
Shengliang Guan 已提交
816
  if (tDecodeI32(&decoder, &pReq->dstVgId) < 0) return -1;
S
Shengliang Guan 已提交
817 818 819
  if (tDecodeI64(&decoder, &pReq->interval) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->offset) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->sliding) < 0) return -1;
820 821
  if (tDecodeI64(&decoder, &pReq->watermark) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->maxDelay) < 0) return -1;
S
Shengliang Guan 已提交
822
  if (tDecodeI32(&decoder, &pReq->exprLen) < 0) return -1;
S
sma  
Shengliang Guan 已提交
823 824 825
  if (tDecodeI32(&decoder, &pReq->tagsFilterLen) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->sqlLen) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->astLen) < 0) return -1;
S
Shengliang Guan 已提交
826
  if (pReq->exprLen > 0) {
wafwerar's avatar
wafwerar 已提交
827
    pReq->expr = taosMemoryMalloc(pReq->exprLen);
S
Shengliang Guan 已提交
828 829 830 831
    if (pReq->expr == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->expr) < 0) return -1;
  }
  if (pReq->tagsFilterLen > 0) {
wafwerar's avatar
wafwerar 已提交
832
    pReq->tagsFilter = taosMemoryMalloc(pReq->tagsFilterLen);
S
Shengliang Guan 已提交
833 834 835
    if (pReq->tagsFilter == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->tagsFilter) < 0) return -1;
  }
S
sma  
Shengliang Guan 已提交
836
  if (pReq->sqlLen > 0) {
wafwerar's avatar
wafwerar 已提交
837
    pReq->sql = taosMemoryMalloc(pReq->sqlLen);
S
sma  
Shengliang Guan 已提交
838 839 840 841
    if (pReq->sql == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
  }
  if (pReq->astLen > 0) {
wafwerar's avatar
wafwerar 已提交
842
    pReq->ast = taosMemoryMalloc(pReq->astLen);
S
sma  
Shengliang Guan 已提交
843 844 845
    if (pReq->ast == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1;
  }
S
Shengliang Guan 已提交
846 847

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
848
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
849 850 851 852
  return 0;
}

void tFreeSMCreateSmaReq(SMCreateSmaReq *pReq) {
wafwerar's avatar
wafwerar 已提交
853 854 855 856
  taosMemoryFreeClear(pReq->expr);
  taosMemoryFreeClear(pReq->tagsFilter);
  taosMemoryFreeClear(pReq->sql);
  taosMemoryFreeClear(pReq->ast);
S
Shengliang Guan 已提交
857 858 859
}

int32_t tSerializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) {
H
Hongze Cheng 已提交
860 861
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
862 863 864

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
865

S
Shengliang Guan 已提交
866 867 868 869
  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
870
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
871 872 873 874
  return tlen;
}

int32_t tDeserializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) {
H
Hongze Cheng 已提交
875 876
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
877 878 879 880 881 882

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
883
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
884 885
  return 0;
}
dengyihao's avatar
dengyihao 已提交
886
int32_t tSerializeSMCreateFullTextReq(void *buf, int32_t bufLen, SMCreateFullTextReq *pReq) {
H
Hongze Cheng 已提交
887 888
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
dengyihao's avatar
dengyihao 已提交
889 890 891 892 893

  if (tStartEncode(&encoder) < 0) return -1;

  tEndEncode(&encoder);
  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
894
  tEncoderClear(&encoder);
dengyihao's avatar
dengyihao 已提交
895 896 897
  return tlen;
}
int32_t tDeserializeSMCreateFullTextReq(void *buf, int32_t bufLen, SMCreateFullTextReq *pReq) {
H
Hongze Cheng 已提交
898 899
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
dengyihao's avatar
dengyihao 已提交
900 901 902
  if (tStartDecode(&decoder) < 0) return -1;

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
903
  tDecoderClear(&decoder);
dengyihao's avatar
dengyihao 已提交
904 905 906 907 908 909
  return 0;
}
void tFreeSMCreateFullTextReq(SMCreateFullTextReq *pReq) {
  // impl later
  return;
}
dengyihao's avatar
dengyihao 已提交
910
int32_t tSerializeSMDropFullTextReq(void *buf, int32_t bufLen, SMDropFullTextReq *pReq) {
H
Hongze Cheng 已提交
911 912
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
dengyihao's avatar
dengyihao 已提交
913 914 915

  if (tStartEncode(&encoder) < 0) return -1;

dengyihao's avatar
dengyihao 已提交
916 917 918 919
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;

  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;

dengyihao's avatar
dengyihao 已提交
920 921
  tEndEncode(&encoder);
  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
922
  tEncoderClear(&encoder);
dengyihao's avatar
dengyihao 已提交
923 924 925
  return tlen;
}
int32_t tDeserializeSMDropFullTextReq(void *buf, int32_t bufLen, SMDropFullTextReq *pReq) {
H
Hongze Cheng 已提交
926 927
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
dengyihao's avatar
dengyihao 已提交
928
  if (tStartDecode(&decoder) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
929 930
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
931 932

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
933
  tDecoderClear(&decoder);
dengyihao's avatar
dengyihao 已提交
934 935
  return 0;
}
S
Shengliang Guan 已提交
936

S
Shengliang Guan 已提交
937
int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
H
Hongze Cheng 已提交
938 939
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
940 941

  if (tStartEncode(&encoder) < 0) return -1;
S
Shengliang Guan 已提交
942 943

  // status
S
Shengliang Guan 已提交
944
  if (tEncodeI32(&encoder, pReq->sver) < 0) return -1;
S
Shengliang Guan 已提交
945
  if (tEncodeI64(&encoder, pReq->dnodeVer) < 0) return -1;
S
Shengliang Guan 已提交
946 947 948 949
  if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->updateTime) < 0) return -1;
S
Shengliang Guan 已提交
950
  if (tEncodeFloat(&encoder, pReq->numOfCores) < 0) return -1;
S
Shengliang Guan 已提交
951
  if (tEncodeI32(&encoder, pReq->numOfSupportVnodes) < 0) return -1;
952 953
  if (tEncodeI64(&encoder, pReq->memTotal) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->memAvail) < 0) return -1;
S
Shengliang Guan 已提交
954
  if (tEncodeCStr(&encoder, pReq->dnodeEp) < 0) return -1;
S
Shengliang Guan 已提交
955 956

  // cluster cfg
S
Shengliang Guan 已提交
957 958 959 960 961
  if (tEncodeI32(&encoder, pReq->clusterCfg.statusInterval) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->clusterCfg.checkTime) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->clusterCfg.timezone) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->clusterCfg.locale) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->clusterCfg.charset) < 0) return -1;
S
Shengliang Guan 已提交
962 963 964

  // vnode loads
  int32_t vlen = (int32_t)taosArrayGetSize(pReq->pVloads);
S
Shengliang Guan 已提交
965
  if (tEncodeI32(&encoder, vlen) < 0) return -1;
S
Shengliang Guan 已提交
966 967
  for (int32_t i = 0; i < vlen; ++i) {
    SVnodeLoad *pload = taosArrayGet(pReq->pVloads, i);
S
Shengliang Guan 已提交
968
    if (tEncodeI32(&encoder, pload->vgId) < 0) return -1;
S
Shengliang Guan 已提交
969
    if (tEncodeI32(&encoder, pload->syncState) < 0) return -1;
S
Shengliang Guan 已提交
970 971 972 973 974
    if (tEncodeI64(&encoder, pload->numOfTables) < 0) return -1;
    if (tEncodeI64(&encoder, pload->numOfTimeSeries) < 0) return -1;
    if (tEncodeI64(&encoder, pload->totalStorage) < 0) return -1;
    if (tEncodeI64(&encoder, pload->compStorage) < 0) return -1;
    if (tEncodeI64(&encoder, pload->pointsWritten) < 0) return -1;
S
Shengliang Guan 已提交
975 976
  }

977 978 979
  // mnode loads
  if (tEncodeI32(&encoder, pReq->mload.syncState) < 0) return -1;

D
dapan1121 已提交
980 981 982 983 984 985
  if (tEncodeI32(&encoder, pReq->qload.dnodeId) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfProcessedQuery) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfProcessedCQuery) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfProcessedFetch) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfProcessedDrop) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfProcessedHb) < 0) return -1;
D
dapan1121 已提交
986
  if (tEncodeI64(&encoder, pReq->qload.numOfProcessedDelete) < 0) return -1;
D
dapan1121 已提交
987 988 989 990 991 992
  if (tEncodeI64(&encoder, pReq->qload.cacheDataSize) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfQueryInQueue) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.numOfFetchInQueue) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.timeInQueryQueue) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->qload.timeInFetchQueue) < 0) return -1;

S
Shengliang Guan 已提交
993 994 995
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
996
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
997 998 999
  return tlen;
}

S
Shengliang Guan 已提交
1000
int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
H
Hongze Cheng 已提交
1001 1002
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1003 1004 1005

  if (tStartDecode(&decoder) < 0) return -1;

S
Shengliang Guan 已提交
1006
  // status
S
Shengliang Guan 已提交
1007
  if (tDecodeI32(&decoder, &pReq->sver) < 0) return -1;
S
Shengliang Guan 已提交
1008
  if (tDecodeI64(&decoder, &pReq->dnodeVer) < 0) return -1;
S
Shengliang Guan 已提交
1009 1010 1011 1012
  if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->updateTime) < 0) return -1;
S
Shengliang Guan 已提交
1013
  if (tDecodeFloat(&decoder, &pReq->numOfCores) < 0) return -1;
S
Shengliang Guan 已提交
1014
  if (tDecodeI32(&decoder, &pReq->numOfSupportVnodes) < 0) return -1;
1015 1016
  if (tDecodeI64(&decoder, &pReq->memTotal) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->memAvail) < 0) return -1;
S
Shengliang Guan 已提交
1017
  if (tDecodeCStrTo(&decoder, pReq->dnodeEp) < 0) return -1;
S
Shengliang Guan 已提交
1018 1019

  // cluster cfg
S
Shengliang Guan 已提交
1020 1021 1022 1023 1024
  if (tDecodeI32(&decoder, &pReq->clusterCfg.statusInterval) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->clusterCfg.checkTime) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->clusterCfg.timezone) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->clusterCfg.locale) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->clusterCfg.charset) < 0) return -1;
S
Shengliang Guan 已提交
1025 1026 1027

  // vnode loads
  int32_t vlen = 0;
S
Shengliang Guan 已提交
1028
  if (tDecodeI32(&decoder, &vlen) < 0) return -1;
S
Shengliang Guan 已提交
1029 1030 1031
  pReq->pVloads = taosArrayInit(vlen, sizeof(SVnodeLoad));
  if (pReq->pVloads == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
1032
    return -1;
S
Shengliang Guan 已提交
1033 1034 1035 1036
  }

  for (int32_t i = 0; i < vlen; ++i) {
    SVnodeLoad vload = {0};
S
Shengliang Guan 已提交
1037
    if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1;
S
Shengliang Guan 已提交
1038
    if (tDecodeI32(&decoder, &vload.syncState) < 0) return -1;
S
Shengliang Guan 已提交
1039 1040 1041 1042 1043
    if (tDecodeI64(&decoder, &vload.numOfTables) < 0) return -1;
    if (tDecodeI64(&decoder, &vload.numOfTimeSeries) < 0) return -1;
    if (tDecodeI64(&decoder, &vload.totalStorage) < 0) return -1;
    if (tDecodeI64(&decoder, &vload.compStorage) < 0) return -1;
    if (tDecodeI64(&decoder, &vload.pointsWritten) < 0) return -1;
S
Shengliang Guan 已提交
1044 1045
    if (taosArrayPush(pReq->pVloads, &vload) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
1046
      return -1;
S
Shengliang Guan 已提交
1047 1048 1049
    }
  }

1050 1051
  if (tDecodeI32(&decoder, &pReq->mload.syncState) < 0) return -1;

D
dapan1121 已提交
1052 1053 1054 1055 1056 1057
  if (tDecodeI32(&decoder, &pReq->qload.dnodeId) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedQuery) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedCQuery) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedFetch) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedDrop) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedHb) < 0) return -1;
D
dapan1121 已提交
1058
  if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedDelete) < 0) return -1;
D
dapan1121 已提交
1059 1060 1061 1062 1063 1064
  if (tDecodeI64(&decoder, &pReq->qload.cacheDataSize) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfQueryInQueue) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.numOfFetchInQueue) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.timeInQueryQueue) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->qload.timeInFetchQueue) < 0) return -1;

S
Shengliang Guan 已提交
1065
  tEndDecode(&decoder);
H
Hongze Cheng 已提交
1066
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1067
  return 0;
S
Shengliang Guan 已提交
1068
}
S
Shengliang Guan 已提交
1069

S
Shengliang Guan 已提交
1070 1071
void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); }

S
Shengliang Guan 已提交
1072
int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
H
Hongze Cheng 已提交
1073 1074
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1075

S
Shengliang Guan 已提交
1076
  if (tStartEncode(&encoder) < 0) return -1;
S
Shengliang Guan 已提交
1077

S
Shengliang Guan 已提交
1078
  // status
S
Shengliang Guan 已提交
1079
  if (tEncodeI64(&encoder, pRsp->dnodeVer) < 0) return -1;
S
Shengliang Guan 已提交
1080 1081

  // dnode cfg
S
Shengliang Guan 已提交
1082 1083
  if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->dnodeCfg.clusterId) < 0) return -1;
S
Shengliang Guan 已提交
1084 1085 1086

  // dnode eps
  int32_t dlen = (int32_t)taosArrayGetSize(pRsp->pDnodeEps);
S
Shengliang Guan 已提交
1087
  if (tEncodeI32(&encoder, dlen) < 0) return -1;
S
Shengliang Guan 已提交
1088 1089
  for (int32_t i = 0; i < dlen; ++i) {
    SDnodeEp *pDnodeEp = taosArrayGet(pRsp->pDnodeEps, i);
S
Shengliang Guan 已提交
1090 1091 1092 1093
    if (tEncodeI32(&encoder, pDnodeEp->id) < 0) return -1;
    if (tEncodeI8(&encoder, pDnodeEp->isMnode) < 0) return -1;
    if (tEncodeCStr(&encoder, pDnodeEp->ep.fqdn) < 0) return -1;
    if (tEncodeU16(&encoder, pDnodeEp->ep.port) < 0) return -1;
S
Shengliang Guan 已提交
1094 1095
  }

S
Shengliang Guan 已提交
1096 1097 1098
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1099
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1100 1101 1102
  return tlen;
}

S
Shengliang Guan 已提交
1103
int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
H
Hongze Cheng 已提交
1104 1105
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1106 1107 1108

  if (tStartDecode(&decoder) < 0) return -1;

S
Shengliang Guan 已提交
1109
  // status
S
Shengliang Guan 已提交
1110
  if (tDecodeI64(&decoder, &pRsp->dnodeVer) < 0) return -1;
S
Shengliang Guan 已提交
1111 1112

  // cluster cfg
S
Shengliang Guan 已提交
1113 1114
  if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->dnodeCfg.clusterId) < 0) return -1;
S
Shengliang Guan 已提交
1115 1116 1117

  // dnode eps
  int32_t dlen = 0;
S
Shengliang Guan 已提交
1118
  if (tDecodeI32(&decoder, &dlen) < 0) return -1;
S
Shengliang Guan 已提交
1119 1120 1121
  pRsp->pDnodeEps = taosArrayInit(dlen, sizeof(SDnodeEp));
  if (pRsp->pDnodeEps == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
1122
    return -1;
S
Shengliang Guan 已提交
1123 1124 1125 1126
  }

  for (int32_t i = 0; i < dlen; ++i) {
    SDnodeEp dnodeEp = {0};
S
Shengliang Guan 已提交
1127 1128 1129 1130
    if (tDecodeI32(&decoder, &dnodeEp.id) < 0) return -1;
    if (tDecodeI8(&decoder, &dnodeEp.isMnode) < 0) return -1;
    if (tDecodeCStrTo(&decoder, dnodeEp.ep.fqdn) < 0) return -1;
    if (tDecodeU16(&decoder, &dnodeEp.ep.port) < 0) return -1;
S
Shengliang Guan 已提交
1131 1132
    if (taosArrayPush(pRsp->pDnodeEps, &dnodeEp) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
S
Shengliang Guan 已提交
1133
      return -1;
S
Shengliang Guan 已提交
1134 1135 1136
    }
  }

S
Shengliang Guan 已提交
1137
  tEndDecode(&decoder);
H
Hongze Cheng 已提交
1138
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1139
  return 0;
S
Shengliang Guan 已提交
1140
}
S
Shengliang Guan 已提交
1141

S
shm  
Shengliang Guan 已提交
1142 1143
void tFreeSStatusRsp(SStatusRsp *pRsp) { taosArrayDestroy(pRsp->pDnodeEps); }

S
Shengliang Guan 已提交
1144
int32_t tSerializeSCreateAcctReq(void *buf, int32_t bufLen, SCreateAcctReq *pReq) {
H
Hongze Cheng 已提交
1145 1146
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->maxUsers) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->maxDbs) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->maxTimeSeries) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->maxStreams) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->accessState) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->maxStorage) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1160
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1161 1162 1163
  return tlen;
}

S
Shengliang Guan 已提交
1164
int32_t tDeserializeSCreateAcctReq(void *buf, int32_t bufLen, SCreateAcctReq *pReq) {
H
Hongze Cheng 已提交
1165 1166
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->maxUsers) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->maxDbs) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->maxTimeSeries) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->maxStreams) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->accessState) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->maxStorage) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1179
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1180
  return 0;
S
Shengliang Guan 已提交
1181 1182
}

S
Shengliang Guan 已提交
1183
int32_t tSerializeSDropUserReq(void *buf, int32_t bufLen, SDropUserReq *pReq) {
H
Hongze Cheng 已提交
1184 1185
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1186 1187 1188 1189 1190 1191

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1192
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1193 1194 1195
  return tlen;
}

S
Shengliang Guan 已提交
1196
int32_t tDeserializeSDropUserReq(void *buf, int32_t bufLen, SDropUserReq *pReq) {
H
Hongze Cheng 已提交
1197 1198
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1199 1200 1201 1202 1203

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1204
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1205
  return 0;
S
Shengliang Guan 已提交
1206 1207
}

S
Shengliang Guan 已提交
1208
int32_t tSerializeSCreateUserReq(void *buf, int32_t bufLen, SCreateUserReq *pReq) {
H
Hongze Cheng 已提交
1209 1210
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1211 1212 1213 1214

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->createType) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->superUser) < 0) return -1;
1215 1216
  if (tEncodeI8(&encoder, pReq->sysInfo) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->enable) < 0) return -1;
S
Shengliang Guan 已提交
1217 1218 1219 1220 1221
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1222
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1223 1224 1225
  return tlen;
}

S
Shengliang Guan 已提交
1226
int32_t tDeserializeSCreateUserReq(void *buf, int32_t bufLen, SCreateUserReq *pReq) {
H
Hongze Cheng 已提交
1227 1228
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1229 1230 1231 1232

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->createType) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->superUser) < 0) return -1;
1233 1234
  if (tDecodeI8(&decoder, &pReq->sysInfo) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->enable) < 0) return -1;
S
Shengliang Guan 已提交
1235 1236 1237 1238
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1239
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1240
  return 0;
S
Shengliang Guan 已提交
1241 1242
}

S
Shengliang Guan 已提交
1243
int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq) {
H
Hongze Cheng 已提交
1244 1245
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1246 1247 1248 1249

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->alterType) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->superUser) < 0) return -1;
1250 1251
  if (tEncodeI8(&encoder, pReq->sysInfo) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->enable) < 0) return -1;
S
Shengliang Guan 已提交
1252 1253 1254 1255 1256 1257
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->dbname) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1258
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1259 1260 1261
  return tlen;
}

S
Shengliang Guan 已提交
1262
int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq) {
H
Hongze Cheng 已提交
1263 1264
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1265 1266 1267 1268

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->alterType) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->superUser) < 0) return -1;
1269 1270
  if (tDecodeI8(&decoder, &pReq->sysInfo) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->enable) < 0) return -1;
S
Shengliang Guan 已提交
1271 1272 1273 1274 1275
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->dbname) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1276
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1277
  return 0;
S
Shengliang Guan 已提交
1278 1279
}

S
Shengliang Guan 已提交
1280
int32_t tSerializeSGetUserAuthReq(void *buf, int32_t bufLen, SGetUserAuthReq *pReq) {
H
Hongze Cheng 已提交
1281 1282
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1283 1284 1285 1286 1287 1288

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1289
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1290 1291 1292
  return tlen;
}

S
Shengliang Guan 已提交
1293
int32_t tDeserializeSGetUserAuthReq(void *buf, int32_t bufLen, SGetUserAuthReq *pReq) {
H
Hongze Cheng 已提交
1294 1295
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1296 1297 1298 1299 1300

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1301
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1302
  return 0;
S
Shengliang Guan 已提交
1303 1304
}

H
Hongze Cheng 已提交
1305
int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp) {
D
dapan 已提交
1306 1307
  if (tEncodeCStr(pEncoder, pRsp->user) < 0) return -1;
  if (tEncodeI8(pEncoder, pRsp->superAuth) < 0) return -1;
1308 1309 1310
  if (tEncodeI8(pEncoder, pRsp->sysInfo) < 0) return -1;
  if (tEncodeI8(pEncoder, pRsp->enable) < 0) return -1;
  if (tEncodeI8(pEncoder, pRsp->reserve) < 0) return -1;
D
dapan 已提交
1311
  if (tEncodeI32(pEncoder, pRsp->version) < 0) return -1;
S
Shengliang Guan 已提交
1312

D
dapan 已提交
1313
  int32_t numOfCreatedDbs = taosHashGetSize(pRsp->createdDbs);
S
Shengliang Guan 已提交
1314 1315
  int32_t numOfReadDbs = taosHashGetSize(pRsp->readDbs);
  int32_t numOfWriteDbs = taosHashGetSize(pRsp->writeDbs);
D
dapan 已提交
1316 1317 1318
  if (tEncodeI32(pEncoder, numOfCreatedDbs) < 0) return -1;
  if (tEncodeI32(pEncoder, numOfReadDbs) < 0) return -1;
  if (tEncodeI32(pEncoder, numOfWriteDbs) < 0) return -1;
S
Shengliang Guan 已提交
1319

D
dapan 已提交
1320
  char *db = taosHashIterate(pRsp->createdDbs, NULL);
S
Shengliang Guan 已提交
1321
  while (db != NULL) {
D
dapan 已提交
1322 1323 1324 1325 1326 1327 1328
    if (tEncodeCStr(pEncoder, db) < 0) return -1;
    db = taosHashIterate(pRsp->createdDbs, db);
  }

  db = taosHashIterate(pRsp->readDbs, NULL);
  while (db != NULL) {
    if (tEncodeCStr(pEncoder, db) < 0) return -1;
S
Shengliang Guan 已提交
1329
    db = taosHashIterate(pRsp->readDbs, db);
S
Shengliang Guan 已提交
1330 1331
  }

S
Shengliang Guan 已提交
1332
  db = taosHashIterate(pRsp->writeDbs, NULL);
S
Shengliang Guan 已提交
1333
  while (db != NULL) {
D
dapan 已提交
1334
    if (tEncodeCStr(pEncoder, db) < 0) return -1;
S
Shengliang Guan 已提交
1335
    db = taosHashIterate(pRsp->writeDbs, db);
S
Shengliang Guan 已提交
1336 1337
  }

D
dapan 已提交
1338 1339 1340 1341
  return 0;
}

int32_t tSerializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp *pRsp) {
H
Hongze Cheng 已提交
1342 1343
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan 已提交
1344 1345 1346 1347 1348

  if (tStartEncode(&encoder) < 0) return -1;

  if (tSerializeSGetUserAuthRspImpl(&encoder, pRsp) < 0) return -1;

S
Shengliang Guan 已提交
1349 1350 1351
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1352
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1353 1354 1355
  return tlen;
}

H
Hongze Cheng 已提交
1356
int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRsp) {
D
dapan 已提交
1357 1358 1359
  pRsp->createdDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
  pRsp->readDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
  pRsp->writeDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
S
Shengliang Guan 已提交
1360
  if (pRsp->readDbs == NULL || pRsp->writeDbs == NULL) {
S
Shengliang Guan 已提交
1361
    return -1;
S
Shengliang Guan 已提交
1362 1363
  }

D
dapan 已提交
1364 1365
  if (tDecodeCStrTo(pDecoder, pRsp->user) < 0) return -1;
  if (tDecodeI8(pDecoder, &pRsp->superAuth) < 0) return -1;
1366 1367 1368
  if (tDecodeI8(pDecoder, &pRsp->sysInfo) < 0) return -1;
  if (tDecodeI8(pDecoder, &pRsp->enable) < 0) return -1;
  if (tDecodeI8(pDecoder, &pRsp->reserve) < 0) return -1;
D
dapan 已提交
1369
  if (tDecodeI32(pDecoder, &pRsp->version) < 0) return -1;
S
Shengliang Guan 已提交
1370

D
dapan 已提交
1371
  int32_t numOfCreatedDbs = 0;
S
Shengliang Guan 已提交
1372 1373
  int32_t numOfReadDbs = 0;
  int32_t numOfWriteDbs = 0;
D
dapan 已提交
1374 1375 1376 1377 1378 1379 1380
  if (tDecodeI32(pDecoder, &numOfCreatedDbs) < 0) return -1;
  if (tDecodeI32(pDecoder, &numOfReadDbs) < 0) return -1;
  if (tDecodeI32(pDecoder, &numOfWriteDbs) < 0) return -1;

  for (int32_t i = 0; i < numOfCreatedDbs; ++i) {
    char db[TSDB_DB_FNAME_LEN] = {0};
    if (tDecodeCStrTo(pDecoder, db) < 0) return -1;
D
fix bug  
dapan 已提交
1381
    int32_t len = strlen(db);
D
dapan 已提交
1382 1383
    taosHashPut(pRsp->createdDbs, db, len, db, len);
  }
S
Shengliang Guan 已提交
1384 1385 1386

  for (int32_t i = 0; i < numOfReadDbs; ++i) {
    char db[TSDB_DB_FNAME_LEN] = {0};
D
dapan 已提交
1387
    if (tDecodeCStrTo(pDecoder, db) < 0) return -1;
D
fix bug  
dapan 已提交
1388
    int32_t len = strlen(db);
S
Shengliang Guan 已提交
1389
    taosHashPut(pRsp->readDbs, db, len, db, len);
S
Shengliang Guan 已提交
1390 1391 1392 1393
  }

  for (int32_t i = 0; i < numOfWriteDbs; ++i) {
    char db[TSDB_DB_FNAME_LEN] = {0};
D
dapan 已提交
1394
    if (tDecodeCStrTo(pDecoder, db) < 0) return -1;
D
fix bug  
dapan 已提交
1395
    int32_t len = strlen(db);
S
Shengliang Guan 已提交
1396
    taosHashPut(pRsp->writeDbs, db, len, db, len);
S
Shengliang Guan 已提交
1397 1398
  }

D
dapan 已提交
1399 1400 1401 1402
  return 0;
}

int32_t tDeserializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp *pRsp) {
H
Hongze Cheng 已提交
1403 1404
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan 已提交
1405 1406 1407 1408 1409

  if (tStartDecode(&decoder) < 0) return -1;

  if (tDeserializeSGetUserAuthRspImpl(&decoder, pRsp) < 0) return -1;

S
Shengliang Guan 已提交
1410 1411
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1412
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1413
  return 0;
S
Shengliang Guan 已提交
1414
}
S
Shengliang Guan 已提交
1415

S
Shengliang Guan 已提交
1416
void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
D
dapan 已提交
1417
  taosHashCleanup(pRsp->createdDbs);
S
Shengliang Guan 已提交
1418 1419 1420 1421
  taosHashCleanup(pRsp->readDbs);
  taosHashCleanup(pRsp->writeDbs);
}

1422
int32_t tSerializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
H
Hongze Cheng 已提交
1423 1424
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1425 1426 1427 1428 1429 1430

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1431
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1432 1433 1434
  return tlen;
}

1435
int32_t tDeserializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
H
Hongze Cheng 已提交
1436 1437
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1438 1439 1440 1441 1442

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1443
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1444 1445
  return 0;
}
S
Shengliang Guan 已提交
1446 1447

int32_t tSerializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) {
H
Hongze Cheng 已提交
1448 1449
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
1450 1451 1452 1453 1454 1455 1456 1457

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->port) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1458
  tEncoderClear(&encoder);
1459
  return tlen;
S
Shengliang Guan 已提交
1460 1461 1462
}

int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) {
H
Hongze Cheng 已提交
1463 1464
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
1465 1466 1467 1468 1469 1470 1471

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->port) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1472
  tDecoderClear(&decoder);
1473
  return 0;
S
Shengliang Guan 已提交
1474 1475 1476
}

int32_t tSerializeSMCfgDnodeReq(void *buf, int32_t bufLen, SMCfgDnodeReq *pReq) {
H
Hongze Cheng 已提交
1477 1478
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1479 1480 1481 1482 1483 1484 1485 1486

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->config) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->value) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1487
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1488 1489 1490 1491
  return tlen;
}

int32_t tDeserializeSMCfgDnodeReq(void *buf, int32_t bufLen, SMCfgDnodeReq *pReq) {
H
Hongze Cheng 已提交
1492 1493
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1494 1495 1496 1497 1498 1499 1500

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->config) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->value) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1501
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1502 1503 1504
  return 0;
}

S
Shengliang Guan 已提交
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
int32_t tSerializeSDCfgDnodeReq(void *buf, int32_t bufLen, SDCfgDnodeReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->config) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->value) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSDCfgDnodeReq(void *buf, int32_t bufLen, SDCfgDnodeReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->config) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->value) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

S
Shengliang Guan 已提交
1532
int32_t tSerializeSCreateDnodeReq(void *buf, int32_t bufLen, SCreateDnodeReq *pReq) {
H
Hongze Cheng 已提交
1533 1534
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1535 1536 1537 1538 1539 1540 1541

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->port) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1542
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1543 1544 1545 1546
  return tlen;
}

int32_t tDeserializeSCreateDnodeReq(void *buf, int32_t bufLen, SCreateDnodeReq *pReq) {
H
Hongze Cheng 已提交
1547 1548
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1549 1550 1551 1552 1553 1554

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->port) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1555
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1556 1557
  return 0;
}
S
Shengliang Guan 已提交
1558 1559

int32_t tSerializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pReq) {
H
Hongze Cheng 已提交
1560 1561
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1562 1563 1564 1565 1566 1567 1568 1569 1570

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->funcType) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->scriptType) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->outputType) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->outputLen) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->bufSize) < 0) return -1;
1571
  if (tEncodeI32(&encoder, pReq->codeLen) < 0) return -1;
S
Shengliang Guan 已提交
1572
  if (tEncodeI64(&encoder, pReq->signature) < 0) return -1;
1573 1574

  if (pReq->pCode != NULL) {
S
Shengliang Guan 已提交
1575
    if (tEncodeBinary(&encoder, pReq->pCode, pReq->codeLen) < 0) return -1;
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
  }

  int32_t commentSize = 0;
  if (pReq->pComment != NULL) {
    commentSize = strlen(pReq->pComment) + 1;
  }
  if (tEncodeI32(&encoder, commentSize) < 0) return -1;
  if (pReq->pComment != NULL) {
    if (tEncodeCStr(&encoder, pReq->pComment) < 0) return -1;
  }

S
Shengliang Guan 已提交
1587 1588 1589
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1590
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1591 1592 1593 1594
  return tlen;
}

int32_t tDeserializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pReq) {
H
Hongze Cheng 已提交
1595 1596
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1597 1598 1599 1600 1601 1602 1603 1604 1605

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->funcType) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->scriptType) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->outputType) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->outputLen) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->bufSize) < 0) return -1;
1606
  if (tDecodeI32(&decoder, &pReq->codeLen) < 0) return -1;
S
Shengliang Guan 已提交
1607
  if (tDecodeI64(&decoder, &pReq->signature) < 0) return -1;
1608

S
Shengliang Guan 已提交
1609 1610
  if (pReq->codeLen > 0) {
    pReq->pCode = taosMemoryCalloc(1, pReq->codeLen);
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628
    if (pReq->pCode == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
    if (tDecodeCStrTo(&decoder, pReq->pCode) < 0) return -1;
  }

  int32_t commentSize = 0;
  if (tDecodeI32(&decoder, &commentSize) < 0) return -1;
  if (commentSize > 0) {
    pReq->pComment = taosMemoryCalloc(1, commentSize);
    if (pReq->pComment == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
    if (tDecodeCStrTo(&decoder, pReq->pComment) < 0) return -1;
  }

S
Shengliang Guan 已提交
1629 1630
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1631
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1632 1633 1634
  return 0;
}

1635 1636 1637 1638 1639
void tFreeSCreateFuncReq(SCreateFuncReq *pReq) {
  taosMemoryFree(pReq->pCode);
  taosMemoryFree(pReq->pComment);
}

S
Shengliang Guan 已提交
1640
int32_t tSerializeSDropFuncReq(void *buf, int32_t bufLen, SDropFuncReq *pReq) {
H
Hongze Cheng 已提交
1641 1642
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1643 1644 1645 1646 1647 1648 1649

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1650
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1651 1652 1653 1654
  return tlen;
}

int32_t tDeserializeSDropFuncReq(void *buf, int32_t bufLen, SDropFuncReq *pReq) {
H
Hongze Cheng 已提交
1655 1656
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1657 1658 1659 1660 1661 1662

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1663
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1664 1665 1666 1667
  return 0;
}

int32_t tSerializeSRetrieveFuncReq(void *buf, int32_t bufLen, SRetrieveFuncReq *pReq) {
H
Hongze Cheng 已提交
1668 1669
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1670 1671 1672

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->numOfFuncs) < 0) return -1;
D
dapan1121 已提交
1673
  if (tEncodeI8(&encoder, pReq->ignoreCodeComment) < 0) return -1;
S
Shengliang Guan 已提交
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683

  if (pReq->numOfFuncs != (int32_t)taosArrayGetSize(pReq->pFuncNames)) return -1;
  for (int32_t i = 0; i < pReq->numOfFuncs; ++i) {
    char *fname = taosArrayGet(pReq->pFuncNames, i);
    if (tEncodeCStr(&encoder, fname) < 0) return -1;
  }

  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1684
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1685 1686 1687 1688
  return tlen;
}

int32_t tDeserializeSRetrieveFuncReq(void *buf, int32_t bufLen, SRetrieveFuncReq *pReq) {
H
Hongze Cheng 已提交
1689 1690
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1691 1692 1693

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->numOfFuncs) < 0) return -1;
D
dapan1121 已提交
1694
  if (tDecodeI8(&decoder, (int8_t *)&pReq->ignoreCodeComment) < 0) return -1;
S
Shengliang Guan 已提交
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705

  pReq->pFuncNames = taosArrayInit(pReq->numOfFuncs, TSDB_FUNC_NAME_LEN);
  if (pReq->pFuncNames == NULL) return -1;

  for (int32_t i = 0; i < pReq->numOfFuncs; ++i) {
    char fname[TSDB_FUNC_NAME_LEN] = {0};
    if (tDecodeCStrTo(&decoder, fname) < 0) return -1;
    taosArrayPush(pReq->pFuncNames, fname);
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1706
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1707 1708 1709
  return 0;
}

1710 1711
void tFreeSRetrieveFuncReq(SRetrieveFuncReq *pReq) { taosArrayDestroy(pReq->pFuncNames); }

S
Shengliang Guan 已提交
1712
int32_t tSerializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp *pRsp) {
H
Hongze Cheng 已提交
1713 1714
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->numOfFuncs) < 0) return -1;

  if (pRsp->numOfFuncs != (int32_t)taosArrayGetSize(pRsp->pFuncInfos)) return -1;
  for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) {
    SFuncInfo *pInfo = taosArrayGet(pRsp->pFuncInfos, i);

    if (tEncodeCStr(&encoder, pInfo->name) < 0) return -1;
    if (tEncodeI8(&encoder, pInfo->funcType) < 0) return -1;
    if (tEncodeI8(&encoder, pInfo->scriptType) < 0) return -1;
    if (tEncodeI8(&encoder, pInfo->outputType) < 0) return -1;
    if (tEncodeI32(&encoder, pInfo->outputLen) < 0) return -1;
    if (tEncodeI32(&encoder, pInfo->bufSize) < 0) return -1;
    if (tEncodeI64(&encoder, pInfo->signature) < 0) return -1;
    if (tEncodeI32(&encoder, pInfo->codeSize) < 0) return -1;
1731
    if (tEncodeI32(&encoder, pInfo->commentSize) < 0) return -1;
D
dapan1121 已提交
1732
    if (pInfo->codeSize) {
S
Shengliang Guan 已提交
1733
      if (tEncodeBinary(&encoder, pInfo->pCode, pInfo->codeSize) < 0) return -1;
D
dapan1121 已提交
1734 1735 1736 1737
    }
    if (pInfo->commentSize) {
      if (tEncodeCStr(&encoder, pInfo->pComment) < 0) return -1;
    }
S
Shengliang Guan 已提交
1738 1739 1740 1741 1742
  }

  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
1743
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
1744 1745 1746 1747
  return tlen;
}

int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp *pRsp) {
H
Hongze Cheng 已提交
1748 1749
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->numOfFuncs) < 0) return -1;

  pRsp->pFuncInfos = taosArrayInit(pRsp->numOfFuncs, sizeof(SFuncInfo));
  if (pRsp->pFuncInfos == NULL) return -1;

  for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) {
    SFuncInfo fInfo = {0};
    if (tDecodeCStrTo(&decoder, fInfo.name) < 0) return -1;
    if (tDecodeI8(&decoder, &fInfo.funcType) < 0) return -1;
    if (tDecodeI8(&decoder, &fInfo.scriptType) < 0) return -1;
    if (tDecodeI8(&decoder, &fInfo.outputType) < 0) return -1;
    if (tDecodeI32(&decoder, &fInfo.outputLen) < 0) return -1;
    if (tDecodeI32(&decoder, &fInfo.bufSize) < 0) return -1;
    if (tDecodeI64(&decoder, &fInfo.signature) < 0) return -1;
    if (tDecodeI32(&decoder, &fInfo.codeSize) < 0) return -1;
1767
    if (tDecodeI32(&decoder, &fInfo.commentSize) < 0) return -1;
D
dapan1121 已提交
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
    if (fInfo.codeSize) {
      fInfo.pCode = taosMemoryCalloc(1, fInfo.codeSize);
      if (fInfo.pCode == NULL) {
        terrno = TSDB_CODE_OUT_OF_MEMORY;
        return -1;
      }
      if (tDecodeCStrTo(&decoder, fInfo.pCode) < 0) return -1;
    }
    if (fInfo.commentSize) {
      fInfo.pComment = taosMemoryCalloc(1, fInfo.commentSize);
      if (fInfo.pComment == NULL) {
        terrno = TSDB_CODE_OUT_OF_MEMORY;
        return -1;
      }
      if (tDecodeCStrTo(&decoder, fInfo.pComment) < 0) return -1;
1783 1784
    }

S
Shengliang Guan 已提交
1785 1786 1787 1788
    taosArrayPush(pRsp->pFuncInfos, &fInfo);
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
1789
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
1790 1791
  return 0;
}
S
Shengliang Guan 已提交
1792

D
dapan1121 已提交
1793 1794 1795 1796 1797 1798 1799 1800 1801
void tFreeSFuncInfo(SFuncInfo *pInfo) {
  if (NULL == pInfo) {
    return;
  }

  taosMemoryFree(pInfo->pCode);
  taosMemoryFree(pInfo->pComment);
}

1802 1803 1804 1805
void tFreeSRetrieveFuncRsp(SRetrieveFuncRsp *pRsp) {
  int32_t size = taosArrayGetSize(pRsp->pFuncInfos);
  for (int32_t i = 0; i < size; ++i) {
    SFuncInfo *pInfo = taosArrayGet(pRsp->pFuncInfos, i);
D
dapan1121 已提交
1806
    tFreeSFuncInfo(pInfo);
1807 1808 1809 1810
  }
  taosArrayDestroy(pRsp->pFuncInfos);
}

D
dapan1121 已提交
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857
int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);
  if (buf != NULL) {
    buf = (char *)buf + headLen;
    bufLen -= headLen;
  }

  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->tbName) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);

  if (buf != NULL) {
    SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
    pHead->vgId = htonl(pReq->header.vgId);
    pHead->contLen = htonl(tlen + headLen);
  }

  return tlen + headLen;
}

int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);

  SMsgHead *pHead = buf;
  pHead->vgId = pReq->header.vgId;
  pHead->contLen = pReq->header.contLen;

  SDecoder decoder = {0};
  tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->tbName) < 0) return -1;

  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) {
D
dapan1121 已提交
1858 1859
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
1860

D
dapan1121 已提交
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872
  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->tbName) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->stbName) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->dbFName) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->numOfTags) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->numOfColumns) < 0) return -1;
  if (tEncodeI8(&encoder, pRsp->tableType) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->delay1) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->delay2) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->watermark1) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->watermark2) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->ttl) < 0) return -1;
1873

D
dapan1121 已提交
1874 1875 1876 1877 1878 1879 1880
  int32_t numOfFuncs = taosArrayGetSize(pRsp->pFuncs);
  if (tEncodeI32(&encoder, numOfFuncs) < 0) return -1;
  for (int32_t i = 0; i < numOfFuncs; ++i) {
    const char *pFunc = taosArrayGet(pRsp->pFuncs, i);
    if (tEncodeCStr(&encoder, pFunc) < 0) return -1;
  }

1881
  if (tEncodeI32(&encoder, pRsp->commentLen) < 0) return -1;
D
dapan1121 已提交
1882 1883 1884
  if (pRsp->commentLen > 0) {
    if (tEncodeCStr(&encoder, pRsp->pComment) < 0) return -1;
  }
1885

D
dapan1121 已提交
1886 1887 1888 1889 1890
  for (int32_t i = 0; i < pRsp->numOfColumns + pRsp->numOfTags; ++i) {
    SSchema *pSchema = &pRsp->pSchemas[i];
    if (tEncodeSSchema(&encoder, pSchema) < 0) return -1;
  }

1891 1892 1893
  if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1;
  if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1;

D
dapan1121 已提交
1894 1895 1896 1897 1898
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
D
dapan1121 已提交
1899 1900 1901
}

int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) {
D
dapan1121 已提交
1902 1903
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
1904

D
dapan1121 已提交
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->tbName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->stbName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->dbFName) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->numOfTags) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->numOfColumns) < 0) return -1;
  if (tDecodeI8(&decoder, &pRsp->tableType) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->delay1) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->delay2) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->watermark1) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->watermark2) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->ttl) < 0) return -1;

  int32_t numOfFuncs = 0;
  if (tDecodeI32(&decoder, &numOfFuncs) < 0) return -1;
  if (numOfFuncs > 0) {
    pRsp->pFuncs = taosArrayInit(numOfFuncs, TSDB_FUNC_NAME_LEN);
    if (NULL == pRsp->pFuncs) return -1;
  }
  for (int32_t i = 0; i < numOfFuncs; ++i) {
    char pFunc[TSDB_FUNC_NAME_LEN];
    if (tDecodeCStrTo(&decoder, pFunc) < 0) return -1;
    if (taosArrayPush(pRsp->pFuncs, pFunc) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
  }

  if (tDecodeI32(&decoder, &pRsp->commentLen) < 0) return -1;
  if (pRsp->commentLen > 0) {
    if (tDecodeCStrAlloc(&decoder, &pRsp->pComment) < 0) return -1;
  } else {
    pRsp->pComment = NULL;
  }

  int32_t totalCols = pRsp->numOfTags + pRsp->numOfColumns;
  pRsp->pSchemas = taosMemoryMalloc(sizeof(SSchema) * totalCols);
  if (pRsp->pSchemas == NULL) return -1;

  for (int32_t i = 0; i < totalCols; ++i) {
    SSchema *pSchema = &pRsp->pSchemas[i];
    if (tDecodeSSchema(&decoder, pSchema) < 0) return -1;
  }

  if (tDecodeI32(&decoder, &pRsp->tagsLen) < 0) return -1;
1950
  if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 0) return -1;
D
dapan1121 已提交
1951 1952 1953 1954 1955

  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
D
dapan1121 已提交
1956 1957
}

D
dapan1121 已提交
1958 1959 1960 1961 1962 1963 1964 1965
void tFreeSTableCfgRsp(STableCfgRsp *pRsp) {
  if (NULL == pRsp) {
    return;
  }

  taosMemoryFreeClear(pRsp->pComment);
  taosMemoryFreeClear(pRsp->pSchemas);
  taosMemoryFreeClear(pRsp->pTags);
1966

D
dapan1121 已提交
1967 1968
  taosArrayDestroy(pRsp->pFuncs);
}
D
dapan1121 已提交
1969

S
Shengliang Guan 已提交
1970
int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
H
Hongze Cheng 已提交
1971 1972
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
1973 1974 1975 1976

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->numOfVgroups) < 0) return -1;
S
Shengliang Guan 已提交
1977 1978 1979 1980
  if (tEncodeI32(&encoder, pReq->numOfStables) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
1981
  if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992
  if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->minRows) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->precision) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->compression) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->replications) < 0) return -1;
S
Shengliang Guan 已提交
1993
  if (tEncodeI8(&encoder, pReq->strict) < 0) return -1;
S
Shengliang Guan 已提交
1994
  if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1;
X
Xiaoyu Wang 已提交
1995
  if (tEncodeI8(&encoder, pReq->schemaless) < 0) return -1;
S
Shengliang Guan 已提交
1996
  if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1;
S
Shengliang Guan 已提交
1997 1998 1999
  if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1;
  for (int32_t i = 0; i < pReq->numOfRetensions; ++i) {
    SRetention *pRetension = taosArrayGet(pReq->pRetensions, i);
C
Cary Xu 已提交
2000 2001
    if (tEncodeI64(&encoder, pRetension->freq) < 0) return -1;
    if (tEncodeI64(&encoder, pRetension->keep) < 0) return -1;
S
sma  
Shengliang Guan 已提交
2002 2003
    if (tEncodeI8(&encoder, pRetension->freqUnit) < 0) return -1;
    if (tEncodeI8(&encoder, pRetension->keepUnit) < 0) return -1;
S
Shengliang Guan 已提交
2004
  }
S
Shengliang Guan 已提交
2005 2006 2007
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2008
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2009 2010 2011 2012
  return tlen;
}

int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
H
Hongze Cheng 已提交
2013 2014
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2015 2016 2017 2018

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->numOfVgroups) < 0) return -1;
S
Shengliang Guan 已提交
2019 2020 2021 2022
  if (tDecodeI32(&decoder, &pReq->numOfStables) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
2023
  if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
  if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->minRows) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1;
S
Shengliang Guan 已提交
2035
  if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1;
S
Shengliang Guan 已提交
2036
  if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1;
X
Xiaoyu Wang 已提交
2037
  if (tDecodeI8(&decoder, &pReq->schemaless) < 0) return -1;
S
Shengliang Guan 已提交
2038
  if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1;
S
Shengliang Guan 已提交
2039 2040 2041 2042 2043 2044 2045 2046 2047
  if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1;
  pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention));
  if (pReq->pRetensions == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

  for (int32_t i = 0; i < pReq->numOfRetensions; ++i) {
    SRetention rentension = {0};
C
Cary Xu 已提交
2048 2049
    if (tDecodeI64(&decoder, &rentension.freq) < 0) return -1;
    if (tDecodeI64(&decoder, &rentension.keep) < 0) return -1;
S
sma  
Shengliang Guan 已提交
2050 2051
    if (tDecodeI8(&decoder, &rentension.freqUnit) < 0) return -1;
    if (tDecodeI8(&decoder, &rentension.keepUnit) < 0) return -1;
S
Shengliang Guan 已提交
2052 2053 2054 2055 2056 2057
    if (taosArrayPush(pReq->pRetensions, &rentension) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
  }

S
Shengliang Guan 已提交
2058 2059
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2060
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2061 2062 2063
  return 0;
}

S
Shengliang Guan 已提交
2064 2065 2066 2067 2068
void tFreeSCreateDbReq(SCreateDbReq *pReq) {
  taosArrayDestroy(pReq->pRetensions);
  pReq->pRetensions = NULL;
}

S
Shengliang Guan 已提交
2069
int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
H
Hongze Cheng 已提交
2070 2071
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2072 2073 2074

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
S
Shengliang Guan 已提交
2075 2076 2077
  if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
2078
  if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
2079
  if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
S
Shengliang Guan 已提交
2080 2081 2082 2083 2084
  if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1;
S
Shengliang Guan 已提交
2085
  if (tEncodeI8(&encoder, pReq->strict) < 0) return -1;
S
Shengliang Guan 已提交
2086
  if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1;
X
Xiaoyu Wang 已提交
2087
  if (tEncodeI8(&encoder, pReq->replications) < 0) return -1;
S
Shengliang Guan 已提交
2088 2089 2090
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2091
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2092 2093 2094 2095
  return tlen;
}

int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
H
Hongze Cheng 已提交
2096 2097
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2098 2099 2100

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
S
Shengliang Guan 已提交
2101 2102 2103
  if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
2104
  if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
2105
  if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
S
Shengliang Guan 已提交
2106 2107 2108 2109 2110
  if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1;
S
Shengliang Guan 已提交
2111
  if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1;
S
Shengliang Guan 已提交
2112
  if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1;
X
Xiaoyu Wang 已提交
2113
  if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1;
S
Shengliang Guan 已提交
2114 2115
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2116
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2117 2118 2119 2120
  return 0;
}

int32_t tSerializeSDropDbReq(void *buf, int32_t bufLen, SDropDbReq *pReq) {
H
Hongze Cheng 已提交
2121 2122
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2123 2124 2125 2126 2127 2128 2129

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->ignoreNotExists) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2130
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2131 2132 2133 2134
  return tlen;
}

int32_t tDeserializeSDropDbReq(void *buf, int32_t bufLen, SDropDbReq *pReq) {
H
Hongze Cheng 已提交
2135 2136
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2137 2138 2139 2140 2141 2142

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->ignoreNotExists) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2143
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2144 2145 2146 2147
  return 0;
}

int32_t tSerializeSDropDbRsp(void *buf, int32_t bufLen, SDropDbRsp *pRsp) {
H
Hongze Cheng 已提交
2148 2149
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2150 2151 2152

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->db) < 0) return -1;
L
Liu Jicong 已提交
2153
  if (tEncodeI64(&encoder, pRsp->uid) < 0) return -1;
S
Shengliang Guan 已提交
2154 2155 2156
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2157
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2158 2159 2160 2161
  return tlen;
}

int32_t tDeserializeSDropDbRsp(void *buf, int32_t bufLen, SDropDbRsp *pRsp) {
H
Hongze Cheng 已提交
2162 2163
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2164 2165 2166

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->db) < 0) return -1;
L
Liu Jicong 已提交
2167
  if (tDecodeI64(&decoder, &pRsp->uid) < 0) return -1;
S
Shengliang Guan 已提交
2168 2169
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2170
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2171 2172 2173 2174
  return 0;
}

int32_t tSerializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
H
Hongze Cheng 已提交
2175 2176
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2177 2178 2179

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
D
dapan1121 已提交
2180
  if (tEncodeI64(&encoder, pReq->dbId) < 0) return -1;
S
Shengliang Guan 已提交
2181
  if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1;
D
dapan1121 已提交
2182
  if (tEncodeI32(&encoder, pReq->numOfTable) < 0) return -1;
S
Shengliang Guan 已提交
2183 2184 2185
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2186
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2187 2188 2189 2190
  return tlen;
}

int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
H
Hongze Cheng 已提交
2191 2192
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2193 2194 2195

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
D
dapan1121 已提交
2196
  if (tDecodeI64(&decoder, &pReq->dbId) < 0) return -1;
S
Shengliang Guan 已提交
2197
  if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1;
D
dapan1121 已提交
2198
  if (tDecodeI32(&decoder, &pReq->numOfTable) < 0) return -1;
S
Shengliang Guan 已提交
2199 2200
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2201
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2202 2203 2204
  return 0;
}

L
Liu Jicong 已提交
2205
int32_t tSerializeSQnodeListReq(void *buf, int32_t bufLen, SQnodeListReq *pReq) {
H
Hongze Cheng 已提交
2206 2207
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
2208 2209 2210 2211 2212 2213

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->rowNum) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2214
  tEncoderClear(&encoder);
D
dapan1121 已提交
2215 2216 2217 2218
  return tlen;
}

int32_t tDeserializeSQnodeListReq(void *buf, int32_t bufLen, SQnodeListReq *pReq) {
H
Hongze Cheng 已提交
2219 2220
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
2221 2222 2223 2224 2225

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->rowNum) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2226
  tDecoderClear(&decoder);
D
dapan1121 已提交
2227 2228 2229
  return 0;
}

D
dapan1121 已提交
2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254
int32_t tSerializeSDnodeListReq(void *buf, int32_t bufLen, SDnodeListReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->rowNum) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSDnodeListReq(void *buf, int32_t bufLen, SDnodeListReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->rowNum) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

D
dapan1121 已提交
2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304
int32_t tSerializeSServerVerReq(void *buf, int32_t bufLen, SServerVerReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->useless) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSServerVerReq(void *buf, int32_t bufLen, SServerVerReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->useless) < 0) return -1;

  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

int32_t tSerializeSServerVerRsp(void *buf, int32_t bufLen, SServerVerRsp *pRsp) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->ver) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSServerVerRsp(void *buf, int32_t bufLen, SServerVerRsp *pRsp) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->ver) < 0) return -1;

  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

D
dapan1121 已提交
2305
int32_t tSerializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) {
H
Hongze Cheng 已提交
2306 2307
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
2308 2309

  if (tStartEncode(&encoder) < 0) return -1;
D
dapan1121 已提交
2310
  int32_t num = taosArrayGetSize(pRsp->qnodeList);
L
Liu Jicong 已提交
2311
  if (tEncodeI32(&encoder, num) < 0) return -1;
D
dapan1121 已提交
2312
  for (int32_t i = 0; i < num; ++i) {
D
dapan1121 已提交
2313 2314
    SQueryNodeLoad *pLoad = taosArrayGet(pRsp->qnodeList, i);
    if (tEncodeSQueryNodeLoad(&encoder, pLoad) < 0) return -1;
D
dapan1121 已提交
2315 2316 2317 2318
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2319
  tEncoderClear(&encoder);
D
dapan1121 已提交
2320 2321 2322 2323
  return tlen;
}

int32_t tDeserializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) {
H
Hongze Cheng 已提交
2324 2325
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
2326 2327 2328 2329

  if (tStartDecode(&decoder) < 0) return -1;
  int32_t num = 0;
  if (tDecodeI32(&decoder, &num) < 0) return -1;
D
dapan1121 已提交
2330 2331 2332
  if (NULL == pRsp->qnodeList) {
    pRsp->qnodeList = taosArrayInit(num, sizeof(SQueryNodeLoad));
    if (NULL == pRsp->qnodeList) return -1;
D
dapan 已提交
2333
  }
2334

D
dapan1121 已提交
2335
  for (int32_t i = 0; i < num; ++i) {
D
dapan1121 已提交
2336 2337 2338
    SQueryNodeLoad load = {0};
    if (tDecodeSQueryNodeLoad(&decoder, &load) < 0) return -1;
    taosArrayPush(pRsp->qnodeList, &load);
D
dapan1121 已提交
2339 2340 2341
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2342
  tDecoderClear(&decoder);
D
dapan1121 已提交
2343 2344 2345
  return 0;
}

D
dapan1121 已提交
2346
void tFreeSQnodeListRsp(SQnodeListRsp *pRsp) { taosArrayDestroy(pRsp->qnodeList); }
D
dapan1121 已提交
2347

D
dapan1121 已提交
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
int32_t tSerializeSDnodeListRsp(void *buf, int32_t bufLen, SDnodeListRsp *pRsp) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  int32_t num = taosArrayGetSize(pRsp->dnodeList);
  if (tEncodeI32(&encoder, num) < 0) return -1;
  for (int32_t i = 0; i < num; ++i) {
    SEpSet *pEpSet = taosArrayGet(pRsp->dnodeList, i);
    if (tEncodeSEpSet(&encoder, pEpSet) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSDnodeListRsp(void *buf, int32_t bufLen, SDnodeListRsp *pRsp) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  int32_t num = 0;
  if (tDecodeI32(&decoder, &num) < 0) return -1;
  if (NULL == pRsp->dnodeList) {
    pRsp->dnodeList = taosArrayInit(num, sizeof(SEpSet));
    if (NULL == pRsp->dnodeList) return -1;
  }

  for (int32_t i = 0; i < num; ++i) {
    SEpSet epSet = {0};
    if (tDecodeSEpSet(&decoder, &epSet) < 0) return -1;
    taosArrayPush(pRsp->dnodeList, &epSet);
  }
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

void tFreeSDnodeListRsp(SDnodeListRsp *pRsp) { taosArrayDestroy(pRsp->dnodeList); }

S
Shengliang Guan 已提交
2391
int32_t tSerializeSCompactDbReq(void *buf, int32_t bufLen, SCompactDbReq *pReq) {
H
Hongze Cheng 已提交
2392 2393
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2394 2395 2396 2397 2398 2399

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2400
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2401 2402 2403
  return tlen;
}

S
Shengliang Guan 已提交
2404
int32_t tDeserializeSCompactDbReq(void *buf, int32_t bufLen, SCompactDbReq *pReq) {
H
Hongze Cheng 已提交
2405 2406
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2407 2408 2409 2410 2411

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2412
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2413
  return 0;
S
Shengliang Guan 已提交
2414 2415
}

H
Hongze Cheng 已提交
2416
int32_t tSerializeSUseDbRspImp(SEncoder *pEncoder, const SUseDbRsp *pRsp) {
S
Shengliang Guan 已提交
2417
  if (tEncodeCStr(pEncoder, pRsp->db) < 0) return -1;
L
Liu Jicong 已提交
2418
  if (tEncodeI64(pEncoder, pRsp->uid) < 0) return -1;
S
Shengliang Guan 已提交
2419 2420 2421 2422 2423 2424 2425 2426 2427
  if (tEncodeI32(pEncoder, pRsp->vgVersion) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->vgNum) < 0) return -1;
  if (tEncodeI8(pEncoder, pRsp->hashMethod) < 0) return -1;

  for (int32_t i = 0; i < pRsp->vgNum; ++i) {
    SVgroupInfo *pVgInfo = taosArrayGet(pRsp->pVgroupInfos, i);
    if (tEncodeI32(pEncoder, pVgInfo->vgId) < 0) return -1;
    if (tEncodeU32(pEncoder, pVgInfo->hashBegin) < 0) return -1;
    if (tEncodeU32(pEncoder, pVgInfo->hashEnd) < 0) return -1;
L
Liu Jicong 已提交
2428
    if (tEncodeSEpSet(pEncoder, &pVgInfo->epSet) < 0) return -1;
D
dapan1121 已提交
2429
    if (tEncodeI32(pEncoder, pVgInfo->numOfTable) < 0) return -1;
S
Shengliang Guan 已提交
2430 2431 2432 2433 2434
  }

  return 0;
}

L
Liu Jicong 已提交
2435
int32_t tSerializeSUseDbRsp(void *buf, int32_t bufLen, const SUseDbRsp *pRsp) {
H
Hongze Cheng 已提交
2436 2437
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2438 2439 2440 2441 2442 2443

  if (tStartEncode(&encoder) < 0) return -1;
  if (tSerializeSUseDbRspImp(&encoder, pRsp) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2444
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2445 2446 2447 2448
  return tlen;
}

int32_t tSerializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
2449 2450
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462

  if (tStartEncode(&encoder) < 0) return -1;

  int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
  if (tEncodeI32(&encoder, numOfBatch) < 0) return -1;
  for (int32_t i = 0; i < numOfBatch; ++i) {
    SUseDbRsp *pUsedbRsp = taosArrayGet(pRsp->pArray, i);
    if (tSerializeSUseDbRspImp(&encoder, pUsedbRsp) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2463
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2464 2465 2466
  return tlen;
}

H
Hongze Cheng 已提交
2467
int32_t tDeserializeSUseDbRspImp(SDecoder *pDecoder, SUseDbRsp *pRsp) {
S
Shengliang Guan 已提交
2468
  if (tDecodeCStrTo(pDecoder, pRsp->db) < 0) return -1;
L
Liu Jicong 已提交
2469
  if (tDecodeI64(pDecoder, &pRsp->uid) < 0) return -1;
S
Shengliang Guan 已提交
2470 2471 2472 2473
  if (tDecodeI32(pDecoder, &pRsp->vgVersion) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->vgNum) < 0) return -1;
  if (tDecodeI8(pDecoder, &pRsp->hashMethod) < 0) return -1;

D
dapan1121 已提交
2474 2475 2476
  if (pRsp->vgNum <= 0) {
    return 0;
  }
L
Liu Jicong 已提交
2477

S
Shengliang Guan 已提交
2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488
  pRsp->pVgroupInfos = taosArrayInit(pRsp->vgNum, sizeof(SVgroupInfo));
  if (pRsp->pVgroupInfos == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

  for (int32_t i = 0; i < pRsp->vgNum; ++i) {
    SVgroupInfo vgInfo = {0};
    if (tDecodeI32(pDecoder, &vgInfo.vgId) < 0) return -1;
    if (tDecodeU32(pDecoder, &vgInfo.hashBegin) < 0) return -1;
    if (tDecodeU32(pDecoder, &vgInfo.hashEnd) < 0) return -1;
L
Liu Jicong 已提交
2489
    if (tDecodeSEpSet(pDecoder, &vgInfo.epSet) < 0) return -1;
D
dapan1121 已提交
2490
    if (tDecodeI32(pDecoder, &vgInfo.numOfTable) < 0) return -1;
S
Shengliang Guan 已提交
2491 2492 2493 2494 2495 2496 2497
    taosArrayPush(pRsp->pVgroupInfos, &vgInfo);
  }

  return 0;
}

int32_t tDeserializeSUseDbRsp(void *buf, int32_t bufLen, SUseDbRsp *pRsp) {
H
Hongze Cheng 已提交
2498 2499
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2500 2501 2502 2503 2504

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDeserializeSUseDbRspImp(&decoder, pRsp) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2505
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2506 2507 2508 2509
  return 0;
}

int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
2510 2511
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2512 2513 2514 2515 2516 2517

  if (tStartDecode(&decoder) < 0) return -1;

  int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
  if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1;

D
dapan1121 已提交
2518
  pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbRsp));
S
Shengliang Guan 已提交
2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530
  if (pRsp->pArray == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

  for (int32_t i = 0; i < numOfBatch; ++i) {
    SUseDbRsp usedbRsp = {0};
    if (tDeserializeSUseDbRspImp(&decoder, &usedbRsp) < 0) return -1;
    taosArrayPush(pRsp->pArray, &usedbRsp);
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2531
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544
  return 0;
}

void tFreeSUsedbRsp(SUseDbRsp *pRsp) { taosArrayDestroy(pRsp->pVgroupInfos); }

void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) {
  int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
  for (int32_t i = 0; i < numOfBatch; ++i) {
    SUseDbRsp *pUsedbRsp = taosArrayGet(pRsp->pArray, i);
    tFreeSUsedbRsp(pUsedbRsp);
  }

  taosArrayDestroy(pRsp->pArray);
S
Shengliang Guan 已提交
2545 2546
}

H
Hongze Cheng 已提交
2547
int32_t tSerializeSUserAuthBatchRsp(void *buf, int32_t bufLen, SUserAuthBatchRsp *pRsp) {
H
Hongze Cheng 已提交
2548 2549
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan 已提交
2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561

  if (tStartEncode(&encoder) < 0) return -1;

  int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
  if (tEncodeI32(&encoder, numOfBatch) < 0) return -1;
  for (int32_t i = 0; i < numOfBatch; ++i) {
    SGetUserAuthRsp *pUserAuthRsp = taosArrayGet(pRsp->pArray, i);
    if (tSerializeSGetUserAuthRspImpl(&encoder, pUserAuthRsp) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2562
  tEncoderClear(&encoder);
D
dapan 已提交
2563 2564 2565
  return tlen;
}

H
Hongze Cheng 已提交
2566
int32_t tDeserializeSUserAuthBatchRsp(void *buf, int32_t bufLen, SUserAuthBatchRsp *pRsp) {
H
Hongze Cheng 已提交
2567 2568
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan 已提交
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587

  if (tStartDecode(&decoder) < 0) return -1;

  int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
  if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1;

  pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SGetUserAuthRsp));
  if (pRsp->pArray == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

  for (int32_t i = 0; i < numOfBatch; ++i) {
    SGetUserAuthRsp rsp = {0};
    if (tDeserializeSGetUserAuthRspImpl(&decoder, &rsp) < 0) return -1;
    taosArrayPush(pRsp->pArray, &rsp);
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2588
  tDecoderClear(&decoder);
D
dapan 已提交
2589 2590 2591
  return 0;
}

H
Hongze Cheng 已提交
2592
void tFreeSUserAuthBatchRsp(SUserAuthBatchRsp *pRsp) {
D
dapan 已提交
2593 2594 2595 2596 2597 2598 2599 2600 2601
  int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
  for (int32_t i = 0; i < numOfBatch; ++i) {
    SGetUserAuthRsp *pUserAuthRsp = taosArrayGet(pRsp->pArray, i);
    tFreeSGetUserAuthRsp(pUserAuthRsp);
  }

  taosArrayDestroy(pRsp->pArray);
}

S
Shengliang Guan 已提交
2602
int32_t tSerializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) {
H
Hongze Cheng 已提交
2603 2604
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
2605 2606 2607 2608 2609 2610

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2611
  tEncoderClear(&encoder);
D
dapan1121 已提交
2612 2613 2614
  return tlen;
}

S
Shengliang Guan 已提交
2615
int32_t tDeserializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) {
H
Hongze Cheng 已提交
2616 2617
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
2618 2619 2620 2621 2622

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2623
  tDecoderClear(&decoder);
D
dapan1121 已提交
2624 2625 2626
  return 0;
}

S
Shengliang Guan 已提交
2627
int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) {
H
Hongze Cheng 已提交
2628 2629
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
2630 2631 2632

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->numOfVgroups) < 0) return -1;
S
Shengliang Guan 已提交
2633 2634 2635 2636
  if (tEncodeI32(&encoder, pRsp->numOfStables) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->buffer) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->pageSize) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->pages) < 0) return -1;
D
dapan1121 已提交
2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647
  if (tEncodeI32(&encoder, pRsp->daysPerFile) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->daysToKeep0) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->daysToKeep1) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->daysToKeep2) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->minRows) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->maxRows) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->fsyncPeriod) < 0) return -1;
  if (tEncodeI8(&encoder, pRsp->walLevel) < 0) return -1;
  if (tEncodeI8(&encoder, pRsp->precision) < 0) return -1;
  if (tEncodeI8(&encoder, pRsp->compression) < 0) return -1;
  if (tEncodeI8(&encoder, pRsp->replications) < 0) return -1;
S
Shengliang Guan 已提交
2648
  if (tEncodeI8(&encoder, pRsp->strict) < 0) return -1;
D
dapan1121 已提交
2649
  if (tEncodeI8(&encoder, pRsp->cacheLastRow) < 0) return -1;
2650 2651 2652
  if (tEncodeI32(&encoder, pRsp->numOfRetensions) < 0) return -1;
  for (int32_t i = 0; i < pRsp->numOfRetensions; ++i) {
    SRetention *pRetension = taosArrayGet(pRsp->pRetensions, i);
C
Cary Xu 已提交
2653 2654
    if (tEncodeI64(&encoder, pRetension->freq) < 0) return -1;
    if (tEncodeI64(&encoder, pRetension->keep) < 0) return -1;
2655 2656 2657
    if (tEncodeI8(&encoder, pRetension->freqUnit) < 0) return -1;
    if (tEncodeI8(&encoder, pRetension->keepUnit) < 0) return -1;
  }
wmmhello's avatar
wmmhello 已提交
2658
  if (tEncodeI8(&encoder, pRsp->schemaless) < 0) return -1;
D
dapan1121 已提交
2659 2660 2661
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2662
  tEncoderClear(&encoder);
D
dapan1121 已提交
2663 2664 2665
  return tlen;
}

S
Shengliang Guan 已提交
2666
int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) {
H
Hongze Cheng 已提交
2667 2668
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
2669 2670 2671

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->numOfVgroups) < 0) return -1;
S
Shengliang Guan 已提交
2672 2673 2674 2675
  if (tDecodeI32(&decoder, &pRsp->numOfStables) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->buffer) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->pageSize) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->pages) < 0) return -1;
D
dapan1121 已提交
2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686
  if (tDecodeI32(&decoder, &pRsp->daysPerFile) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->daysToKeep0) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->daysToKeep1) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->daysToKeep2) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->minRows) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->maxRows) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->fsyncPeriod) < 0) return -1;
  if (tDecodeI8(&decoder, &pRsp->walLevel) < 0) return -1;
  if (tDecodeI8(&decoder, &pRsp->precision) < 0) return -1;
  if (tDecodeI8(&decoder, &pRsp->compression) < 0) return -1;
  if (tDecodeI8(&decoder, &pRsp->replications) < 0) return -1;
S
Shengliang Guan 已提交
2687
  if (tDecodeI8(&decoder, &pRsp->strict) < 0) return -1;
D
dapan1121 已提交
2688
  if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1;
2689
  if (tDecodeI32(&decoder, &pRsp->numOfRetensions) < 0) return -1;
2690 2691 2692 2693 2694 2695
  if (pRsp->numOfRetensions > 0) {
    pRsp->pRetensions = taosArrayInit(pRsp->numOfRetensions, sizeof(SRetention));
    if (pRsp->pRetensions == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
2696
  }
D
dapan1121 已提交
2697

2698 2699
  for (int32_t i = 0; i < pRsp->numOfRetensions; ++i) {
    SRetention rentension = {0};
C
Cary Xu 已提交
2700 2701
    if (tDecodeI64(&decoder, &rentension.freq) < 0) return -1;
    if (tDecodeI64(&decoder, &rentension.keep) < 0) return -1;
2702 2703 2704 2705 2706 2707 2708
    if (tDecodeI8(&decoder, &rentension.freqUnit) < 0) return -1;
    if (tDecodeI8(&decoder, &rentension.keepUnit) < 0) return -1;
    if (taosArrayPush(pRsp->pRetensions, &rentension) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
  }
wmmhello's avatar
wmmhello 已提交
2709
  if (tDecodeI8(&decoder, &pRsp->schemaless) < 0) return -1;
D
dapan1121 已提交
2710 2711
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2712
  tDecoderClear(&decoder);
D
dapan1121 已提交
2713 2714 2715
  return 0;
}

S
Shengliang Guan 已提交
2716
int32_t tSerializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) {
H
Hongze Cheng 已提交
2717 2718
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
2719 2720 2721 2722 2723 2724

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->indexFName) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2725
  tEncoderClear(&encoder);
D
dapan1121 已提交
2726 2727 2728
  return tlen;
}

S
Shengliang Guan 已提交
2729
int32_t tDeserializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) {
H
Hongze Cheng 已提交
2730 2731
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
2732 2733 2734 2735 2736

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->indexFName) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2737
  tDecoderClear(&decoder);
D
dapan1121 已提交
2738 2739 2740
  return 0;
}

S
Shengliang Guan 已提交
2741
int32_t tSerializeSUserIndexRsp(void *buf, int32_t bufLen, const SUserIndexRsp *pRsp) {
H
Hongze Cheng 已提交
2742 2743
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
2744 2745 2746 2747 2748 2749 2750 2751 2752 2753

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->dbFName) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->tblFName) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->colName) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->indexType) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->indexExts) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2754
  tEncoderClear(&encoder);
D
dapan1121 已提交
2755 2756 2757
  return tlen;
}

S
Shengliang Guan 已提交
2758
int32_t tDeserializeSUserIndexRsp(void *buf, int32_t bufLen, SUserIndexRsp *pRsp) {
H
Hongze Cheng 已提交
2759 2760
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
2761 2762 2763 2764 2765 2766 2767 2768 2769

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->dbFName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->tblFName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->colName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->indexType) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->indexExts) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
2770
  tDecoderClear(&decoder);
D
dapan1121 已提交
2771 2772 2773
  return 0;
}

D
dapan1121 已提交
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798
int32_t tSerializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->tbFName) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->tbFName) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

C
Cary Xu 已提交
2799
int32_t tSerializeSTableIndexInfo(SEncoder *pEncoder, STableIndexInfo *pInfo) {
D
dapan1121 已提交
2800 2801 2802 2803 2804 2805 2806
  if (tEncodeI8(pEncoder, pInfo->intervalUnit) < 0) return -1;
  if (tEncodeI8(pEncoder, pInfo->slidingUnit) < 0) return -1;
  if (tEncodeI64(pEncoder, pInfo->interval) < 0) return -1;
  if (tEncodeI64(pEncoder, pInfo->offset) < 0) return -1;
  if (tEncodeI64(pEncoder, pInfo->sliding) < 0) return -1;
  if (tEncodeI64(pEncoder, pInfo->dstTbUid) < 0) return -1;
  if (tEncodeI32(pEncoder, pInfo->dstVgId) < 0) return -1;
D
dapan1121 已提交
2807
  if (tEncodeSEpSet(pEncoder, &pInfo->epSet) < 0) return -1;
D
dapan1121 已提交
2808 2809 2810 2811 2812 2813 2814 2815 2816
  if (tEncodeCStr(pEncoder, pInfo->expr) < 0) return -1;
  return 0;
}

int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp *pRsp) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
D
dapan1121 已提交
2817 2818
  if (tEncodeCStr(&encoder, pRsp->tbName) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->dbFName) < 0) return -1;
D
dapan1121 已提交
2819
  if (tEncodeU64(&encoder, pRsp->suid) < 0) return -1;
D
dapan1121 已提交
2820
  if (tEncodeI32(&encoder, pRsp->version) < 0) return -1;
D
dapan1121 已提交
2821 2822 2823 2824
  int32_t num = taosArrayGetSize(pRsp->pIndex);
  if (tEncodeI32(&encoder, num) < 0) return -1;
  if (num > 0) {
    for (int32_t i = 0; i < num; ++i) {
C
Cary Xu 已提交
2825
      STableIndexInfo *pInfo = (STableIndexInfo *)taosArrayGet(pRsp->pIndex, i);
D
dapan1121 已提交
2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843
      if (tSerializeSTableIndexInfo(&encoder, pInfo) < 0) return -1;
    }
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSTableIndexInfo(SDecoder *pDecoder, STableIndexInfo *pInfo) {
  if (tDecodeI8(pDecoder, &pInfo->intervalUnit) < 0) return -1;
  if (tDecodeI8(pDecoder, &pInfo->slidingUnit) < 0) return -1;
  if (tDecodeI64(pDecoder, &pInfo->interval) < 0) return -1;
  if (tDecodeI64(pDecoder, &pInfo->offset) < 0) return -1;
  if (tDecodeI64(pDecoder, &pInfo->sliding) < 0) return -1;
  if (tDecodeI64(pDecoder, &pInfo->dstTbUid) < 0) return -1;
  if (tDecodeI32(pDecoder, &pInfo->dstVgId) < 0) return -1;
D
dapan1121 已提交
2844
  if (tDecodeSEpSet(pDecoder, &pInfo->epSet) < 0) return -1;
D
dapan1121 已提交
2845 2846 2847 2848 2849 2850 2851 2852 2853 2854
  if (tDecodeCStrAlloc(pDecoder, &pInfo->expr) < 0) return -1;

  return 0;
}

int32_t tDeserializeSTableIndexRsp(void *buf, int32_t bufLen, STableIndexRsp *pRsp) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
D
dapan1121 已提交
2855 2856
  if (tDecodeCStrTo(&decoder, pRsp->tbName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->dbFName) < 0) return -1;
D
dapan1121 已提交
2857
  if (tDecodeU64(&decoder, &pRsp->suid) < 0) return -1;
D
dapan1121 已提交
2858
  if (tDecodeI32(&decoder, &pRsp->version) < 0) return -1;
D
dapan1121 已提交
2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
  int32_t num = 0;
  if (tDecodeI32(&decoder, &num) < 0) return -1;
  if (num > 0) {
    pRsp->pIndex = taosArrayInit(num, sizeof(STableIndexInfo));
    if (NULL == pRsp->pIndex) return -1;
    STableIndexInfo info;
    for (int32_t i = 0; i < num; ++i) {
      if (tDeserializeSTableIndexInfo(&decoder, &info) < 0) return -1;
      if (NULL == taosArrayPush(pRsp->pIndex, &info)) {
        taosMemoryFree(info.expr);
        return -1;
      }
    }
  }
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

2879
void tFreeSTableIndexInfo(void *info) {
D
dapan1121 已提交
2880 2881 2882 2883
  if (NULL == info) {
    return;
  }

2884
  STableIndexInfo *pInfo = (STableIndexInfo *)info;
D
dapan1121 已提交
2885 2886 2887

  taosMemoryFree(pInfo->expr);
}
D
dapan1121 已提交
2888

X
Xiaoyu Wang 已提交
2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913
int32_t tSerializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->useless) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->useless) < 0) return -1;

  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

H
Hongze Cheng 已提交
2914
int32_t tEncodeSVariablesInfo(SEncoder *pEncoder, SVariablesInfo *pInfo) {
D
dapan1121 已提交
2915 2916 2917 2918 2919
  if (tEncodeCStr(pEncoder, pInfo->name) < 0) return -1;
  if (tEncodeCStr(pEncoder, pInfo->value) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
2920
int32_t tDecodeSVariablesInfo(SDecoder *pDecoder, SVariablesInfo *pInfo) {
D
dapan1121 已提交
2921 2922 2923 2924 2925
  if (tDecodeCStrTo(pDecoder, pInfo->name) < 0) return -1;
  if (tDecodeCStrTo(pDecoder, pInfo->value) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
2926
int32_t tSerializeSShowVariablesRsp(void *buf, int32_t bufLen, SShowVariablesRsp *pRsp) {
D
dapan1121 已提交
2927 2928 2929 2930 2931 2932 2933
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  int32_t varNum = taosArrayGetSize(pRsp->variables);
  if (tEncodeI32(&encoder, varNum) < 0) return -1;
  for (int32_t i = 0; i < varNum; ++i) {
H
Hongze Cheng 已提交
2934
    SVariablesInfo *pInfo = taosArrayGet(pRsp->variables, i);
D
dapan1121 已提交
2935 2936 2937 2938 2939 2940 2941 2942 2943
    if (tEncodeSVariablesInfo(&encoder, pInfo) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

H
Hongze Cheng 已提交
2944
int32_t tDeserializeSShowVariablesRsp(void *buf, int32_t bufLen, SShowVariablesRsp *pRsp) {
D
dapan1121 已提交
2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  int32_t varNum = 0;
  if (tDecodeI32(&decoder, &varNum) < 0) return -1;
  if (varNum > 0) {
    pRsp->variables = taosArrayInit(varNum, sizeof(SVariablesInfo));
    if (NULL == pRsp->variables) return -1;
    for (int32_t i = 0; i < varNum; ++i) {
      SVariablesInfo info = {0};
      if (tDecodeSVariablesInfo(&decoder, &info) < 0) return -1;
      if (NULL == taosArrayPush(pRsp->variables, &info)) return -1;
    }
  }

  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

H
Hongze Cheng 已提交
2966
void tFreeSShowVariablesRsp(SShowVariablesRsp *pRsp) {
D
dapan1121 已提交
2967 2968 2969
  if (NULL == pRsp) {
    return;
  }
H
Hongze Cheng 已提交
2970

D
dapan1121 已提交
2971 2972 2973
  taosArrayDestroy(pRsp->variables);
}

S
Shengliang Guan 已提交
2974
int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
H
Hongze Cheng 已提交
2975 2976
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
2977 2978 2979 2980 2981 2982

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->type) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->payloadLen) < 0) return -1;
  if (pReq->payloadLen > 0) {
S
Shengliang Guan 已提交
2983
    if (tEncodeBinary(&encoder, pReq->payload, pReq->payloadLen) < 0) return -1;
S
Shengliang Guan 已提交
2984 2985 2986 2987
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
2988
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
2989 2990 2991 2992
  return tlen;
}

int32_t tDeserializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
H
Hongze Cheng 已提交
2993 2994
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
2995 2996 2997 2998 2999 3000

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->type) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->payloadLen) < 0) return -1;
  if (pReq->payloadLen > 0) {
wafwerar's avatar
wafwerar 已提交
3001
    pReq->payload = taosMemoryMalloc(pReq->payloadLen);
S
Shengliang Guan 已提交
3002 3003 3004 3005 3006
    if (pReq->payload == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->payload) < 0) return -1;
  }

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3007
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3008 3009 3010
  return 0;
}

wafwerar's avatar
wafwerar 已提交
3011
void tFreeSShowReq(SShowReq *pReq) { taosMemoryFreeClear(pReq->payload); }
3012 3013

int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq *pReq) {
H
Hongze Cheng 已提交
3014 3015
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
3016 3017 3018

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->showId) < 0) return -1;
H
Haojun Liao 已提交
3019 3020
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1;
3021
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
3022 3023 3024
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3025
  tEncoderClear(&encoder);
3026 3027 3028 3029
  return tlen;
}

int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq *pReq) {
H
Hongze Cheng 已提交
3030 3031
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
3032 3033 3034

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1;
H
Haojun Liao 已提交
3035 3036
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1;
3037 3038
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;

3039
  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3040
  tDecoderClear(&decoder);
3041 3042
  return 0;
}
S
Shengliang Guan 已提交
3043

H
Hongze Cheng 已提交
3044
static int32_t tEncodeSTableMetaRsp(SEncoder *pEncoder, STableMetaRsp *pRsp) {
S
Shengliang Guan 已提交
3045 3046 3047
  if (tEncodeCStr(pEncoder, pRsp->tbName) < 0) return -1;
  if (tEncodeCStr(pEncoder, pRsp->stbName) < 0) return -1;
  if (tEncodeCStr(pEncoder, pRsp->dbFName) < 0) return -1;
L
Liu Jicong 已提交
3048
  if (tEncodeI64(pEncoder, pRsp->dbId) < 0) return -1;
S
Shengliang Guan 已提交
3049 3050 3051 3052 3053 3054
  if (tEncodeI32(pEncoder, pRsp->numOfTags) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->numOfColumns) < 0) return -1;
  if (tEncodeI8(pEncoder, pRsp->precision) < 0) return -1;
  if (tEncodeI8(pEncoder, pRsp->tableType) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->sversion) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->tversion) < 0) return -1;
L
Liu Jicong 已提交
3055 3056
  if (tEncodeU64(pEncoder, pRsp->suid) < 0) return -1;
  if (tEncodeU64(pEncoder, pRsp->tuid) < 0) return -1;
S
Shengliang Guan 已提交
3057 3058 3059 3060 3061 3062 3063 3064 3065
  if (tEncodeI32(pEncoder, pRsp->vgId) < 0) return -1;
  for (int32_t i = 0; i < pRsp->numOfColumns + pRsp->numOfTags; ++i) {
    SSchema *pSchema = &pRsp->pSchemas[i];
    if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1;
  }

  return 0;
}

H
Hongze Cheng 已提交
3066
static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
S
Shengliang Guan 已提交
3067 3068 3069
  if (tDecodeCStrTo(pDecoder, pRsp->tbName) < 0) return -1;
  if (tDecodeCStrTo(pDecoder, pRsp->stbName) < 0) return -1;
  if (tDecodeCStrTo(pDecoder, pRsp->dbFName) < 0) return -1;
L
Liu Jicong 已提交
3070
  if (tDecodeI64(pDecoder, &pRsp->dbId) < 0) return -1;
S
Shengliang Guan 已提交
3071 3072 3073 3074 3075 3076
  if (tDecodeI32(pDecoder, &pRsp->numOfTags) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->numOfColumns) < 0) return -1;
  if (tDecodeI8(pDecoder, &pRsp->precision) < 0) return -1;
  if (tDecodeI8(pDecoder, &pRsp->tableType) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->sversion) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->tversion) < 0) return -1;
L
Liu Jicong 已提交
3077 3078
  if (tDecodeU64(pDecoder, &pRsp->suid) < 0) return -1;
  if (tDecodeU64(pDecoder, &pRsp->tuid) < 0) return -1;
S
Shengliang Guan 已提交
3079 3080 3081
  if (tDecodeI32(pDecoder, &pRsp->vgId) < 0) return -1;

  int32_t totalCols = pRsp->numOfTags + pRsp->numOfColumns;
wafwerar's avatar
wafwerar 已提交
3082
  pRsp->pSchemas = taosMemoryMalloc(sizeof(SSchema) * totalCols);
S
Shengliang Guan 已提交
3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093
  if (pRsp->pSchemas == NULL) return -1;

  for (int32_t i = 0; i < totalCols; ++i) {
    SSchema *pSchema = &pRsp->pSchemas[i];
    if (tDecodeSSchema(pDecoder, pSchema) < 0) return -1;
  }

  return 0;
}

int32_t tSerializeSTableMetaRsp(void *buf, int32_t bufLen, STableMetaRsp *pRsp) {
H
Hongze Cheng 已提交
3094 3095
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3096 3097 3098 3099 3100 3101

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSTableMetaRsp(&encoder, pRsp) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3102
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3103 3104 3105
  return tlen;
}

D
dapan1121 已提交
3106
int32_t tSerializeSSTbHbRsp(void *buf, int32_t bufLen, SSTbHbRsp *pRsp) {
H
Hongze Cheng 已提交
3107 3108
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3109 3110 3111

  if (tStartEncode(&encoder) < 0) return -1;

D
dapan1121 已提交
3112 3113 3114 3115
  int32_t numOfMeta = taosArrayGetSize(pRsp->pMetaRsp);
  if (tEncodeI32(&encoder, numOfMeta) < 0) return -1;
  for (int32_t i = 0; i < numOfMeta; ++i) {
    STableMetaRsp *pMetaRsp = taosArrayGet(pRsp->pMetaRsp, i);
S
Shengliang Guan 已提交
3116 3117
    if (tEncodeSTableMetaRsp(&encoder, pMetaRsp) < 0) return -1;
  }
D
dapan1121 已提交
3118 3119

  int32_t numOfIndex = taosArrayGetSize(pRsp->pIndexRsp);
C
Cary Xu 已提交
3120
  if (tEncodeI32(&encoder, numOfIndex) < 0) return -1;
D
dapan1121 已提交
3121
  for (int32_t i = 0; i < numOfIndex; ++i) {
D
dapan1121 已提交
3122 3123 3124 3125 3126 3127 3128
    STableIndexRsp *pIndexRsp = taosArrayGet(pRsp->pIndexRsp, i);
    if (tEncodeCStr(&encoder, pIndexRsp->tbName) < 0) return -1;
    if (tEncodeCStr(&encoder, pIndexRsp->dbFName) < 0) return -1;
    if (tEncodeU64(&encoder, pIndexRsp->suid) < 0) return -1;
    if (tEncodeI32(&encoder, pIndexRsp->version) < 0) return -1;
    int32_t num = taosArrayGetSize(pIndexRsp->pIndex);
    if (tEncodeI32(&encoder, num) < 0) return -1;
D
dapan1121 已提交
3129 3130 3131 3132
    for (int32_t i = 0; i < num; ++i) {
      STableIndexInfo *pInfo = (STableIndexInfo *)taosArrayGet(pIndexRsp->pIndex, i);
      if (tSerializeSTableIndexInfo(&encoder, pInfo) < 0) return -1;
    }
D
dapan1121 已提交
3133 3134
  }

S
Shengliang Guan 已提交
3135 3136 3137
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3138
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3139 3140 3141 3142
  return tlen;
}

int32_t tDeserializeSTableMetaRsp(void *buf, int32_t bufLen, STableMetaRsp *pRsp) {
H
Hongze Cheng 已提交
3143 3144
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3145 3146 3147 3148 3149

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSTableMetaRsp(&decoder, pRsp) < 0) return -1;

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3150
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3151 3152 3153
  return 0;
}

D
dapan1121 已提交
3154
int32_t tDeserializeSSTbHbRsp(void *buf, int32_t bufLen, SSTbHbRsp *pRsp) {
H
Hongze Cheng 已提交
3155 3156
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3157 3158 3159

  if (tStartDecode(&decoder) < 0) return -1;

D
dapan1121 已提交
3160
  int32_t numOfMeta = 0;
D
dapan1121 已提交
3161 3162 3163
  if (tDecodeI32(&decoder, &numOfMeta) < 0) return -1;
  pRsp->pMetaRsp = taosArrayInit(numOfMeta, sizeof(STableMetaRsp));
  if (pRsp->pMetaRsp == NULL) {
S
Shengliang Guan 已提交
3164 3165 3166 3167
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

D
dapan1121 已提交
3168
  for (int32_t i = 0; i < numOfMeta; ++i) {
S
Shengliang Guan 已提交
3169 3170
    STableMetaRsp tableMetaRsp = {0};
    if (tDecodeSTableMetaRsp(&decoder, &tableMetaRsp) < 0) return -1;
D
dapan1121 已提交
3171 3172 3173
    taosArrayPush(pRsp->pMetaRsp, &tableMetaRsp);
  }

D
dapan1121 已提交
3174
  int32_t numOfIndex = 0;
D
dapan1121 已提交
3175 3176 3177 3178 3179 3180
  if (tDecodeI32(&decoder, &numOfIndex) < 0) return -1;

  pRsp->pIndexRsp = taosArrayInit(numOfIndex, sizeof(STableIndexRsp));
  if (pRsp->pIndexRsp == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
S
Shengliang Guan 已提交
3181
  }
D
dapan1121 已提交
3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203

  for (int32_t i = 0; i < numOfIndex; ++i) {
    STableIndexRsp tableIndexRsp = {0};
    if (tDecodeCStrTo(&decoder, tableIndexRsp.tbName) < 0) return -1;
    if (tDecodeCStrTo(&decoder, tableIndexRsp.dbFName) < 0) return -1;
    if (tDecodeU64(&decoder, &tableIndexRsp.suid) < 0) return -1;
    if (tDecodeI32(&decoder, &tableIndexRsp.version) < 0) return -1;
    int32_t num = 0;
    if (tDecodeI32(&decoder, &num) < 0) return -1;
    if (num > 0) {
      tableIndexRsp.pIndex = taosArrayInit(num, sizeof(STableIndexInfo));
      if (NULL == tableIndexRsp.pIndex) return -1;
      STableIndexInfo info;
      for (int32_t i = 0; i < num; ++i) {
        if (tDeserializeSTableIndexInfo(&decoder, &info) < 0) return -1;
        if (NULL == taosArrayPush(tableIndexRsp.pIndex, &info)) {
          taosMemoryFree(info.expr);
          return -1;
        }
      }
    }
    taosArrayPush(pRsp->pIndexRsp, &tableIndexRsp);
S
Shengliang Guan 已提交
3204
  }
C
Cary Xu 已提交
3205

S
Shengliang Guan 已提交
3206 3207
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3208
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3209 3210 3211
  return 0;
}

wafwerar's avatar
wafwerar 已提交
3212
void tFreeSTableMetaRsp(STableMetaRsp *pRsp) { taosMemoryFreeClear(pRsp->pSchemas); }
S
Shengliang Guan 已提交
3213

D
dapan1121 已提交
3214 3215 3216 3217 3218 3219 3220 3221 3222 3223
void tFreeSTableIndexRsp(void *info) {
  if (NULL == info) {
    return;
  }

  STableIndexRsp *pInfo = (STableIndexRsp *)info;

  taosArrayDestroyEx(pInfo->pIndex, tFreeSTableIndexInfo);
}

D
dapan1121 已提交
3224
void tFreeSSTbHbRsp(SSTbHbRsp *pRsp) {
D
dapan1121 已提交
3225 3226 3227
  int32_t numOfMeta = taosArrayGetSize(pRsp->pMetaRsp);
  for (int32_t i = 0; i < numOfMeta; ++i) {
    STableMetaRsp *pMetaRsp = taosArrayGet(pRsp->pMetaRsp, i);
S
Shengliang Guan 已提交
3228 3229 3230
    tFreeSTableMetaRsp(pMetaRsp);
  }

D
dapan1121 已提交
3231 3232 3233 3234 3235 3236 3237 3238 3239
  taosArrayDestroy(pRsp->pMetaRsp);

  int32_t numOfIndex = taosArrayGetSize(pRsp->pIndexRsp);
  for (int32_t i = 0; i < numOfIndex; ++i) {
    STableIndexRsp *pIndexRsp = taosArrayGet(pRsp->pIndexRsp, i);
    tFreeSTableIndexRsp(pIndexRsp);
  }

  taosArrayDestroy(pRsp->pIndexRsp);
S
Shengliang Guan 已提交
3240 3241 3242
}

int32_t tSerializeSShowRsp(void *buf, int32_t bufLen, SShowRsp *pRsp) {
H
Hongze Cheng 已提交
3243 3244
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3245 3246 3247 3248 3249 3250 3251

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->showId) < 0) return -1;
  if (tEncodeSTableMetaRsp(&encoder, &pRsp->tableMeta) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3252
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3253 3254 3255 3256
  return tlen;
}

int32_t tDeserializeSShowRsp(void *buf, int32_t bufLen, SShowRsp *pRsp) {
H
Hongze Cheng 已提交
3257 3258
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3259 3260 3261 3262 3263 3264

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->showId) < 0) return -1;
  if (tDecodeSTableMetaRsp(&decoder, &pRsp->tableMeta) < 0) return -1;

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3265
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3266 3267 3268 3269 3270 3271 3272
  return 0;
}

void tFreeSShowRsp(SShowRsp *pRsp) { tFreeSTableMetaRsp(&pRsp->tableMeta); }

int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);
S
Shengliang Guan 已提交
3273 3274 3275 3276
  if (buf != NULL) {
    buf = (char *)buf + headLen;
    bufLen -= headLen;
  }
S
Shengliang Guan 已提交
3277

H
Hongze Cheng 已提交
3278 3279
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3280 3281 3282 3283 3284 3285 3286

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->tbName) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3287
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3288 3289 3290 3291 3292 3293 3294 3295

  if (buf != NULL) {
    SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
    pHead->vgId = htonl(pReq->header.vgId);
    pHead->contLen = htonl(tlen + headLen);
  }

  return tlen + headLen;
S
Shengliang Guan 已提交
3296 3297 3298
}

int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) {
S
Shengliang Guan 已提交
3299 3300 3301 3302 3303
  int32_t headLen = sizeof(SMsgHead);

  SMsgHead *pHead = buf;
  pHead->vgId = pReq->header.vgId;
  pHead->contLen = pReq->header.contLen;
S
Shengliang Guan 已提交
3304

H
Hongze Cheng 已提交
3305 3306
  SDecoder decoder = {0};
  tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
S
Shengliang Guan 已提交
3307 3308 3309 3310 3311 3312

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->tbName) < 0) return -1;

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3313
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3314 3315
  return 0;
}
S
Shengliang Guan 已提交
3316

S
Shengliang Guan 已提交
3317
int32_t tSerializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pReq) {
H
Hongze Cheng 已提交
3318 3319
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3320 3321 3322 3323 3324 3325 3326

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3327
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3328 3329 3330 3331
  return tlen;
}

int32_t tDeserializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pReq) {
H
Hongze Cheng 已提交
3332 3333
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3334 3335 3336 3337 3338 3339

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3340
  tDecoderClear(&decoder);
3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369
  return 0;
}

int32_t tSerializeSMDropCgroupReq(void *buf, int32_t bufLen, SMDropCgroupReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->topic) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->cgroup) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSMDropCgroupReq(void *buf, int32_t bufLen, SMDropCgroupReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->topic) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->cgroup) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3370 3371
  return 0;
}
S
Shengliang Guan 已提交
3372

L
Liu Jicong 已提交
3373
int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTopicReq *pReq) {
H
Hongze Cheng 已提交
3374 3375
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3376 3377 3378 3379

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
L
Liu Jicong 已提交
3380
  if (tEncodeI8(&encoder, pReq->subType) < 0) return -1;
L
Liu Jicong 已提交
3381
  if (tEncodeI8(&encoder, pReq->withMeta) < 0) return -1;
L
Liu Jicong 已提交
3382
  if (tEncodeCStr(&encoder, pReq->subDbName) < 0) return -1;
3383 3384 3385 3386 3387 3388 3389 3390 3391
  if (TOPIC_SUB_TYPE__DB == pReq->subType) {
  } else if (TOPIC_SUB_TYPE__TABLE == pReq->subType) {
    if (tEncodeCStr(&encoder, pReq->subStbName) < 0) return -1;
  } else {
    if (tEncodeI32(&encoder, strlen(pReq->ast)) < 0) return -1;
    if (tEncodeCStr(&encoder, pReq->ast) < 0) return -1;
  }
  if (tEncodeI32(&encoder, strlen(pReq->sql)) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
S
Shengliang Guan 已提交
3392 3393 3394 3395

  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3396
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3397 3398 3399
  return tlen;
}

L
Liu Jicong 已提交
3400
int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicReq *pReq) {
S
Shengliang Guan 已提交
3401
  int32_t sqlLen = 0;
3402
  int32_t astLen = 0;
S
Shengliang Guan 已提交
3403

H
Hongze Cheng 已提交
3404 3405
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3406 3407 3408 3409

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
L
Liu Jicong 已提交
3410
  if (tDecodeI8(&decoder, &pReq->subType) < 0) return -1;
L
Liu Jicong 已提交
3411
  if (tDecodeI8(&decoder, &pReq->withMeta) < 0) return -1;
L
Liu Jicong 已提交
3412
  if (tDecodeCStrTo(&decoder, pReq->subDbName) < 0) return -1;
3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423
  if (TOPIC_SUB_TYPE__DB == pReq->subType) {
  } else if (TOPIC_SUB_TYPE__TABLE == pReq->subType) {
    if (tDecodeCStrTo(&decoder, pReq->subStbName) < 0) return -1;
  } else {
    if (tDecodeI32(&decoder, &astLen) < 0) return -1;
    if (astLen > 0) {
      pReq->ast = taosMemoryCalloc(1, astLen + 1);
      if (pReq->ast == NULL) return -1;
      if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1;
    }
  }
S
Shengliang Guan 已提交
3424
  if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
3425
  if (sqlLen > 0) {
wafwerar's avatar
wafwerar 已提交
3426
    pReq->sql = taosMemoryCalloc(1, sqlLen + 1);
3427 3428 3429 3430
    if (pReq->sql == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
  }

S
Shengliang Guan 已提交
3431 3432
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3433
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3434 3435 3436
  return 0;
}

L
Liu Jicong 已提交
3437
void tFreeSCMCreateTopicReq(SCMCreateTopicReq *pReq) {
wafwerar's avatar
wafwerar 已提交
3438
  taosMemoryFreeClear(pReq->sql);
3439 3440 3441
  if (TOPIC_SUB_TYPE__COLUMN == pReq->subType) {
    taosMemoryFreeClear(pReq->ast);
  }
S
Shengliang Guan 已提交
3442 3443
}

L
Liu Jicong 已提交
3444
int32_t tSerializeSCMCreateTopicRsp(void *buf, int32_t bufLen, const SCMCreateTopicRsp *pRsp) {
H
Hongze Cheng 已提交
3445 3446
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3447 3448 3449 3450 3451 3452

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->topicId) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3453
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3454 3455 3456
  return tlen;
}

L
Liu Jicong 已提交
3457
int32_t tDeserializeSCMCreateTopicRsp(void *buf, int32_t bufLen, SCMCreateTopicRsp *pRsp) {
H
Hongze Cheng 已提交
3458 3459
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3460 3461 3462 3463 3464

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->topicId) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3465
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3466 3467
  return 0;
}
S
Shengliang Guan 已提交
3468 3469

int32_t tSerializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) {
H
Hongze Cheng 已提交
3470 3471
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3472 3473

  if (tStartEncode(&encoder) < 0) return -1;
L
Liu Jicong 已提交
3474
  if (tEncodeI8(&encoder, pReq->connType) < 0) return -1;
S
Shengliang Guan 已提交
3475 3476 3477
  if (tEncodeI32(&encoder, pReq->pid) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->app) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
3478
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
3479
  if (tEncodeCStrWithLen(&encoder, pReq->passwd, TSDB_PASSWORD_LEN) < 0) return -1;
S
Shengliang Guan 已提交
3480 3481 3482 3483
  if (tEncodeI64(&encoder, pReq->startTime) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3484
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3485 3486 3487 3488
  return tlen;
}

int32_t tDeserializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) {
H
Hongze Cheng 已提交
3489 3490
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3491 3492

  if (tStartDecode(&decoder) < 0) return -1;
L
Liu Jicong 已提交
3493
  if (tDecodeI8(&decoder, &pReq->connType) < 0) return -1;
S
Shengliang Guan 已提交
3494 3495 3496
  if (tDecodeI32(&decoder, &pReq->pid) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->app) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
3497 3498
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->passwd) < 0) return -1;
S
Shengliang Guan 已提交
3499 3500 3501
  if (tDecodeI64(&decoder, &pReq->startTime) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3502
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3503 3504 3505 3506
  return 0;
}

int32_t tSerializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) {
H
Hongze Cheng 已提交
3507 3508
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3509 3510 3511 3512

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->acctId) < 0) return -1;
  if (tEncodeI64(&encoder, pRsp->clusterId) < 0) return -1;
D
dapan1121 已提交
3513
  if (tEncodeU32(&encoder, pRsp->connId) < 0) return -1;
D
dapan 已提交
3514
  if (tEncodeI32(&encoder, pRsp->dnodeNum) < 0) return -1;
S
Shengliang Guan 已提交
3515
  if (tEncodeI8(&encoder, pRsp->superUser) < 0) return -1;
L
Liu Jicong 已提交
3516
  if (tEncodeI8(&encoder, pRsp->connType) < 0) return -1;
S
Shengliang Guan 已提交
3517
  if (tEncodeSEpSet(&encoder, &pRsp->epSet) < 0) return -1;
D
dapan1121 已提交
3518 3519
  if (tEncodeCStr(&encoder, pRsp->sVer) < 0) return -1;
  if (tEncodeCStr(&encoder, pRsp->sDetailVer) < 0) return -1;
S
Shengliang Guan 已提交
3520 3521 3522
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3523
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3524 3525 3526 3527
  return tlen;
}

int32_t tDeserializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) {
H
Hongze Cheng 已提交
3528 3529
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3530 3531 3532 3533

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->acctId) < 0) return -1;
  if (tDecodeI64(&decoder, &pRsp->clusterId) < 0) return -1;
D
dapan1121 已提交
3534
  if (tDecodeU32(&decoder, &pRsp->connId) < 0) return -1;
D
dapan 已提交
3535
  if (tDecodeI32(&decoder, &pRsp->dnodeNum) < 0) return -1;
S
Shengliang Guan 已提交
3536
  if (tDecodeI8(&decoder, &pRsp->superUser) < 0) return -1;
L
Liu Jicong 已提交
3537
  if (tDecodeI8(&decoder, &pRsp->connType) < 0) return -1;
S
Shengliang Guan 已提交
3538
  if (tDecodeSEpSet(&decoder, &pRsp->epSet) < 0) return -1;
D
dapan1121 已提交
3539 3540
  if (tDecodeCStrTo(&decoder, pRsp->sVer) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->sDetailVer) < 0) return -1;
S
Shengliang Guan 已提交
3541 3542
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3543
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3544 3545
  return 0;
}
S
Shengliang Guan 已提交
3546 3547

int32_t tSerializeSMTimerMsg(void *buf, int32_t bufLen, SMTimerReq *pReq) {
H
Hongze Cheng 已提交
3548 3549
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3550 3551 3552 3553 3554 3555

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->reserved) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3556
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3557 3558 3559 3560
  return tlen;
}

int32_t tDeserializeSMTimerMsg(void *buf, int32_t bufLen, SMTimerReq *pReq) {
H
Hongze Cheng 已提交
3561 3562
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3563 3564 3565 3566 3567

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->reserved) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3568
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3569 3570
  return 0;
}
S
Shengliang Guan 已提交
3571

H
Hongze Cheng 已提交
3572
int32_t tEncodeSReplica(SEncoder *pEncoder, SReplica *pReplica) {
S
Shengliang Guan 已提交
3573 3574 3575 3576 3577 3578
  if (tEncodeI32(pEncoder, pReplica->id) < 0) return -1;
  if (tEncodeU16(pEncoder, pReplica->port) < 0) return -1;
  if (tEncodeCStr(pEncoder, pReplica->fqdn) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
3579
int32_t tDecodeSReplica(SDecoder *pDecoder, SReplica *pReplica) {
S
Shengliang Guan 已提交
3580 3581 3582 3583 3584 3585
  if (tDecodeI32(pDecoder, &pReplica->id) < 0) return -1;
  if (tDecodeU16(pDecoder, &pReplica->port) < 0) return -1;
  if (tDecodeCStrTo(pDecoder, pReplica->fqdn) < 0) return -1;
  return 0;
}

S
Shengliang Guan 已提交
3586
int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pReq) {
H
Hongze Cheng 已提交
3587 3588
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3589 3590 3591 3592

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
L
Liu Jicong 已提交
3593
  if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1;
S
Shengliang Guan 已提交
3594
  if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1;
S
Shengliang Guan 已提交
3595 3596 3597 3598
  if (tEncodeI32(&encoder, pReq->numOfStables) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
3599
  if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
3600 3601 3602 3603 3604 3605 3606
  if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->minRows) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1;
D
dapan1121 已提交
3607 3608 3609
  if (tEncodeU32(&encoder, pReq->hashBegin) < 0) return -1;
  if (tEncodeU32(&encoder, pReq->hashEnd) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->hashMethod) < 0) return -1;
S
Shengliang Guan 已提交
3610 3611 3612
  if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->precision) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->compression) < 0) return -1;
S
Shengliang Guan 已提交
3613
  if (tEncodeI8(&encoder, pReq->strict) < 0) return -1;
S
Shengliang Guan 已提交
3614
  if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1;
3615
  if (tEncodeI8(&encoder, pReq->standby) < 0) return -1;
S
Shengliang Guan 已提交
3616 3617 3618 3619
  if (tEncodeI8(&encoder, pReq->replica) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1;
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
    SReplica *pReplica = &pReq->replicas[i];
S
Shengliang Guan 已提交
3620
    if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
S
Shengliang Guan 已提交
3621
  }
S
sma  
Shengliang Guan 已提交
3622 3623 3624
  if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1;
  for (int32_t i = 0; i < pReq->numOfRetensions; ++i) {
    SRetention *pRetension = taosArrayGet(pReq->pRetensions, i);
C
Cary Xu 已提交
3625 3626
    if (tEncodeI64(&encoder, pRetension->freq) < 0) return -1;
    if (tEncodeI64(&encoder, pRetension->keep) < 0) return -1;
S
sma  
Shengliang Guan 已提交
3627 3628 3629
    if (tEncodeI8(&encoder, pRetension->freqUnit) < 0) return -1;
    if (tEncodeI8(&encoder, pRetension->keepUnit) < 0) return -1;
  }
S
Shengliang Guan 已提交
3630 3631

  if (tEncodeI8(&encoder, pReq->isTsma) < 0) return -1;
C
Cary Xu 已提交
3632 3633 3634 3635 3636
  if (pReq->isTsma) {
    uint32_t tsmaLen = (uint32_t)(htonl(((SMsgHead *)pReq->pTsma)->contLen));
    if (tEncodeBinary(&encoder, (const uint8_t *)pReq->pTsma, tsmaLen) < 0) return -1;
  }

S
Shengliang Guan 已提交
3637 3638 3639
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3640
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3641 3642 3643 3644
  return tlen;
}

int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pReq) {
H
Hongze Cheng 已提交
3645 3646
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3647 3648 3649 3650

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
L
Liu Jicong 已提交
3651
  if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1;
S
Shengliang Guan 已提交
3652
  if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1;
S
Shengliang Guan 已提交
3653 3654 3655 3656
  if (tDecodeI32(&decoder, &pReq->numOfStables) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
3657
  if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
3658 3659 3660 3661 3662 3663 3664
  if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->minRows) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1;
D
dapan1121 已提交
3665 3666 3667
  if (tDecodeU32(&decoder, &pReq->hashBegin) < 0) return -1;
  if (tDecodeU32(&decoder, &pReq->hashEnd) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->hashMethod) < 0) return -1;
S
Shengliang Guan 已提交
3668 3669 3670
  if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1;
S
Shengliang Guan 已提交
3671
  if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1;
S
Shengliang Guan 已提交
3672
  if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1;
3673
  if (tDecodeI8(&decoder, &pReq->standby) < 0) return -1;
S
Shengliang Guan 已提交
3674 3675 3676 3677
  if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1;
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
    SReplica *pReplica = &pReq->replicas[i];
S
Shengliang Guan 已提交
3678
    if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
S
Shengliang Guan 已提交
3679
  }
S
sma  
Shengliang Guan 已提交
3680 3681 3682 3683 3684 3685 3686 3687 3688
  if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1;
  pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention));
  if (pReq->pRetensions == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

  for (int32_t i = 0; i < pReq->numOfRetensions; ++i) {
    SRetention rentension = {0};
C
Cary Xu 已提交
3689 3690
    if (tDecodeI64(&decoder, &rentension.freq) < 0) return -1;
    if (tDecodeI64(&decoder, &rentension.keep) < 0) return -1;
S
sma  
Shengliang Guan 已提交
3691 3692 3693 3694 3695 3696 3697 3698
    if (tDecodeI8(&decoder, &rentension.freqUnit) < 0) return -1;
    if (tDecodeI8(&decoder, &rentension.keepUnit) < 0) return -1;
    if (taosArrayPush(pReq->pRetensions, &rentension) == NULL) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
  }

S
Shengliang Guan 已提交
3699
  if (tDecodeI8(&decoder, &pReq->isTsma) < 0) return -1;
C
Cary Xu 已提交
3700
  if (pReq->isTsma) {
C
Cary Xu 已提交
3701
    if (tDecodeBinary(&decoder, (uint8_t **)&pReq->pTsma, NULL) < 0) return -1;
C
Cary Xu 已提交
3702
  }
S
Shengliang Guan 已提交
3703

S
Shengliang Guan 已提交
3704
  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3705
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3706 3707 3708
  return 0;
}

S
sma  
Shengliang Guan 已提交
3709 3710 3711
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq *pReq) {
  taosArrayDestroy(pReq->pRetensions);
  pReq->pRetensions = NULL;
3712
  return 0;
S
sma  
Shengliang Guan 已提交
3713 3714
}

S
Shengliang Guan 已提交
3715
int32_t tSerializeSDropVnodeReq(void *buf, int32_t bufLen, SDropVnodeReq *pReq) {
H
Hongze Cheng 已提交
3716 3717
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3718 3719 3720 3721

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
L
Liu Jicong 已提交
3722
  if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1;
S
Shengliang Guan 已提交
3723 3724 3725 3726
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3727
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3728 3729 3730 3731
  return tlen;
}

int32_t tDeserializeSDropVnodeReq(void *buf, int32_t bufLen, SDropVnodeReq *pReq) {
H
Hongze Cheng 已提交
3732 3733
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3734 3735 3736 3737

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
L
Liu Jicong 已提交
3738
  if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1;
S
Shengliang Guan 已提交
3739 3740 3741
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3742
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3743 3744 3745
  return 0;
}

S
Shengliang Guan 已提交
3746
int32_t tSerializeSCompactVnodeReq(void *buf, int32_t bufLen, SCompactVnodeReq *pReq) {
H
Hongze Cheng 已提交
3747 3748
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3749 3750 3751 3752 3753 3754 3755

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3756
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3757 3758 3759 3760
  return tlen;
}

int32_t tDeserializeSCompactVnodeReq(void *buf, int32_t bufLen, SCompactVnodeReq *pReq) {
H
Hongze Cheng 已提交
3761 3762
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3763 3764 3765 3766 3767 3768

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3769
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3770 3771 3772 3773
  return 0;
}

int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq) {
H
Hongze Cheng 已提交
3774 3775
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3776 3777 3778

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1;
S
Shengliang Guan 已提交
3779 3780 3781
  if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
3782
  if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
3783
  if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
S
Shengliang Guan 已提交
3784 3785 3786
  if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1;
S
Shengliang Guan 已提交
3787
  if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1;
S
Shengliang Guan 已提交
3788 3789 3790 3791
  if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->strict) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1;
3792
  if (tEncodeI8(&encoder, pReq->replica) < 0) return -1;
S
Shengliang Guan 已提交
3793 3794 3795 3796 3797 3798 3799
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
    SReplica *pReplica = &pReq->replicas[i];
    if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3800
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3801 3802 3803 3804
  return tlen;
}

int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq) {
H
Hongze Cheng 已提交
3805 3806
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3807 3808 3809

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1;
S
Shengliang Guan 已提交
3810 3811 3812
  if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
3813
  if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
S
Shengliang Guan 已提交
3814
  if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
S
Shengliang Guan 已提交
3815 3816 3817
  if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1;
S
Shengliang Guan 已提交
3818
  if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1;
S
Shengliang Guan 已提交
3819 3820 3821 3822
  if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1;
3823
  if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1;
S
Shengliang Guan 已提交
3824 3825 3826 3827 3828 3829
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
    SReplica *pReplica = &pReq->replicas[i];
    if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
  }

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
3830
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3831 3832 3833
  return 0;
}

S
Shengliang Guan 已提交
3834
int32_t tSerializeSKillQueryReq(void *buf, int32_t bufLen, SKillQueryReq *pReq) {
H
Hongze Cheng 已提交
3835 3836
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3837 3838

  if (tStartEncode(&encoder) < 0) return -1;
X
Xiaoyu Wang 已提交
3839
  if (tEncodeCStr(&encoder, pReq->queryStrId) < 0) return -1;
S
Shengliang Guan 已提交
3840 3841 3842
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3843
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3844 3845 3846 3847
  return tlen;
}

int32_t tDeserializeSKillQueryReq(void *buf, int32_t bufLen, SKillQueryReq *pReq) {
H
Hongze Cheng 已提交
3848 3849
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3850 3851

  if (tStartDecode(&decoder) < 0) return -1;
X
Xiaoyu Wang 已提交
3852
  if (tDecodeCStrTo(&decoder, pReq->queryStrId) < 0) return -1;
S
Shengliang Guan 已提交
3853 3854
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3855
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3856 3857 3858 3859
  return 0;
}

int32_t tSerializeSKillConnReq(void *buf, int32_t bufLen, SKillConnReq *pReq) {
H
Hongze Cheng 已提交
3860 3861
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3862 3863

  if (tStartEncode(&encoder) < 0) return -1;
D
dapan1121 已提交
3864
  if (tEncodeU32(&encoder, pReq->connId) < 0) return -1;
S
Shengliang Guan 已提交
3865 3866 3867
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3868
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3869 3870 3871 3872
  return tlen;
}

int32_t tDeserializeSKillConnReq(void *buf, int32_t bufLen, SKillConnReq *pReq) {
H
Hongze Cheng 已提交
3873 3874
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3875 3876

  if (tStartDecode(&decoder) < 0) return -1;
D
dapan1121 已提交
3877
  if (tDecodeU32(&decoder, &pReq->connId) < 0) return -1;
S
Shengliang Guan 已提交
3878 3879
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3880
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3881
  return 0;
S
Shengliang Guan 已提交
3882 3883
}

S
Shengliang Guan 已提交
3884
int32_t tSerializeSKillTransReq(void *buf, int32_t bufLen, SKillTransReq *pReq) {
H
Hongze Cheng 已提交
3885 3886
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
3887 3888 3889 3890 3891 3892

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->transId) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
3893
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
3894 3895 3896 3897
  return tlen;
}

int32_t tDeserializeSKillTransReq(void *buf, int32_t bufLen, SKillTransReq *pReq) {
H
Hongze Cheng 已提交
3898 3899
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
3900 3901 3902 3903 3904

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->transId) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
3905
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
3906 3907 3908
  return 0;
}

X
Xiaoyu Wang 已提交
3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991
int32_t tSerializeSBalanceVgroupReq(void *buf, int32_t bufLen, SBalanceVgroupReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->useless) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSBalanceVgroupReq(void *buf, int32_t bufLen, SBalanceVgroupReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->useless) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

int32_t tSerializeSMergeVgroupReq(void *buf, int32_t bufLen, SMergeVgroupReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgId1) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgId2) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSMergeVgroupReq(void *buf, int32_t bufLen, SMergeVgroupReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgId1) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgId2) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

int32_t tSerializeSRedistributeVgroupReq(void *buf, int32_t bufLen, SRedistributeVgroupReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId1) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId2) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId3) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSRedistributeVgroupReq(void *buf, int32_t bufLen, SRedistributeVgroupReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId1) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId2) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId3) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016
int32_t tSerializeSSplitVgroupReq(void *buf, int32_t bufLen, SSplitVgroupReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSSplitVgroupReq(void *buf, int32_t bufLen, SSplitVgroupReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

S
Shengliang Guan 已提交
4017
int32_t tSerializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq *pReq) {
H
Hongze Cheng 已提交
4018 4019
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
4020 4021 4022 4023 4024 4025 4026 4027 4028 4029

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->replica) < 0) return -1;
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
    SReplica *pReplica = &pReq->replicas[i];
    if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4030
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
4031 4032 4033 4034
  return tlen;
}

int32_t tDeserializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq *pReq) {
H
Hongze Cheng 已提交
4035 4036
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
4037 4038 4039 4040 4041 4042 4043 4044 4045

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1;
  for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
    SReplica *pReplica = &pReq->replicas[i];
    if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
4046
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
4047 4048 4049
  return 0;
}

4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076
int32_t tSerializeSSetStandbyReq(void *buf, int32_t bufLen, SSetStandbyReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->standby) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSSetStandbyReq(void *buf, int32_t bufLen, SSetStandbyReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->standby) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

S
Shengliang Guan 已提交
4077
int32_t tSerializeSAuthReq(void *buf, int32_t bufLen, SAuthReq *pReq) {
H
Hongze Cheng 已提交
4078 4079
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
4080 4081 4082 4083 4084 4085 4086 4087 4088 4089

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->spi) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->encrypt) < 0) return -1;
  if (tEncodeBinary(&encoder, pReq->secret, TSDB_PASSWORD_LEN) < 0) return -1;
  if (tEncodeBinary(&encoder, pReq->ckey, TSDB_PASSWORD_LEN) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4090
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
4091 4092 4093 4094
  return tlen;
}

int32_t tDeserializeSAuthReq(void *buf, int32_t bufLen, SAuthReq *pReq) {
H
Hongze Cheng 已提交
4095 4096
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
4097 4098 4099 4100 4101 4102 4103 4104 4105

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->spi) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->encrypt) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->secret) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->ckey) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
4106
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
4107 4108
  return 0;
}
L
Liu Jicong 已提交
4109

S
Shengliang Guan 已提交
4110
int32_t tSerializeSServerStatusRsp(void *buf, int32_t bufLen, SServerStatusRsp *pRsp) {
H
Hongze Cheng 已提交
4111 4112
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
4113 4114 4115

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->statusCode) < 0) return -1;
S
Shengliang Guan 已提交
4116
  if (tEncodeCStr(&encoder, pRsp->details) < 0) return -1;
S
Shengliang Guan 已提交
4117 4118 4119 4120

  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4121
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
4122 4123 4124 4125
  return tlen;
}

int32_t tDeserializeSServerStatusRsp(void *buf, int32_t bufLen, SServerStatusRsp *pRsp) {
H
Hongze Cheng 已提交
4126 4127
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
4128 4129 4130

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->statusCode) < 0) return -1;
S
Shengliang Guan 已提交
4131
  if (tDecodeCStrTo(&decoder, pRsp->details) < 0) return -1;
S
Shengliang Guan 已提交
4132 4133

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
4134
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
4135 4136 4137
  return 0;
}

H
Hongze Cheng 已提交
4138
int32_t tEncodeSMqOffset(SEncoder *encoder, const SMqOffset *pOffset) {
L
Liu Jicong 已提交
4139 4140 4141 4142 4143 4144 4145
  if (tEncodeI32(encoder, pOffset->vgId) < 0) return -1;
  if (tEncodeI64(encoder, pOffset->offset) < 0) return -1;
  if (tEncodeCStr(encoder, pOffset->topicName) < 0) return -1;
  if (tEncodeCStr(encoder, pOffset->cgroup) < 0) return -1;
  return encoder->pos;
}

H
Hongze Cheng 已提交
4146
int32_t tDecodeSMqOffset(SDecoder *decoder, SMqOffset *pOffset) {
L
Liu Jicong 已提交
4147 4148 4149 4150 4151 4152 4153
  if (tDecodeI32(decoder, &pOffset->vgId) < 0) return -1;
  if (tDecodeI64(decoder, &pOffset->offset) < 0) return -1;
  if (tDecodeCStrTo(decoder, pOffset->topicName) < 0) return -1;
  if (tDecodeCStrTo(decoder, pOffset->cgroup) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
4154
int32_t tEncodeSMqCMCommitOffsetReq(SEncoder *encoder, const SMqCMCommitOffsetReq *pReq) {
L
Liu Jicong 已提交
4155 4156 4157 4158 4159 4160 4161 4162 4163
  if (tStartEncode(encoder) < 0) return -1;
  if (tEncodeI32(encoder, pReq->num) < 0) return -1;
  for (int32_t i = 0; i < pReq->num; i++) {
    tEncodeSMqOffset(encoder, &pReq->offsets[i]);
  }
  tEndEncode(encoder);
  return encoder->pos;
}

H
Hongze Cheng 已提交
4164
int32_t tDecodeSMqCMCommitOffsetReq(SDecoder *decoder, SMqCMCommitOffsetReq *pReq) {
L
Liu Jicong 已提交
4165
  if (tStartDecode(decoder) < 0) return -1;
L
Liu Jicong 已提交
4166
  if (tDecodeI32(decoder, &pReq->num) < 0) return -1;
H
Hongze Cheng 已提交
4167
  pReq->offsets = (SMqOffset *)tDecoderMalloc(decoder, sizeof(SMqOffset) * pReq->num);
L
Liu Jicong 已提交
4168 4169 4170 4171
  if (pReq->offsets == NULL) return -1;
  for (int32_t i = 0; i < pReq->num; i++) {
    tDecodeSMqOffset(decoder, &pReq->offsets[i]);
  }
L
Liu Jicong 已提交
4172
  tEndDecode(decoder);
L
Liu Jicong 已提交
4173 4174
  return 0;
}
D
dapan1121 已提交
4175

dengyihao's avatar
dengyihao 已提交
4176
int32_t tSerializeSExplainRsp(void *buf, int32_t bufLen, SExplainRsp *pRsp) {
H
Hongze Cheng 已提交
4177 4178
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
4179 4180 4181 4182 4183

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, pRsp->numOfPlans) < 0) return -1;
  for (int32_t i = 0; i < pRsp->numOfPlans; ++i) {
    SExplainExecInfo *info = &pRsp->subplanInfo[i];
4184 4185
    if (tEncodeDouble(&encoder, info->startupCost) < 0) return -1;
    if (tEncodeDouble(&encoder, info->totalCost) < 0) return -1;
D
dapan1121 已提交
4186
    if (tEncodeU64(&encoder, info->numOfRows) < 0) return -1;
4187 4188
    if (tEncodeU32(&encoder, info->verboseLen) < 0) return -1;
    if (tEncodeBinary(&encoder, info->verboseInfo, info->verboseLen) < 0) return -1;
D
dapan1121 已提交
4189 4190 4191 4192 4193
  }

  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4194
  tEncoderClear(&encoder);
D
dapan1121 已提交
4195 4196 4197
  return tlen;
}

dengyihao's avatar
dengyihao 已提交
4198
int32_t tDeserializeSExplainRsp(void *buf, int32_t bufLen, SExplainRsp *pRsp) {
H
Hongze Cheng 已提交
4199 4200
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
4201 4202 4203 4204 4205 4206 4207 4208

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->numOfPlans) < 0) return -1;
  if (pRsp->numOfPlans > 0) {
    pRsp->subplanInfo = taosMemoryMalloc(pRsp->numOfPlans * sizeof(SExplainExecInfo));
    if (pRsp->subplanInfo == NULL) return -1;
  }
  for (int32_t i = 0; i < pRsp->numOfPlans; ++i) {
4209 4210
    if (tDecodeDouble(&decoder, &pRsp->subplanInfo[i].startupCost) < 0) return -1;
    if (tDecodeDouble(&decoder, &pRsp->subplanInfo[i].totalCost) < 0) return -1;
D
dapan1121 已提交
4211
    if (tDecodeU64(&decoder, &pRsp->subplanInfo[i].numOfRows) < 0) return -1;
4212
    if (tDecodeU32(&decoder, &pRsp->subplanInfo[i].verboseLen) < 0) return -1;
X
Xiaoyu Wang 已提交
4213 4214
    if (tDecodeBinary(&decoder, (uint8_t **)&pRsp->subplanInfo[i].verboseInfo, &pRsp->subplanInfo[i].verboseLen) < 0)
      return -1;
D
dapan1121 已提交
4215 4216 4217 4218
  }

  tEndDecode(&decoder);

H
Hongze Cheng 已提交
4219
  tDecoderClear(&decoder);
D
dapan1121 已提交
4220 4221 4222
  return 0;
}

D
dapan1121 已提交
4223 4224 4225 4226 4227 4228 4229
int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);
  if (buf != NULL) {
    buf = (char *)buf + headLen;
    bufLen -= headLen;
  }

H
Hongze Cheng 已提交
4230 4231
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
4232 4233

  if (tStartEncode(&encoder) < 0) return -1;
L
Liu Jicong 已提交
4234 4235
  if (tEncodeU64(&encoder, pReq->sId) < 0) return -1;
  if (tEncodeI32(&encoder, pReq->epId.nodeId) < 0) return -1;
D
dapan1121 已提交
4236
  if (tEncodeU16(&encoder, pReq->epId.ep.port) < 0) return -1;
L
Liu Jicong 已提交
4237
  if (tEncodeCStr(&encoder, pReq->epId.ep.fqdn) < 0) return -1;
D
dapan1121 已提交
4238 4239
  if (pReq->taskAction) {
    int32_t num = taosArrayGetSize(pReq->taskAction);
L
Liu Jicong 已提交
4240
    if (tEncodeI32(&encoder, num) < 0) return -1;
D
dapan1121 已提交
4241 4242
    for (int32_t i = 0; i < num; ++i) {
      STaskAction *action = taosArrayGet(pReq->taskAction, i);
L
Liu Jicong 已提交
4243 4244 4245
      if (tEncodeU64(&encoder, action->queryId) < 0) return -1;
      if (tEncodeU64(&encoder, action->taskId) < 0) return -1;
      if (tEncodeI8(&encoder, action->action) < 0) return -1;
D
dapan1121 已提交
4246 4247
    }
  } else {
L
Liu Jicong 已提交
4248
    if (tEncodeI32(&encoder, 0) < 0) return -1;
D
dapan1121 已提交
4249 4250 4251 4252
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4253
  tEncoderClear(&encoder);
L
Liu Jicong 已提交
4254

D
dapan1121 已提交
4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270
  if (buf != NULL) {
    SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
    pHead->vgId = htonl(pReq->header.vgId);
    pHead->contLen = htonl(tlen + headLen);
  }

  return tlen + headLen;
}

int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);

  SMsgHead *pHead = buf;
  pHead->vgId = pReq->header.vgId;
  pHead->contLen = pReq->header.contLen;

H
Hongze Cheng 已提交
4271 4272
  SDecoder decoder = {0};
  tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
D
dapan1121 已提交
4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeU64(&decoder, &pReq->sId) < 0) return -1;
  if (tDecodeI32(&decoder, &pReq->epId.nodeId) < 0) return -1;
  if (tDecodeU16(&decoder, &pReq->epId.ep.port) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->epId.ep.fqdn) < 0) return -1;
  int32_t num = 0;
  if (tDecodeI32(&decoder, &num) < 0) return -1;
  if (num > 0) {
    pReq->taskAction = taosArrayInit(num, sizeof(STaskStatus));
    if (NULL == pReq->taskAction) return -1;
    for (int32_t i = 0; i < num; ++i) {
      STaskAction action = {0};
      if (tDecodeU64(&decoder, &action.queryId) < 0) return -1;
      if (tDecodeU64(&decoder, &action.taskId) < 0) return -1;
      if (tDecodeI8(&decoder, &action.action) < 0) return -1;
      taosArrayPush(pReq->taskAction, &action);
    }
  } else {
    pReq->taskAction = NULL;
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
4296
  tDecoderClear(&decoder);
D
dapan1121 已提交
4297 4298 4299 4300 4301 4302
  return 0;
}

void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq) { taosArrayDestroy(pReq->taskAction); }

int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) {
H
Hongze Cheng 已提交
4303 4304
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
D
dapan1121 已提交
4305 4306

  if (tStartEncode(&encoder) < 0) return -1;
L
Liu Jicong 已提交
4307
  if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1;
D
dapan1121 已提交
4308
  if (tEncodeU16(&encoder, pRsp->epId.ep.port) < 0) return -1;
L
Liu Jicong 已提交
4309
  if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1;
D
dapan1121 已提交
4310 4311
  if (pRsp->taskStatus) {
    int32_t num = taosArrayGetSize(pRsp->taskStatus);
L
Liu Jicong 已提交
4312
    if (tEncodeI32(&encoder, num) < 0) return -1;
D
dapan1121 已提交
4313 4314
    for (int32_t i = 0; i < num; ++i) {
      STaskStatus *status = taosArrayGet(pRsp->taskStatus, i);
L
Liu Jicong 已提交
4315 4316 4317
      if (tEncodeU64(&encoder, status->queryId) < 0) return -1;
      if (tEncodeU64(&encoder, status->taskId) < 0) return -1;
      if (tEncodeI64(&encoder, status->refId) < 0) return -1;
D
dapan1121 已提交
4318
      if (tEncodeI32(&encoder, status->execId) < 0) return -1;
L
Liu Jicong 已提交
4319
      if (tEncodeI8(&encoder, status->status) < 0) return -1;
D
dapan1121 已提交
4320 4321
    }
  } else {
L
Liu Jicong 已提交
4322
    if (tEncodeI32(&encoder, 0) < 0) return -1;
D
dapan1121 已提交
4323 4324 4325 4326
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4327
  tEncoderClear(&encoder);
D
dapan1121 已提交
4328 4329 4330 4331
  return tlen;
}

int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) {
H
Hongze Cheng 已提交
4332 4333
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
D
dapan1121 已提交
4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->epId.nodeId) < 0) return -1;
  if (tDecodeU16(&decoder, &pRsp->epId.ep.port) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pRsp->epId.ep.fqdn) < 0) return -1;
  int32_t num = 0;
  if (tDecodeI32(&decoder, &num) < 0) return -1;
  if (num > 0) {
    pRsp->taskStatus = taosArrayInit(num, sizeof(STaskStatus));
    if (NULL == pRsp->taskStatus) return -1;
    for (int32_t i = 0; i < num; ++i) {
      STaskStatus status = {0};
      if (tDecodeU64(&decoder, &status.queryId) < 0) return -1;
      if (tDecodeU64(&decoder, &status.taskId) < 0) return -1;
      if (tDecodeI64(&decoder, &status.refId) < 0) return -1;
D
dapan1121 已提交
4349
      if (tDecodeI32(&decoder, &status.execId) < 0) return -1;
D
dapan1121 已提交
4350 4351 4352 4353 4354 4355 4356 4357
      if (tDecodeI8(&decoder, &status.status) < 0) return -1;
      taosArrayPush(pRsp->taskStatus, &status);
    }
  } else {
    pRsp->taskStatus = NULL;
  }
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
4358
  tDecoderClear(&decoder);
D
dapan1121 已提交
4359 4360 4361 4362 4363
  return 0;
}

void tFreeSSchedulerHbRsp(SSchedulerHbRsp *pRsp) { taosArrayDestroy(pRsp->taskStatus); }

D
dapan 已提交
4364
int32_t tSerializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
4365 4366
  // SEncoder encoder = {0};
  // tEncoderInit(&encoder, buf, bufLen);
D
dapan 已提交
4367

H
Hongze Cheng 已提交
4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379
  // if (tStartEncode(&encoder) < 0) return -1;
  // if (pRsp->rspList) {
  //   int32_t num = taosArrayGetSize(pRsp->rspList);
  //   if (tEncodeI32(&encoder, num) < 0) return -1;
  //   for (int32_t i = 0; i < num; ++i) {
  //     SVCreateTbRsp *rsp = taosArrayGet(pRsp->rspList, i);
  //     if (tEncodeI32(&encoder, rsp->code) < 0) return -1;
  //   }
  // } else {
  //   if (tEncodeI32(&encoder, 0) < 0) return -1;
  // }
  // tEndEncode(&encoder);
D
dapan 已提交
4380

H
Hongze Cheng 已提交
4381
  // int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4382
  // tEncoderClear(&encoder);
H
Hongze Cheng 已提交
4383 4384
  // reture tlen;
  return 0;
D
dapan 已提交
4385 4386 4387
}

int32_t tDeserializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
4388
  // SDecoder  decoder = {0};
H
Hongze Cheng 已提交
4389
  // int32_t num = 0;
H
Hongze Cheng 已提交
4390
  // tDecoderInit(&decoder, buf, bufLen);
D
dapan 已提交
4391

H
Hongze Cheng 已提交
4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405
  // if (tStartDecode(&decoder) < 0) return -1;
  // if (tDecodeI32(&decoder, &num) < 0) return -1;
  // if (num > 0) {
  //   pRsp->rspList = taosArrayInit(num, sizeof(SVCreateTbRsp));
  //   if (NULL == pRsp->rspList) return -1;
  //   for (int32_t i = 0; i < num; ++i) {
  //     SVCreateTbRsp rsp = {0};
  //     if (tDecodeI32(&decoder, &rsp.code) < 0) return -1;
  //     if (NULL == taosArrayPush(pRsp->rspList, &rsp)) return -1;
  //   }
  // } else {
  //   pRsp->rspList = NULL;
  // }
  // tEndDecode(&decoder);
D
dapan 已提交
4406

H
Hongze Cheng 已提交
4407
  // tDecoderClear(&decoder);
D
dapan 已提交
4408 4409 4410
  return 0;
}

H
Hongze Cheng 已提交
4411
int tEncodeSVCreateTbBatchRsp(SEncoder *pCoder, const SVCreateTbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
4412 4413 4414 4415 4416 4417 4418 4419 4420
  int32_t        nRsps = taosArrayGetSize(pRsp->pArray);
  SVCreateTbRsp *pCreateRsp;

  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32v(pCoder, nRsps) < 0) return -1;
  for (int32_t i = 0; i < nRsps; i++) {
    pCreateRsp = taosArrayGet(pRsp->pArray, i);
    if (tEncodeSVCreateTbRsp(pCoder, pCreateRsp) < 0) return -1;
D
dapan 已提交
4421 4422
  }

H
Hongze Cheng 已提交
4423 4424 4425 4426 4427
  tEndEncode(pCoder);

  return 0;
}

H
Hongze Cheng 已提交
4428
int tDecodeSVCreateTbBatchRsp(SDecoder *pCoder, SVCreateTbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
4429 4430 4431
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32v(pCoder, &pRsp->nRsps) < 0) return -1;
H
Hongze Cheng 已提交
4432
  pRsp->pRsps = (SVCreateTbRsp *)tDecoderMalloc(pCoder, sizeof(*pRsp->pRsps) * pRsp->nRsps);
H
Hongze Cheng 已提交
4433 4434 4435 4436 4437
  for (int32_t i = 0; i < pRsp->nRsps; i++) {
    if (tDecodeSVCreateTbRsp(pCoder, pRsp->pRsps + i) < 0) return -1;
  }

  tEndDecode(pCoder);
D
dapan 已提交
4438 4439 4440
  return 0;
}

4441 4442 4443 4444 4445
int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
  if (tEncodeI8(pCoder, pSma->version) < 0) return -1;
  if (tEncodeI8(pCoder, pSma->intervalUnit) < 0) return -1;
  if (tEncodeI8(pCoder, pSma->slidingUnit) < 0) return -1;
  if (tEncodeI8(pCoder, pSma->timezoneInt) < 0) return -1;
C
Cary Xu 已提交
4446
  if (tEncodeI32(pCoder, pSma->dstVgId) < 0) return -1;
4447 4448 4449 4450 4451
  if (tEncodeCStr(pCoder, pSma->indexName) < 0) return -1;
  if (tEncodeI32(pCoder, pSma->exprLen) < 0) return -1;
  if (tEncodeI32(pCoder, pSma->tagsFilterLen) < 0) return -1;
  if (tEncodeI64(pCoder, pSma->indexUid) < 0) return -1;
  if (tEncodeI64(pCoder, pSma->tableUid) < 0) return -1;
C
Cary Xu 已提交
4452 4453
  if (tEncodeI64(pCoder, pSma->dstTbUid) < 0) return -1;
  if (tEncodeCStr(pCoder, pSma->dstTbName) < 0) return -1;
4454 4455 4456 4457 4458 4459 4460 4461 4462
  if (tEncodeI64(pCoder, pSma->interval) < 0) return -1;
  if (tEncodeI64(pCoder, pSma->offset) < 0) return -1;
  if (tEncodeI64(pCoder, pSma->sliding) < 0) return -1;
  if (pSma->exprLen > 0) {
    if (tEncodeCStr(pCoder, pSma->expr) < 0) return -1;
  }
  if (pSma->tagsFilterLen > 0) {
    if (tEncodeCStr(pCoder, pSma->tagsFilter) < 0) return -1;
  }
C
Cary Xu 已提交
4463

C
Cary Xu 已提交
4464 4465
  tEncodeSSchemaWrapper(pCoder, &pSma->schemaRow);
  tEncodeSSchemaWrapper(pCoder, &pSma->schemaTag);
C
Cary Xu 已提交
4466

4467 4468 4469
  return 0;
}

C
Cary Xu 已提交
4470
int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma, bool deepCopy) {
4471 4472 4473 4474
  if (tDecodeI8(pCoder, &pSma->version) < 0) return -1;
  if (tDecodeI8(pCoder, &pSma->intervalUnit) < 0) return -1;
  if (tDecodeI8(pCoder, &pSma->slidingUnit) < 0) return -1;
  if (tDecodeI8(pCoder, &pSma->timezoneInt) < 0) return -1;
C
Cary Xu 已提交
4475
  if (tDecodeI32(pCoder, &pSma->dstVgId) < 0) return -1;
C
Cary Xu 已提交
4476
  if (tDecodeCStrTo(pCoder, pSma->indexName) < 0) return -1;
4477 4478 4479 4480
  if (tDecodeI32(pCoder, &pSma->exprLen) < 0) return -1;
  if (tDecodeI32(pCoder, &pSma->tagsFilterLen) < 0) return -1;
  if (tDecodeI64(pCoder, &pSma->indexUid) < 0) return -1;
  if (tDecodeI64(pCoder, &pSma->tableUid) < 0) return -1;
C
Cary Xu 已提交
4481
  if (tDecodeI64(pCoder, &pSma->dstTbUid) < 0) return -1;
C
Cary Xu 已提交
4482 4483 4484 4485 4486 4487
  if (deepCopy) {
    if (tDecodeCStrAlloc(pCoder, &pSma->dstTbName) < 0) return -1;
  } else {
    if (tDecodeCStr(pCoder, &pSma->dstTbName) < 0) return -1;
  }

4488 4489 4490 4491
  if (tDecodeI64(pCoder, &pSma->interval) < 0) return -1;
  if (tDecodeI64(pCoder, &pSma->offset) < 0) return -1;
  if (tDecodeI64(pCoder, &pSma->sliding) < 0) return -1;
  if (pSma->exprLen > 0) {
C
Cary Xu 已提交
4492 4493 4494 4495 4496
    if (deepCopy) {
      if (tDecodeCStrAlloc(pCoder, &pSma->expr) < 0) return -1;
    } else {
      if (tDecodeCStr(pCoder, &pSma->expr) < 0) return -1;
    }
4497 4498 4499 4500
  } else {
    pSma->expr = NULL;
  }
  if (pSma->tagsFilterLen > 0) {
C
Cary Xu 已提交
4501 4502 4503 4504 4505
    if (deepCopy) {
      if (tDecodeCStrAlloc(pCoder, &pSma->tagsFilter) < 0) return -1;
    } else {
      if (tDecodeCStr(pCoder, &pSma->tagsFilter) < 0) return -1;
    }
4506 4507 4508
  } else {
    pSma->tagsFilter = NULL;
  }
C
Cary Xu 已提交
4509 4510 4511
  // only needed in dstVgroup
  tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaRow);
  tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaTag);
4512 4513 4514 4515 4516 4517

  return 0;
}

int32_t tEncodeSVCreateTSmaReq(SEncoder *pCoder, const SVCreateTSmaReq *pReq) {
  if (tStartEncode(pCoder) < 0) return -1;
C
Cary Xu 已提交
4518

4519
  tEncodeTSma(pCoder, pReq);
C
Cary Xu 已提交
4520

4521 4522
  tEndEncode(pCoder);
  return 0;
C
Cary Xu 已提交
4523
}
D
dapan1121 已提交
4524

4525 4526 4527
int32_t tDecodeSVCreateTSmaReq(SDecoder *pCoder, SVCreateTSmaReq *pReq) {
  if (tStartDecode(pCoder) < 0) return -1;

C
Cary Xu 已提交
4528
  tDecodeTSma(pCoder, pReq, false);
D
dapan1121 已提交
4529

4530 4531
  tEndDecode(pCoder);
  return 0;
C
Cary Xu 已提交
4532 4533
}

4534 4535
int32_t tEncodeSVDropTSmaReq(SEncoder *pCoder, const SVDropTSmaReq *pReq) {
  if (tStartEncode(pCoder) < 0) return -1;
C
Cary Xu 已提交
4536

4537 4538
  if (tEncodeI64(pCoder, pReq->indexUid) < 0) return -1;
  if (tEncodeCStr(pCoder, pReq->indexName) < 0) return -1;
C
Cary Xu 已提交
4539

4540 4541
  tEndEncode(pCoder);
  return 0;
C
Cary Xu 已提交
4542 4543
}

4544 4545 4546 4547
int32_t tDecodeSVDropTSmaReq(SDecoder *pCoder, SVDropTSmaReq *pReq) {
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI64(pCoder, &pReq->indexUid) < 0) return -1;
C
Cary Xu 已提交
4548
  if (tDecodeCStrTo(pCoder, pReq->indexName) < 0) return -1;
4549 4550 4551

  tEndDecode(pCoder);
  return 0;
C
Cary Xu 已提交
4552
}
L
Liu Jicong 已提交
4553

D
dapan1121 已提交
4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575
int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);
  if (buf != NULL) {
    buf = (char *)buf + headLen;
    bufLen -= headLen;
  }

  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeU64(&encoder, pReq->sId) < 0) return -1;
  if (tEncodeU64(&encoder, pReq->queryId) < 0) return -1;
  if (tEncodeU64(&encoder, pReq->taskId) < 0) return -1;
  if (tEncodeU32(&encoder, pReq->sqlLen) < 0) return -1;
  if (tEncodeU32(&encoder, pReq->phyLen) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->msg) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
C
Cary Xu 已提交
4576

D
dapan1121 已提交
4577 4578 4579 4580
  if (buf != NULL) {
    SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
    pHead->vgId = htonl(pReq->header.vgId);
    pHead->contLen = htonl(tlen + headLen);
C
Cary Xu 已提交
4581 4582
  }

D
dapan1121 已提交
4583
  return tlen + headLen;
C
Cary Xu 已提交
4584 4585
}

D
dapan1121 已提交
4586 4587
int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) {
  int32_t headLen = sizeof(SMsgHead);
C
Cary Xu 已提交
4588

D
dapan1121 已提交
4589 4590 4591
  SMsgHead *pHead = buf;
  pHead->vgId = pReq->header.vgId;
  pHead->contLen = pReq->header.contLen;
C
Cary Xu 已提交
4592

D
dapan1121 已提交
4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611
  SDecoder decoder = {0};
  tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeU64(&decoder, &pReq->sId) < 0) return -1;
  if (tDecodeU64(&decoder, &pReq->queryId) < 0) return -1;
  if (tDecodeU64(&decoder, &pReq->taskId) < 0) return -1;
  if (tDecodeU32(&decoder, &pReq->sqlLen) < 0) return -1;
  if (tDecodeU32(&decoder, &pReq->phyLen) < 0) return -1;
  pReq->sql = taosMemoryCalloc(1, pReq->sqlLen + 1);
  if (NULL == pReq->sql) return -1;
  pReq->msg = taosMemoryCalloc(1, pReq->phyLen + 1);
  if (NULL == pReq->msg) return -1;
  if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->msg) < 0) return -1;

  tEndDecode(&decoder);

  tDecoderClear(&decoder);
C
Cary Xu 已提交
4612 4613 4614
  return 0;
}

C
Cary Xu 已提交
4615
int32_t tEncodeSVDeleteRsp(SEncoder *pCoder, const SVDeleteRsp *pReq) {
C
Cary Xu 已提交
4616 4617 4618 4619 4620 4621 4622 4623
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI64(pCoder, pReq->affectedRows) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

C
Cary Xu 已提交
4624
int32_t tDecodeSVDeleteRsp(SDecoder *pCoder, SVDeleteRsp *pReq) {
C
Cary Xu 已提交
4625 4626 4627 4628 4629 4630 4631 4632
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI64(pCoder, &pReq->affectedRows) < 0) return -1;

  tEndDecode(pCoder);
  return 0;
}

L
Liu Jicong 已提交
4633
int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateStreamReq *pReq) {
L
Liu Jicong 已提交
4634 4635 4636 4637 4638
  int32_t sqlLen = 0;
  int32_t astLen = 0;
  if (pReq->sql != NULL) sqlLen = (int32_t)strlen(pReq->sql);
  if (pReq->ast != NULL) astLen = (int32_t)strlen(pReq->ast);

H
Hongze Cheng 已提交
4639 4640
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
L
Liu Jicong 已提交
4641 4642 4643

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
L
Liu Jicong 已提交
4644
  if (tEncodeCStr(&encoder, pReq->sourceDB) < 0) return -1;
L
Liu Jicong 已提交
4645
  if (tEncodeCStr(&encoder, pReq->targetStbFullName) < 0) return -1;
L
Liu Jicong 已提交
4646
  if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
L
Liu Jicong 已提交
4647 4648
  if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
  if (tEncodeI32(&encoder, astLen) < 0) return -1;
L
Liu Jicong 已提交
4649
  if (tEncodeI8(&encoder, pReq->triggerType) < 0) return -1;
4650
  if (tEncodeI64(&encoder, pReq->maxDelay) < 0) return -1;
L
Liu Jicong 已提交
4651
  if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1;
4652
  if (tEncodeI8(&encoder, pReq->igExpired) < 0) return -1;
L
Liu Jicong 已提交
4653 4654 4655
  if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
  if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1;

L
Liu Jicong 已提交
4656 4657 4658
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
4659
  tEncoderClear(&encoder);
L
Liu Jicong 已提交
4660 4661 4662 4663
  return tlen;
}

int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStreamReq *pReq) {
L
Liu Jicong 已提交
4664 4665 4666
  int32_t sqlLen = 0;
  int32_t astLen = 0;

H
Hongze Cheng 已提交
4667 4668
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
L
Liu Jicong 已提交
4669 4670 4671

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
L
Liu Jicong 已提交
4672
  if (tDecodeCStrTo(&decoder, pReq->sourceDB) < 0) return -1;
L
Liu Jicong 已提交
4673
  if (tDecodeCStrTo(&decoder, pReq->targetStbFullName) < 0) return -1;
L
Liu Jicong 已提交
4674
  if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
L
Liu Jicong 已提交
4675 4676
  if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
  if (tDecodeI32(&decoder, &astLen) < 0) return -1;
X
Xiaoyu Wang 已提交
4677
  if (tDecodeI8(&decoder, &pReq->triggerType) < 0) return -1;
4678
  if (tDecodeI64(&decoder, &pReq->maxDelay) < 0) return -1;
X
Xiaoyu Wang 已提交
4679
  if (tDecodeI64(&decoder, &pReq->watermark) < 0) return -1;
4680
  if (tDecodeI8(&decoder, &pReq->igExpired) < 0) return -1;
L
Liu Jicong 已提交
4681 4682

  if (sqlLen > 0) {
wafwerar's avatar
wafwerar 已提交
4683
    pReq->sql = taosMemoryCalloc(1, sqlLen + 1);
L
Liu Jicong 已提交
4684 4685 4686 4687 4688
    if (pReq->sql == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
  }

  if (astLen > 0) {
wafwerar's avatar
wafwerar 已提交
4689
    pReq->ast = taosMemoryCalloc(1, astLen + 1);
L
Liu Jicong 已提交
4690 4691 4692
    if (pReq->ast == NULL) return -1;
    if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1;
  }
L
Liu Jicong 已提交
4693 4694
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
4695
  tDecoderClear(&decoder);
L
Liu Jicong 已提交
4696 4697 4698
  return 0;
}

X
Xiaoyu Wang 已提交
4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727
int32_t tSerializeSMDropStreamReq(void *buf, int32_t bufLen, const SMDropStreamReq *pReq) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
  if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;

  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSMDropStreamReq(void *buf, int32_t bufLen, SMDropStreamReq *pReq) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
  if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;

  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}

L
Liu Jicong 已提交
4728
void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) {
wafwerar's avatar
wafwerar 已提交
4729 4730
  taosMemoryFreeClear(pReq->sql);
  taosMemoryFreeClear(pReq->ast);
L
Liu Jicong 已提交
4731
}
C
Cary Xu 已提交
4732

H
Hongze Cheng 已提交
4733
int32_t tEncodeSRSmaParam(SEncoder *pCoder, const SRSmaParam *pRSmaParam) {
4734 4735 4736 4737 4738 4739 4740 4741 4742
  for (int32_t i = 0; i < 2; ++i) {
    if (tEncodeI64v(pCoder, pRSmaParam->maxdelay[i]) < 0) return -1;
    if (tEncodeI64v(pCoder, pRSmaParam->watermark[i]) < 0) return -1;
    if (tEncodeI32v(pCoder, pRSmaParam->qmsgLen[i]) < 0) return -1;
    if (pRSmaParam->qmsgLen[i] > 0) {
      if (tEncodeBinary(pCoder, pRSmaParam->qmsg[i], (uint64_t)pRSmaParam->qmsgLen[i]) <
          0)  // qmsgLen contains len of '\0'
        return -1;
    }
C
Cary Xu 已提交
4743 4744 4745 4746 4747
  }

  return 0;
}

H
Hongze Cheng 已提交
4748
int32_t tDecodeSRSmaParam(SDecoder *pCoder, SRSmaParam *pRSmaParam) {
4749 4750 4751 4752 4753
  for (int32_t i = 0; i < 2; ++i) {
    if (tDecodeI64v(pCoder, &pRSmaParam->maxdelay[i]) < 0) return -1;
    if (tDecodeI64v(pCoder, &pRSmaParam->watermark[i]) < 0) return -1;
    if (tDecodeI32v(pCoder, &pRSmaParam->qmsgLen[i]) < 0) return -1;
    if (pRSmaParam->qmsgLen[i] > 0) {
C
Cary Xu 已提交
4754 4755
      tDecoderMalloc(pCoder, pRSmaParam->qmsgLen[i]);
      if (tDecodeBinary(pCoder, (uint8_t **)&pRSmaParam->qmsg[i], NULL) < 0) return -1;  // qmsgLen contains len of '\0'
4756 4757 4758
    } else {
      pRSmaParam->qmsg[i] = NULL;
    }
C
Cary Xu 已提交
4759
  }
4760

C
Cary Xu 已提交
4761 4762 4763
  return 0;
}

H
Hongze Cheng 已提交
4764
int tEncodeSVCreateStbReq(SEncoder *pCoder, const SVCreateStbReq *pReq) {
H
Hongze Cheng 已提交
4765 4766 4767 4768 4769
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
  if (tEncodeI64(pCoder, pReq->suid) < 0) return -1;
  if (tEncodeI8(pCoder, pReq->rollup) < 0) return -1;
4770
  if (tEncodeSSchemaWrapper(pCoder, &pReq->schemaRow) < 0) return -1;
H
Hongze Cheng 已提交
4771
  if (tEncodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1;
C
Cary Xu 已提交
4772
  if (pReq->rollup) {
C
Cary Xu 已提交
4773
    if (tEncodeSRSmaParam(pCoder, &pReq->rsmaParam) < 0) return -1;
C
Cary Xu 已提交
4774
  }
H
Hongze Cheng 已提交
4775 4776 4777 4778 4779

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4780
int tDecodeSVCreateStbReq(SDecoder *pCoder, SVCreateStbReq *pReq) {
H
Hongze Cheng 已提交
4781 4782 4783 4784 4785
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
  if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1;
  if (tDecodeI8(pCoder, &pReq->rollup) < 0) return -1;
4786
  if (tDecodeSSchemaWrapper(pCoder, &pReq->schemaRow) < 0) return -1;
H
Hongze Cheng 已提交
4787
  if (tDecodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1;
C
Cary Xu 已提交
4788
  if (pReq->rollup) {
C
Cary Xu 已提交
4789
    if (tDecodeSRSmaParam(pCoder, &pReq->rsmaParam) < 0) return -1;
C
Cary Xu 已提交
4790
  }
H
Hongze Cheng 已提交
4791 4792 4793 4794

  tEndDecode(pCoder);
  return 0;
}
4795

C
Cary Xu 已提交
4796 4797
STSchema *tdGetSTSChemaFromSSChema(SSchema **pSchema, int32_t nCols) {
  STSchemaBuilder schemaBuilder = {0};
C
Cary Xu 已提交
4798
  if (tdInitTSchemaBuilder(&schemaBuilder, 1) < 0) {
C
Cary Xu 已提交
4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818
    return NULL;
  }

  for (int i = 0; i < nCols; i++) {
    SSchema *schema = *pSchema + i;
    if (tdAddColToSchema(&schemaBuilder, schema->type, schema->flags, schema->colId, schema->bytes) < 0) {
      tdDestroyTSchemaBuilder(&schemaBuilder);
      return NULL;
    }
  }

  STSchema *pNSchema = tdGetSchemaFromBuilder(&schemaBuilder);
  if (pNSchema == NULL) {
    tdDestroyTSchemaBuilder(&schemaBuilder);
    return NULL;
  }

  tdDestroyTSchemaBuilder(&schemaBuilder);
  return pNSchema;
}
H
Hongze Cheng 已提交
4819

H
Hongze Cheng 已提交
4820
int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
H
Hongze Cheng 已提交
4821 4822
  if (tStartEncode(pCoder) < 0) return -1;

H
Hongze Cheng 已提交
4823
  if (tEncodeI32v(pCoder, pReq->flags) < 0) return -1;
H
Hongze Cheng 已提交
4824
  if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
H
Hongze Cheng 已提交
4825 4826 4827 4828
  if (tEncodeI64(pCoder, pReq->uid) < 0) return -1;
  if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1;
  if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1;
  if (tEncodeI8(pCoder, pReq->type) < 0) return -1;
wmmhello's avatar
wmmhello 已提交
4829 4830 4831 4832
  if (tEncodeI32(pCoder, pReq->commentLen) < 0) return -1;
  if (pReq->commentLen > 0) {
    if (tEncodeCStr(pCoder, pReq->comment) < 0) return -1;
  }
H
Hongze Cheng 已提交
4833 4834 4835

  if (pReq->type == TSDB_CHILD_TABLE) {
    if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
C
Cary Xu 已提交
4836
    if (tEncodeTag(pCoder, (const STag *)pReq->ctb.pTag) < 0) return -1;
H
Hongze Cheng 已提交
4837
  } else if (pReq->type == TSDB_NORMAL_TABLE) {
4838
    if (tEncodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
H
Hongze Cheng 已提交
4839 4840 4841 4842 4843 4844 4845 4846
  } else {
    ASSERT(0);
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4847
int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
H
Hongze Cheng 已提交
4848 4849
  if (tStartDecode(pCoder) < 0) return -1;

H
Hongze Cheng 已提交
4850
  if (tDecodeI32v(pCoder, &pReq->flags) < 0) return -1;
H
Hongze Cheng 已提交
4851
  if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
H
Hongze Cheng 已提交
4852 4853 4854 4855
  if (tDecodeI64(pCoder, &pReq->uid) < 0) return -1;
  if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1;
  if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1;
  if (tDecodeI8(pCoder, &pReq->type) < 0) return -1;
wmmhello's avatar
wmmhello 已提交
4856 4857
  if (tDecodeI32(pCoder, &pReq->commentLen) < 0) return -1;
  if (pReq->commentLen > 0) {
wmmhello's avatar
wmmhello 已提交
4858
    pReq->comment = taosMemoryMalloc(pReq->commentLen + 1);
wmmhello's avatar
wmmhello 已提交
4859 4860 4861
    if (pReq->comment == NULL) return -1;
    if (tDecodeCStrTo(pCoder, pReq->comment) < 0) return -1;
  }
H
Hongze Cheng 已提交
4862 4863 4864

  if (pReq->type == TSDB_CHILD_TABLE) {
    if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
C
Cary Xu 已提交
4865
    if (tDecodeTag(pCoder, (STag **)&pReq->ctb.pTag) < 0) return -1;
H
Hongze Cheng 已提交
4866
  } else if (pReq->type == TSDB_NORMAL_TABLE) {
4867
    if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
H
Hongze Cheng 已提交
4868 4869 4870 4871
  } else {
    ASSERT(0);
  }

H
Hongze Cheng 已提交
4872 4873 4874 4875
  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4876
int tEncodeSVCreateTbBatchReq(SEncoder *pCoder, const SVCreateTbBatchReq *pReq) {
H
Hongze Cheng 已提交
4877 4878
  int32_t nReq = taosArrayGetSize(pReq->pArray);

H
Hongze Cheng 已提交
4879 4880
  if (tStartEncode(pCoder) < 0) return -1;

H
Hongze Cheng 已提交
4881 4882
  if (tEncodeI32v(pCoder, nReq) < 0) return -1;
  for (int iReq = 0; iReq < nReq; iReq++) {
H
Hongze Cheng 已提交
4883 4884 4885 4886 4887 4888 4889
    if (tEncodeSVCreateTbReq(pCoder, (SVCreateTbReq *)taosArrayGet(pReq->pArray, iReq)) < 0) return -1;
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4890
int tDecodeSVCreateTbBatchReq(SDecoder *pCoder, SVCreateTbBatchReq *pReq) {
H
Hongze Cheng 已提交
4891 4892 4893
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32v(pCoder, &pReq->nReqs) < 0) return -1;
H
Hongze Cheng 已提交
4894
  pReq->pReqs = (SVCreateTbReq *)tDecoderMalloc(pCoder, sizeof(SVCreateTbReq) * pReq->nReqs);
H
Hongze Cheng 已提交
4895 4896 4897 4898 4899
  if (pReq->pReqs == NULL) return -1;
  for (int iReq = 0; iReq < pReq->nReqs; iReq++) {
    if (tDecodeSVCreateTbReq(pCoder, pReq->pReqs + iReq) < 0) return -1;
  }

H
Hongze Cheng 已提交
4900 4901 4902 4903
  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4904
int tEncodeSVCreateTbRsp(SEncoder *pCoder, const SVCreateTbRsp *pRsp) {
H
Hongze Cheng 已提交
4905 4906 4907 4908 4909 4910 4911 4912
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32(pCoder, pRsp->code) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4913
int tDecodeSVCreateTbRsp(SDecoder *pCoder, SVCreateTbRsp *pRsp) {
H
Hongze Cheng 已提交
4914 4915 4916 4917
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32(pCoder, &pRsp->code) < 0) return -1;

H
Hongze Cheng 已提交
4918 4919 4920 4921 4922
  tEndDecode(pCoder);
  return 0;
}

// TDMT_VND_DROP_TABLE =================
H
Hongze Cheng 已提交
4923
static int32_t tEncodeSVDropTbReq(SEncoder *pCoder, const SVDropTbReq *pReq) {
H
Hongze Cheng 已提交
4924 4925 4926
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
X
Xiaoyu Wang 已提交
4927
  if (tEncodeI8(pCoder, pReq->igNotExists) < 0) return -1;
H
Hongze Cheng 已提交
4928 4929 4930 4931 4932

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4933
static int32_t tDecodeSVDropTbReq(SDecoder *pCoder, SVDropTbReq *pReq) {
H
Hongze Cheng 已提交
4934 4935 4936
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
X
Xiaoyu Wang 已提交
4937
  if (tDecodeI8(pCoder, &pReq->igNotExists) < 0) return -1;
H
Hongze Cheng 已提交
4938 4939 4940 4941 4942

  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4943
static int32_t tEncodeSVDropTbRsp(SEncoder *pCoder, const SVDropTbRsp *pReq) {
H
Hongze Cheng 已提交
4944 4945 4946 4947 4948 4949 4950 4951
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32(pCoder, pReq->code) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4952
static int32_t tDecodeSVDropTbRsp(SDecoder *pCoder, SVDropTbRsp *pReq) {
H
Hongze Cheng 已提交
4953 4954 4955 4956 4957 4958 4959 4960
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32(pCoder, &pReq->code) < 0) return -1;

  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4961
int32_t tEncodeSVDropTbBatchReq(SEncoder *pCoder, const SVDropTbBatchReq *pReq) {
H
Hongze Cheng 已提交
4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976
  int32_t      nReqs = taosArrayGetSize(pReq->pArray);
  SVDropTbReq *pDropTbReq;

  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32v(pCoder, nReqs) < 0) return -1;
  for (int iReq = 0; iReq < nReqs; iReq++) {
    pDropTbReq = (SVDropTbReq *)taosArrayGet(pReq->pArray, iReq);
    if (tEncodeSVDropTbReq(pCoder, pDropTbReq) < 0) return -1;
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4977
int32_t tDecodeSVDropTbBatchReq(SDecoder *pCoder, SVDropTbBatchReq *pReq) {
H
Hongze Cheng 已提交
4978 4979 4980
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32v(pCoder, &pReq->nReqs) < 0) return -1;
H
Hongze Cheng 已提交
4981
  pReq->pReqs = (SVDropTbReq *)tDecoderMalloc(pCoder, sizeof(SVDropTbReq) * pReq->nReqs);
H
Hongze Cheng 已提交
4982 4983 4984 4985 4986 4987 4988 4989 4990
  if (pReq->pReqs == NULL) return -1;
  for (int iReq = 0; iReq < pReq->nReqs; iReq++) {
    if (tDecodeSVDropTbReq(pCoder, pReq->pReqs + iReq) < 0) return -1;
  }

  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
4991
int32_t tEncodeSVDropTbBatchRsp(SEncoder *pCoder, const SVDropTbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003
  int32_t nRsps = taosArrayGetSize(pRsp->pArray);
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32v(pCoder, nRsps) < 0) return -1;
  for (int iRsp = 0; iRsp < nRsps; iRsp++) {
    if (tEncodeSVDropTbRsp(pCoder, (SVDropTbRsp *)taosArrayGet(pRsp->pArray, iRsp)) < 0) return -1;
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
5004
int32_t tDecodeSVDropTbBatchRsp(SDecoder *pCoder, SVDropTbBatchRsp *pRsp) {
H
Hongze Cheng 已提交
5005 5006 5007
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32v(pCoder, &pRsp->nRsps) < 0) return -1;
H
Hongze Cheng 已提交
5008
  pRsp->pRsps = (SVDropTbRsp *)tDecoderMalloc(pCoder, sizeof(SVDropTbRsp) * pRsp->nRsps);
H
Hongze Cheng 已提交
5009 5010 5011 5012 5013 5014 5015 5016 5017
  if (pRsp->pRsps == NULL) return -1;
  for (int iRsp = 0; iRsp < pRsp->nRsps; iRsp++) {
    if (tDecodeSVDropTbRsp(pCoder, pRsp->pRsps + iRsp) < 0) return -1;
  }

  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
5018
int32_t tEncodeSVDropStbReq(SEncoder *pCoder, const SVDropStbReq *pReq) {
H
Hongze Cheng 已提交
5019 5020 5021 5022 5023 5024 5025 5026 5027
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
  if (tEncodeI64(pCoder, pReq->suid) < 0) return -1;

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
5028
int32_t tDecodeSVDropStbReq(SDecoder *pCoder, SVDropStbReq *pReq) {
H
Hongze Cheng 已提交
5029 5030 5031 5032 5033
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
  if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1;

H
Hongze Cheng 已提交
5034 5035
  tEndDecode(pCoder);
  return 0;
5036
}
H
Hongze Cheng 已提交
5037

H
Hongze Cheng 已提交
5038
static int32_t tEncodeSVSubmitBlk(SEncoder *pCoder, const SVSubmitBlk *pBlock, int32_t flags) {
H
Hongze Cheng 已提交
5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053
  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI64(pCoder, pBlock->suid) < 0) return -1;
  if (tEncodeI64(pCoder, pBlock->uid) < 0) return -1;
  if (tEncodeI32v(pCoder, pBlock->sver) < 0) return -1;
  if (tEncodeBinary(pCoder, pBlock->pData, pBlock->nData) < 0) return -1;

  if (flags & TD_AUTO_CREATE_TABLE) {
    if (tEncodeSVCreateTbReq(pCoder, &pBlock->cTbReq) < 0) return -1;
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
5054
static int32_t tDecodeSVSubmitBlk(SDecoder *pCoder, SVSubmitBlk *pBlock, int32_t flags) {
H
Hongze Cheng 已提交
5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI64(pCoder, &pBlock->suid) < 0) return -1;
  if (tDecodeI64(pCoder, &pBlock->uid) < 0) return -1;
  if (tDecodeI32v(pCoder, &pBlock->sver) < 0) return -1;
  if (tDecodeBinary(pCoder, &pBlock->pData, &pBlock->nData) < 0) return -1;

  if (flags & TD_AUTO_CREATE_TABLE) {
    if (tDecodeSVCreateTbReq(pCoder, &pBlock->cTbReq) < 0) return -1;
  }

  tEndDecode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
5070
int32_t tEncodeSVSubmitReq(SEncoder *pCoder, const SVSubmitReq *pReq) {
H
Hongze Cheng 已提交
5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084
  int32_t nBlocks = taosArrayGetSize(pReq->pArray);

  if (tStartEncode(pCoder) < 0) return -1;

  if (tEncodeI32v(pCoder, pReq->flags) < 0) return -1;
  if (tEncodeI32v(pCoder, nBlocks) < 0) return -1;
  for (int32_t iBlock = 0; iBlock < nBlocks; iBlock++) {
    if (tEncodeSVSubmitBlk(pCoder, (SVSubmitBlk *)taosArrayGet(pReq->pArray, iBlock), pReq->flags) < 0) return -1;
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
5085
int32_t tDecodeSVSubmitReq(SDecoder *pCoder, SVSubmitReq *pReq) {
H
Hongze Cheng 已提交
5086 5087 5088 5089
  if (tStartDecode(pCoder) < 0) return -1;

  if (tDecodeI32v(pCoder, &pReq->flags) < 0) return -1;
  if (tDecodeI32v(pCoder, &pReq->nBlocks) < 0) return -1;
H
Hongze Cheng 已提交
5090
  pReq->pBlocks = tDecoderMalloc(pCoder, sizeof(SVSubmitBlk) * pReq->nBlocks);
H
Hongze Cheng 已提交
5091 5092 5093 5094 5095 5096 5097
  if (pReq->pBlocks == NULL) return -1;
  for (int32_t iBlock = 0; iBlock < pReq->nBlocks; iBlock++) {
    if (tDecodeSVSubmitBlk(pCoder, pReq->pBlocks + iBlock, pReq->flags) < 0) return -1;
  }

  tEndDecode(pCoder);
  return 0;
L
Liu Jicong 已提交
5098
}
H
Hongze Cheng 已提交
5099 5100 5101 5102

static int32_t tEncodeSSubmitBlkRsp(SEncoder *pEncoder, const SSubmitBlkRsp *pBlock) {
  if (tStartEncode(pEncoder) < 0) return -1;

H
Hongze Cheng 已提交
5103
  if (tEncodeI32(pEncoder, pBlock->code) < 0) return -1;
H
Hongze Cheng 已提交
5104
  if (tEncodeI8(pEncoder, pBlock->hashMeta) < 0) return -1;
D
dapan1121 已提交
5105 5106
  if (tEncodeI64(pEncoder, pBlock->uid) < 0) return -1;
  if (tEncodeCStr(pEncoder, pBlock->tblFName) < 0) return -1;
H
Hongze Cheng 已提交
5107 5108
  if (tEncodeI32v(pEncoder, pBlock->numOfRows) < 0) return -1;
  if (tEncodeI32v(pEncoder, pBlock->affectedRows) < 0) return -1;
H
Hongze Cheng 已提交
5109
  if (tEncodeI64v(pEncoder, pBlock->sver) < 0) return -1;
H
Hongze Cheng 已提交
5110 5111 5112 5113 5114 5115 5116 5117

  tEndEncode(pEncoder);
  return 0;
}

static int32_t tDecodeSSubmitBlkRsp(SDecoder *pDecoder, SSubmitBlkRsp *pBlock) {
  if (tStartDecode(pDecoder) < 0) return -1;

H
Hongze Cheng 已提交
5118
  if (tDecodeI32(pDecoder, &pBlock->code) < 0) return -1;
H
Hongze Cheng 已提交
5119
  if (tDecodeI8(pDecoder, &pBlock->hashMeta) < 0) return -1;
D
dapan1121 已提交
5120 5121 5122 5123
  if (tDecodeI64(pDecoder, &pBlock->uid) < 0) return -1;
  pBlock->tblFName = taosMemoryCalloc(TSDB_TABLE_FNAME_LEN, 1);
  if (NULL == pBlock->tblFName) return -1;
  if (tDecodeCStrTo(pDecoder, pBlock->tblFName) < 0) return -1;
H
Hongze Cheng 已提交
5124 5125
  if (tDecodeI32v(pDecoder, &pBlock->numOfRows) < 0) return -1;
  if (tDecodeI32v(pDecoder, &pBlock->affectedRows) < 0) return -1;
H
Hongze Cheng 已提交
5126
  if (tDecodeI64v(pDecoder, &pBlock->sver) < 0) return -1;
H
Hongze Cheng 已提交
5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153

  tEndDecode(pDecoder);
  return 0;
}

int32_t tEncodeSSubmitRsp(SEncoder *pEncoder, const SSubmitRsp *pRsp) {
  int32_t nBlocks = taosArrayGetSize(pRsp->pArray);

  if (tStartEncode(pEncoder) < 0) return -1;

  if (tEncodeI32v(pEncoder, pRsp->numOfRows) < 0) return -1;
  if (tEncodeI32v(pEncoder, pRsp->affectedRows) < 0) return -1;
  if (tEncodeI32v(pEncoder, nBlocks) < 0) return -1;
  for (int32_t iBlock = 0; iBlock < nBlocks; iBlock++) {
    if (tEncodeSSubmitBlkRsp(pEncoder, (SSubmitBlkRsp *)taosArrayGet(pRsp->pArray, iBlock)) < 0) return -1;
  }

  tEndEncode(pEncoder);
  return 0;
}

int32_t tDecodeSSubmitRsp(SDecoder *pDecoder, SSubmitRsp *pRsp) {
  if (tStartDecode(pDecoder) < 0) return -1;

  if (tDecodeI32v(pDecoder, &pRsp->numOfRows) < 0) return -1;
  if (tDecodeI32v(pDecoder, &pRsp->affectedRows) < 0) return -1;
  if (tDecodeI32v(pDecoder, &pRsp->nBlocks) < 0) return -1;
D
dapan 已提交
5154
  pRsp->pBlocks = taosMemoryCalloc(pRsp->nBlocks, sizeof(*pRsp->pBlocks));
H
Hongze Cheng 已提交
5155 5156 5157 5158 5159
  if (pRsp->pBlocks == NULL) return -1;
  for (int32_t iBlock = 0; iBlock < pRsp->nBlocks; iBlock++) {
    if (tDecodeSSubmitBlkRsp(pDecoder, pRsp->pBlocks + iBlock) < 0) return -1;
  }

H
Hongze Cheng 已提交
5160
  tEndDecode(pDecoder);
D
dapan 已提交
5161
  tDecoderClear(pDecoder);
H
Hongze Cheng 已提交
5162 5163
  return 0;
}
D
dapan 已提交
5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178

void tFreeSSubmitRsp(SSubmitRsp *pRsp) {
  if (NULL == pRsp) return;

  if (pRsp->pBlocks) {
    for (int32_t i = 0; i < pRsp->nBlocks; ++i) {
      SSubmitBlkRsp *sRsp = pRsp->pBlocks + i;
      taosMemoryFree(sRsp->tblFName);
    }

    taosMemoryFree(pRsp->pBlocks);
  }

  taosMemoryFree(pRsp);
}
H
Hongze Cheng 已提交
5179 5180 5181 5182 5183 5184 5185 5186

int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
  if (tStartEncode(pEncoder) < 0) return -1;

  if (tEncodeCStr(pEncoder, pReq->tbName) < 0) return -1;
  if (tEncodeI8(pEncoder, pReq->action) < 0) return -1;
  switch (pReq->action) {
    case TSDB_ALTER_TABLE_ADD_COLUMN:
H
fix  
Hongze Cheng 已提交
5187
      if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5188
      if (tEncodeI8(pEncoder, pReq->type) < 0) return -1;
H
Hongze Cheng 已提交
5189
      if (tEncodeI8(pEncoder, pReq->flags) < 0) return -1;
H
Hongze Cheng 已提交
5190 5191 5192
      if (tEncodeI32v(pEncoder, pReq->bytes) < 0) return -1;
      break;
    case TSDB_ALTER_TABLE_DROP_COLUMN:
H
fix  
Hongze Cheng 已提交
5193
      if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5194 5195
      break;
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
H
fix  
Hongze Cheng 已提交
5196
      if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5197 5198 5199
      if (tEncodeI32v(pEncoder, pReq->colModBytes) < 0) return -1;
      break;
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
H
fix  
Hongze Cheng 已提交
5200
      if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214
      if (tEncodeCStr(pEncoder, pReq->colNewName) < 0) return -1;
      break;
    case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:
      if (tEncodeCStr(pEncoder, pReq->tagName) < 0) return -1;
      if (tEncodeI8(pEncoder, pReq->isNull) < 0) return -1;
      if (!pReq->isNull) {
        if (tEncodeBinary(pEncoder, pReq->pTagVal, pReq->nTagVal) < 0) return -1;
      }
      break;
    case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
      if (tEncodeI8(pEncoder, pReq->updateTTL) < 0) return -1;
      if (pReq->updateTTL) {
        if (tEncodeI32v(pEncoder, pReq->newTTL) < 0) return -1;
      }
wmmhello's avatar
wmmhello 已提交
5215 5216
      if (tEncodeI32v(pEncoder, pReq->newCommentLen) < 0) return -1;
      if (pReq->newCommentLen > 0) {
H
Hongze Cheng 已提交
5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234
        if (tEncodeCStr(pEncoder, pReq->newComment) < 0) return -1;
      }
      break;
    default:
      break;
  }

  tEndEncode(pEncoder);
  return 0;
}

int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
  if (tStartDecode(pDecoder) < 0) return -1;

  if (tDecodeCStr(pDecoder, &pReq->tbName) < 0) return -1;
  if (tDecodeI8(pDecoder, &pReq->action) < 0) return -1;
  switch (pReq->action) {
    case TSDB_ALTER_TABLE_ADD_COLUMN:
H
fix  
Hongze Cheng 已提交
5235
      if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5236
      if (tDecodeI8(pDecoder, &pReq->type) < 0) return -1;
H
Hongze Cheng 已提交
5237
      if (tDecodeI8(pDecoder, &pReq->flags) < 0) return -1;
H
Hongze Cheng 已提交
5238 5239 5240
      if (tDecodeI32v(pDecoder, &pReq->bytes) < 0) return -1;
      break;
    case TSDB_ALTER_TABLE_DROP_COLUMN:
H
fix  
Hongze Cheng 已提交
5241
      if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5242 5243
      break;
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
H
fix  
Hongze Cheng 已提交
5244
      if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5245 5246 5247
      if (tDecodeI32v(pDecoder, &pReq->colModBytes) < 0) return -1;
      break;
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
H
fix  
Hongze Cheng 已提交
5248
      if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1;
H
Hongze Cheng 已提交
5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262
      if (tDecodeCStr(pDecoder, &pReq->colNewName) < 0) return -1;
      break;
    case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:
      if (tDecodeCStr(pDecoder, &pReq->tagName) < 0) return -1;
      if (tDecodeI8(pDecoder, &pReq->isNull) < 0) return -1;
      if (!pReq->isNull) {
        if (tDecodeBinary(pDecoder, &pReq->pTagVal, &pReq->nTagVal) < 0) return -1;
      }
      break;
    case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
      if (tDecodeI8(pDecoder, &pReq->updateTTL) < 0) return -1;
      if (pReq->updateTTL) {
        if (tDecodeI32v(pDecoder, &pReq->newTTL) < 0) return -1;
      }
wmmhello's avatar
wmmhello 已提交
5263 5264
      if (tDecodeI32v(pDecoder, &pReq->newCommentLen) < 0) return -1;
      if (pReq->newCommentLen > 0) {
H
Hongze Cheng 已提交
5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278
        if (tDecodeCStr(pDecoder, &pReq->newComment) < 0) return -1;
      }
      break;
    default:
      break;
  }

  tEndDecode(pDecoder);
  return 0;
}

int32_t tEncodeSVAlterTbRsp(SEncoder *pEncoder, const SVAlterTbRsp *pRsp) {
  if (tStartEncode(pEncoder) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->code) < 0) return -1;
D
dapan1121 已提交
5279 5280 5281 5282
  if (tEncodeI32(pEncoder, pRsp->pMeta ? 1 : 0) < 0) return -1;
  if (pRsp->pMeta) {
    if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1;
  }
H
Hongze Cheng 已提交
5283 5284 5285 5286 5287
  tEndEncode(pEncoder);
  return 0;
}

int32_t tDecodeSVAlterTbRsp(SDecoder *pDecoder, SVAlterTbRsp *pRsp) {
D
dapan1121 已提交
5288
  int32_t meta = 0;
H
Hongze Cheng 已提交
5289 5290
  if (tStartDecode(pDecoder) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->code) < 0) return -1;
D
dapan1121 已提交
5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301
  if (tDecodeI32(pDecoder, &meta) < 0) return -1;
  if (meta) {
    pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
    if (NULL == pRsp->pMeta) return -1;
    if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1;
  }
  tEndDecode(pDecoder);
  return 0;
}

int32_t tDeserializeSVAlterTbRsp(void *buf, int32_t bufLen, SVAlterTbRsp *pRsp) {
C
Cary Xu 已提交
5302
  int32_t  meta = 0;
D
dapan1121 已提交
5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &pRsp->code) < 0) return -1;
  if (tDecodeI32(&decoder, &meta) < 0) return -1;
  if (meta) {
    pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
    if (NULL == pRsp->pMeta) return -1;
    if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1;
  }
  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

int32_t tEncodeSMAlterStbRsp(SEncoder *pEncoder, const SMAlterStbRsp *pRsp) {
  if (tStartEncode(pEncoder) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->pMeta->pSchemas ? 1 : 0) < 0) return -1;
  if (pRsp->pMeta->pSchemas) {
    if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1;
  }
  tEndEncode(pEncoder);
  return 0;
}

int32_t tDecodeSMAlterStbRsp(SDecoder *pDecoder, SMAlterStbRsp *pRsp) {
  int32_t meta = 0;
  if (tStartDecode(pDecoder) < 0) return -1;
  if (tDecodeI32(pDecoder, &meta) < 0) return -1;
  if (meta) {
    pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
    if (NULL == pRsp->pMeta) return -1;
    if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1;
  }
H
Hongze Cheng 已提交
5338 5339 5340
  tEndDecode(pDecoder);
  return 0;
}
D
dapan1121 已提交
5341 5342

int32_t tDeserializeSMAlterStbRsp(void *buf, int32_t bufLen, SMAlterStbRsp *pRsp) {
C
Cary Xu 已提交
5343
  int32_t  meta = 0;
D
dapan1121 已提交
5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI32(&decoder, &meta) < 0) return -1;
  if (meta) {
    pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
    if (NULL == pRsp->pMeta) return -1;
    if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1;
  }
  tEndDecode(&decoder);
  tDecoderClear(&decoder);
  return 0;
}

C
Cary Xu 已提交
5359
void tFreeSMAlterStbRsp(SMAlterStbRsp *pRsp) {
D
dapan1121 已提交
5360 5361 5362 5363 5364 5365 5366 5367 5368
  if (NULL == pRsp) {
    return;
  }

  if (pRsp->pMeta) {
    taosMemoryFree(pRsp->pMeta->pSchemas);
    taosMemoryFree(pRsp->pMeta);
  }
}
5369

L
Liu Jicong 已提交
5370 5371 5372 5373 5374 5375 5376 5377 5378
int32_t tEncodeSTqOffsetVal(SEncoder *pEncoder, const STqOffsetVal *pOffsetVal) {
  if (tEncodeI8(pEncoder, pOffsetVal->type) < 0) return -1;
  if (pOffsetVal->type == TMQ_OFFSET__SNAPSHOT_DATA) {
    if (tEncodeI64(pEncoder, pOffsetVal->uid) < 0) return -1;
    if (tEncodeI64(pEncoder, pOffsetVal->ts) < 0) return -1;
  } else if (pOffsetVal->type == TMQ_OFFSET__LOG) {
    if (tEncodeI64(pEncoder, pOffsetVal->version) < 0) return -1;
  } else if (pOffsetVal->type < 0) {
    // do nothing
5379 5380 5381 5382 5383 5384
  } else {
    ASSERT(0);
  }
  return 0;
}

L
Liu Jicong 已提交
5385 5386 5387 5388 5389 5390 5391 5392 5393
int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) {
  if (tDecodeI8(pDecoder, &pOffsetVal->type) < 0) return -1;
  if (pOffsetVal->type == TMQ_OFFSET__SNAPSHOT_DATA) {
    if (tDecodeI64(pDecoder, &pOffsetVal->uid) < 0) return -1;
    if (tDecodeI64(pDecoder, &pOffsetVal->ts) < 0) return -1;
  } else if (pOffsetVal->type == TMQ_OFFSET__LOG) {
    if (tDecodeI64(pDecoder, &pOffsetVal->version) < 0) return -1;
  } else if (pOffsetVal->type < 0) {
    // do nothing
5394 5395 5396
  } else {
    ASSERT(0);
  }
L
Liu Jicong 已提交
5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410
  return 0;
}

#if 1
int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) {
  if (pVal->type == TMQ_OFFSET__RESET_NONE) {
    snprintf(buf, maxLen, "offset(reset to none)");
  } else if (pVal->type == TMQ_OFFSET__RESET_EARLIEAST) {
    snprintf(buf, maxLen, "offset(reset to earlieast)");
  } else if (pVal->type == TMQ_OFFSET__RESET_LATEST) {
    snprintf(buf, maxLen, "offset(reset to latest)");
  } else if (pVal->type == TMQ_OFFSET__LOG) {
    snprintf(buf, maxLen, "offset(log) ver:%ld", pVal->version);
  } else if (pVal->type == TMQ_OFFSET__SNAPSHOT_DATA) {
L
Liu Jicong 已提交
5411
    snprintf(buf, maxLen, "offset(ss data) uid:%ld, ts:%ld", pVal->uid, pVal->ts);
L
Liu Jicong 已提交
5412
  } else if (pVal->type == TMQ_OFFSET__SNAPSHOT_META) {
L
Liu Jicong 已提交
5413
    snprintf(buf, maxLen, "offset(ss meta) uid:%ld, ts:%ld", pVal->uid, pVal->ts);
5414 5415 5416
  } else {
    ASSERT(0);
  }
L
Liu Jicong 已提交
5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443
  return 0;
}
#endif

bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) {
  if (pLeft->type == pRight->type) {
    if (pLeft->type == TMQ_OFFSET__LOG) {
      return pLeft->version == pRight->version;
    } else if (pLeft->type == TMQ_OFFSET__SNAPSHOT_DATA) {
      return pLeft->uid == pRight->uid && pLeft->ts == pRight->ts;
    } else if (pLeft->type == TMQ_OFFSET__SNAPSHOT_META) {
      ASSERT(0);
      // TODO
      return pLeft->uid == pRight->uid && pLeft->ts == pRight->ts;
    }
  }
  return false;
}

int32_t tEncodeSTqOffset(SEncoder *pEncoder, const STqOffset *pOffset) {
  if (tEncodeSTqOffsetVal(pEncoder, &pOffset->val) < 0) return -1;
  if (tEncodeCStr(pEncoder, pOffset->subKey) < 0) return -1;
  return 0;
}

int32_t tDecodeSTqOffset(SDecoder *pDecoder, STqOffset *pOffset) {
  if (tDecodeSTqOffsetVal(pDecoder, &pOffset->val) < 0) return -1;
5444 5445 5446
  if (tDecodeCStrTo(pDecoder, pOffset->subKey) < 0) return -1;
  return 0;
}
H
Hongze Cheng 已提交
5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477

int32_t tEncodeDeleteRes(SEncoder *pCoder, const SDeleteRes *pRes) {
  int32_t nUid = taosArrayGetSize(pRes->uidList);

  if (tEncodeU64(pCoder, pRes->suid) < 0) return -1;
  if (tEncodeI32v(pCoder, nUid) < 0) return -1;
  for (int32_t iUid = 0; iUid < nUid; iUid++) {
    if (tEncodeU64(pCoder, *(uint64_t *)taosArrayGet(pRes->uidList, iUid)) < 0) return -1;
  }
  if (tEncodeI64(pCoder, pRes->skey) < 0) return -1;
  if (tEncodeI64(pCoder, pRes->ekey) < 0) return -1;
  if (tEncodeI64v(pCoder, pRes->affectedRows) < 0) return -1;

  return 0;
}

int32_t tDecodeDeleteRes(SDecoder *pCoder, SDeleteRes *pRes) {
  int32_t  nUid;
  uint64_t uid;

  if (tDecodeU64(pCoder, &pRes->suid) < 0) return -1;
  if (tDecodeI32v(pCoder, &nUid) < 0) return -1;
  for (int32_t iUid = 0; iUid < nUid; iUid++) {
    if (tDecodeU64(pCoder, &uid) < 0) return -1;
    taosArrayPush(pRes->uidList, &uid);
  }
  if (tDecodeI64(pCoder, &pRes->skey) < 0) return -1;
  if (tDecodeI64(pCoder, &pRes->ekey) < 0) return -1;
  if (tDecodeI64v(pCoder, &pRes->affectedRows) < 0) return -1;

  return 0;
5478
}
L
Liu Jicong 已提交
5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545
int32_t tEncodeSMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pRsp) {
  if (tEncodeSTqOffsetVal(pEncoder, &pRsp->reqOffset) < 0) return -1;
  if (tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->skipLogNum) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->blockNum) < 0) return -1;
  if (pRsp->blockNum != 0) {
    if (tEncodeI8(pEncoder, pRsp->withTbName) < 0) return -1;
    if (tEncodeI8(pEncoder, pRsp->withSchema) < 0) return -1;

    for (int32_t i = 0; i < pRsp->blockNum; i++) {
      int32_t bLen = *(int32_t *)taosArrayGet(pRsp->blockDataLen, i);
      void   *data = taosArrayGetP(pRsp->blockData, i);
      if (tEncodeBinary(pEncoder, (const uint8_t *)data, bLen) < 0) return -1;
      if (pRsp->withSchema) {
        SSchemaWrapper *pSW = (SSchemaWrapper *)taosArrayGetP(pRsp->blockSchema, i);
        if (tEncodeSSchemaWrapper(pEncoder, pSW) < 0) return -1;
      }
      if (pRsp->withTbName) {
        char *tbName = (char *)taosArrayGetP(pRsp->blockTbName, i);
        if (tEncodeCStr(pEncoder, tbName) < 0) return -1;
      }
    }
  }
  return 0;
}

int32_t tDecodeSMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) {
  if (tDecodeSTqOffsetVal(pDecoder, &pRsp->reqOffset) < 0) return -1;
  if (tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->skipLogNum) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->blockNum) < 0) return -1;
  if (pRsp->blockNum != 0) {
    pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void *));
    pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(int32_t));
    if (tDecodeI8(pDecoder, &pRsp->withTbName) < 0) return -1;
    if (tDecodeI8(pDecoder, &pRsp->withSchema) < 0) return -1;
    if (pRsp->withTbName) {
      pRsp->blockTbName = taosArrayInit(pRsp->blockNum, sizeof(void *));
    }
    if (pRsp->withSchema) {
      pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void *));
    }

    for (int32_t i = 0; i < pRsp->blockNum; i++) {
      void    *data;
      uint64_t bLen;
      if (tDecodeBinaryAlloc(pDecoder, &data, &bLen) < 0) return -1;
      taosArrayPush(pRsp->blockData, &data);
      int32_t len = bLen;
      taosArrayPush(pRsp->blockDataLen, &len);

      if (pRsp->withSchema) {
        SSchemaWrapper *pSW = (SSchemaWrapper *)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
        if (pSW == NULL) return -1;
        if (tDecodeSSchemaWrapper(pDecoder, pSW) < 0) return -1;
        taosArrayPush(pRsp->blockSchema, &pSW);
      }

      if (pRsp->withTbName) {
        char *tbName;
        if (tDecodeCStrAlloc(pDecoder, &tbName) < 0) return -1;
        taosArrayPush(pRsp->blockTbName, &tbName);
      }
    }
  }
  return 0;
}