dataformat.h 3.5 KB
Newer Older
H
more  
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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
hzcheng 已提交
15
#ifndef _TD_DATA_FORMAT_H_
H
more  
Hongze Cheng 已提交
16 17 18
#define _TD_DATA_FORMAT_H_

#include <stdint.h>
H
hzcheng 已提交
19
#include <stdlib.h>
H
hzcheng 已提交
20
#include <string.h>
H
more  
Hongze Cheng 已提交
21

H
hzcheng 已提交
22
// #include "schema.h"
H
more  
Hongze Cheng 已提交
23

H
more  
hzcheng 已提交
24 25 26
#ifdef __cplusplus
extern "C" {
#endif
H
more  
Hongze Cheng 已提交
27 28
// ----------------- Data row structure

H
hzcheng 已提交
29
/* A data row, the format is like below:
H
more  
Hongze Cheng 已提交
30 31 32
 * +---------+---------------------------------+
 * | int32_t |                                 |
 * +---------+---------------------------------+
H
hzcheng 已提交
33
 * |   len   |                row              |
H
more  
Hongze Cheng 已提交
34
 * +---------+---------------------------------+
H
hzcheng 已提交
35 36
 * len: the length including sizeof(row) + sizeof(len)
 * row: actual row data encoding
H
more  
Hongze Cheng 已提交
37
 */
H
hzcheng 已提交
38 39 40 41 42 43
typedef void *SDataRow;

#define dataRowLen(r) (*(int32_t *)(r))
#define dataRowTuple(r) ((char *)(r) + sizeof(int32_t))
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowIdx(r, i) ((char *)(r) + i)
H
hzcheng 已提交
44
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
H
hzcheng 已提交
45 46

SDataRow tdNewDataRow(int32_t bytes);
H
hzcheng 已提交
47
// SDataRow tdNewDdataFromSchema(SSchema *pSchema);
H
hzcheng 已提交
48
void     tdFreeDataRow(SDataRow row);
H
hzcheng 已提交
49
// int32_t  tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset);
H
hzcheng 已提交
50 51
void     tdDataRowCpy(void *dst, SDataRow row);
void     tdDataRowReset(SDataRow row);
H
hzcheng 已提交
52
SDataRow tdDataRowDup(SDataRow row);
H
more  
Hongze Cheng 已提交
53 54

/* Data rows definition, the format of it is like below:
H
hzcheng 已提交
55 56 57 58 59
 * +---------+-----------------------+--------+-----------------------+
 * | int32_t |                       |        |                       |
 * +---------+-----------------------+--------+-----------------------+
 * |   len   |        SDataRow       |  ....  |        SDataRow       |
 * +---------+-----------------------+--------+-----------------------+
H
more  
Hongze Cheng 已提交
60
 */
H
hzcheng 已提交
61
typedef void *SDataRows;
H
more  
Hongze Cheng 已提交
62

H
hzcheng 已提交
63 64
#define TD_DATA_ROWS_HEAD_LEN sizeof(int32_t)

H
hzcheng 已提交
65 66 67 68
#define dataRowsLen(rs) (*(int32_t *)(rs))
#define dataRowsSetLen(rs, l) (dataRowsLen(rs) = (l))
#define dataRowsInit(rs) dataRowsSetLen(rs, sizeof(int32_t))

H
hzcheng 已提交
69 70 71 72 73 74 75 76 77 78 79 80
void tdDataRowsAppendRow(SDataRows rows, SDataRow row);

// Data rows iterator
typedef struct {
  int32_t totalLen;
  int32_t len;
  SDataRow row;
} SDataRowsIter;

void tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
SDataRow tdDataRowsNext(SDataRowsIter *pIter);

H
more  
Hongze Cheng 已提交
81 82 83 84 85 86 87
/* Data column definition
 * +---------+---------+-----------------------+
 * | int32_t | int32_t |                       |
 * +---------+---------+-----------------------+
 * |   len   | npoints |          data         |
 * +---------+---------+-----------------------+
 */
H
hzcheng 已提交
88
typedef char *SDataCol;
H
more  
Hongze Cheng 已提交
89 90 91 92 93 94 95 96

/* Data columns definition
 * +---------+---------+-----------------------+--------+-----------------------+
 * | int32_t | int32_t |                       |        |                       |
 * +---------+---------+-----------------------+--------+-----------------------+
 * |   len   | npoints |        SDataCol       |  ....  |        SDataCol       |
 * +---------+---------+-----------------------+--------+-----------------------+
 */
H
hzcheng 已提交
97
typedef char *SDataCols;
H
more  
Hongze Cheng 已提交
98

H
more  
hzcheng 已提交
99 100 101 102
#ifdef __cplusplus
}
#endif

H
hzcheng 已提交
103
#endif  // _TD_DATA_FORMAT_H_