metaEntry.c 4.7 KB
Newer Older
H
Hongze Cheng 已提交
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/>.
 */

H
Hongze Cheng 已提交
16
#include "meta.h"
H
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
H
Hongze Cheng 已提交
19 20
  if (tStartEncode(pCoder) < 0) return -1;

H
Hongze Cheng 已提交
21
  if (tEncodeI64(pCoder, pME->version) < 0) return -1;
H
Hongze Cheng 已提交
22 23
  if (tEncodeI8(pCoder, pME->type) < 0) return -1;
  if (tEncodeI64(pCoder, pME->uid) < 0) return -1;
M
Minglei Jin 已提交
24
  if (pME->name == NULL || tEncodeCStr(pCoder, pME->name) < 0) return -1;
H
Hongze Cheng 已提交
25 26

  if (pME->type == TSDB_SUPER_TABLE) {
C
Cary Xu 已提交
27
    if (tEncodeI8(pCoder, pME->flags) < 0) return -1;  // TODO: need refactor?
28
    if (tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow) < 0) return -1;
H
Hongze Cheng 已提交
29
    if (tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
C
Cary Xu 已提交
30 31 32
    if (TABLE_IS_ROLLUP(pME->flags)) {
      if (tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam) < 0) return -1;
    }
H
Hongze Cheng 已提交
33 34 35
  } else if (pME->type == TSDB_CHILD_TABLE) {
    if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1;
    if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1;
C
Cary Xu 已提交
36
    if (tEncodeI32v(pCoder, pME->ctbEntry.commentLen) < 0) return -1;
H
Hongze Cheng 已提交
37
    if (pME->ctbEntry.commentLen > 0) {
wmmhello's avatar
wmmhello 已提交
38 39
      if (tEncodeCStr(pCoder, pME->ctbEntry.comment) < 0) return -1;
    }
H
Hongze Cheng 已提交
40
    if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1;
C
Cary Xu 已提交
41
    if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1;
H
Hongze Cheng 已提交
42 43 44
  } else if (pME->type == TSDB_NORMAL_TABLE) {
    if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1;
    if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1;
C
Cary Xu 已提交
45
    if (tEncodeI32v(pCoder, pME->ntbEntry.commentLen) < 0) return -1;
H
Hongze Cheng 已提交
46
    if (pME->ntbEntry.commentLen > 0) {
wmmhello's avatar
wmmhello 已提交
47 48
      if (tEncodeCStr(pCoder, pME->ntbEntry.comment) < 0) return -1;
    }
H
Hongze Cheng 已提交
49
    if (tEncodeI32v(pCoder, pME->ntbEntry.ncid) < 0) return -1;
50
    if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1;
51
  } else if (pME->type == TSDB_TSMA_TABLE) {
C
Cary Xu 已提交
52
    if (tEncodeTSma(pCoder, pME->smaEntry.tsma) < 0) return -1;
H
Hongze Cheng 已提交
53
  } else {
54 55 56
    metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);

    return -1;
H
Hongze Cheng 已提交
57 58 59 60 61 62
  }

  tEndEncode(pCoder);
  return 0;
}

H
Hongze Cheng 已提交
63
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
H
Hongze Cheng 已提交
64 65
  if (tStartDecode(pCoder) < 0) return -1;

H
Hongze Cheng 已提交
66
  if (tDecodeI64(pCoder, &pME->version) < 0) return -1;
H
Hongze Cheng 已提交
67 68 69 70 71
  if (tDecodeI8(pCoder, &pME->type) < 0) return -1;
  if (tDecodeI64(pCoder, &pME->uid) < 0) return -1;
  if (tDecodeCStr(pCoder, &pME->name) < 0) return -1;

  if (pME->type == TSDB_SUPER_TABLE) {
C
Cary Xu 已提交
72
    if (tDecodeI8(pCoder, &pME->flags) < 0) return -1;  // TODO: need refactor?
73
    if (tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow) < 0) return -1;
H
Hongze Cheng 已提交
74
    if (tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
C
Cary Xu 已提交
75 76 77
    if (TABLE_IS_ROLLUP(pME->flags)) {
      if (tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam) < 0) return -1;
    }
H
Hongze Cheng 已提交
78 79 80
  } else if (pME->type == TSDB_CHILD_TABLE) {
    if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
    if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
C
Cary Xu 已提交
81
    if (tDecodeI32v(pCoder, &pME->ctbEntry.commentLen) < 0) return -1;
H
Hongze Cheng 已提交
82 83
    if (pME->ctbEntry.commentLen > 0) {
      if (tDecodeCStr(pCoder, &pME->ctbEntry.comment) < 0) return -1;
wmmhello's avatar
wmmhello 已提交
84
    }
H
Hongze Cheng 已提交
85
    if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1;
C
Cary Xu 已提交
86
    if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1;  // (TODO)
H
Hongze Cheng 已提交
87 88 89
  } else if (pME->type == TSDB_NORMAL_TABLE) {
    if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
    if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
C
Cary Xu 已提交
90
    if (tDecodeI32v(pCoder, &pME->ntbEntry.commentLen) < 0) return -1;
H
Hongze Cheng 已提交
91
    if (pME->ntbEntry.commentLen > 0) {
wmmhello's avatar
wmmhello 已提交
92 93
      if (tDecodeCStr(pCoder, &pME->ntbEntry.comment) < 0) return -1;
    }
H
Hongze Cheng 已提交
94
    if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1;
95
    if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1;
C
Cary Xu 已提交
96
  } else if (pME->type == TSDB_TSMA_TABLE) {
C
Cary Xu 已提交
97
    pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
H
Hongze Cheng 已提交
98
    if (!pME->smaEntry.tsma) {
C
Cary Xu 已提交
99 100 101
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      return -1;
    }
C
Cary Xu 已提交
102
    if (tDecodeTSma(pCoder, pME->smaEntry.tsma, true) < 0) return -1;
H
Hongze Cheng 已提交
103
  } else {
104 105 106
    metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);

    return -1;
H
Hongze Cheng 已提交
107 108 109 110 111
  }

  tEndDecode(pCoder);
  return 0;
}