dataformat.h 3.7 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
more  
Hongze Cheng 已提交
15 16 17 18 19 20 21
#if !defined(_TD_DATA_FORMAT_H_)
#define _TD_DATA_FORMAT_H_

#include <stdint.h>

#include "schema.h"

H
more  
hzcheng 已提交
22 23 24
#ifdef __cplusplus
extern "C" {
#endif
H
more  
Hongze Cheng 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
// ----------------- Data row structure

/* A data row, the format of it is like below:
 * +---------+---------------------------------+
 * | int32_t |                                 |
 * +---------+---------------------------------+
 * |   len   |               data              |
 * +---------+---------------------------------+
 */
typedef char* SDataRow;

/* Data rows definition, the format of it is like below:
 * +---------+---------+-----------------------+--------+-----------------------+
 * | int32_t | int32_t |                       |        |                       |
 * +---------+---------+-----------------------+--------+-----------------------+
 * |   len   |  nrows  |        SDataRow       |  ....  |        SDataRow       |
 * +---------+---------+-----------------------+--------+-----------------------+
 */
typedef char * SDataRows;

/* Data column definition
 * +---------+---------+-----------------------+
 * | int32_t | int32_t |                       |
 * +---------+---------+-----------------------+
 * |   len   | npoints |          data         |
 * +---------+---------+-----------------------+
 */
typedef char * SDataCol;

/* Data columns definition
 * +---------+---------+-----------------------+--------+-----------------------+
 * | int32_t | int32_t |                       |        |                       |
 * +---------+---------+-----------------------+--------+-----------------------+
 * |   len   | npoints |        SDataCol       |  ....  |        SDataCol       |
 * +---------+---------+-----------------------+--------+-----------------------+
 */
typedef char * SDataCols;

H
more  
hzcheng 已提交
63 64 65 66 67 68
typedef struct {
    int32_t rowCounter;
    int32_t totalRows;
    SDataRow row;
} SDataRowsIter;

H
more  
Hongze Cheng 已提交
69 70 71
// ----------------- Data column structure

// ---- operation on SDataRow;
H
more  
hzcheng 已提交
72
#define TD_DATA_ROW_HEADER_SIZE  sizeof(int32_t)
H
more  
Hongze Cheng 已提交
73 74 75
#define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow))
#define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t))

H
more  
hzcheng 已提交
76
SDataRow tdSDataRowDup(SDataRow rdata);
H
hzcheng 已提交
77
void tdSDataRowCpy(SDataRow src, void *dst);
H
hzcheng 已提交
78
void tdFreeSDataRow(SDataRow rdata);
H
more  
hzcheng 已提交
79

H
more  
Hongze Cheng 已提交
80 81
// ---- operation on SDataRows
#define TD_DATAROWS_LEN(pDataRows) (*(int32_t *)(pDataRows))
H
more  
hzcheng 已提交
82 83
#define TD_DATAROWS_ROWS(pDataRows) (*(int32_t *)((pDataRows) + sizeof(int32_t)))
#define TD_DATAROWS_DATA(pDataRows) (SDataRow)((pDataRows) + 2 * sizeof(int32_t))
H
more  
Hongze Cheng 已提交
84 85 86 87 88 89 90 91 92

// ---- operation on SDataCol
#define TD_DATACOL_LEN(pDataCol) (*(int32_t *)(pDataCol))
#define TD_DATACOL_NPOINTS(pDataCol) (*(int32_t *)(pDataCol + sizeof(int32_t)))

// ---- operation on SDataCols
#define TD_DATACOLS_LEN(pDataCols) (*(int32_t *)(pDataCols))
#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t)))

H
more  
hzcheng 已提交
93 94 95 96 97
// ---- operation on SDataRowIter
int32_t tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
int32_t tdRdataIterEnd(SDataRowsIter *pIter);
void    tdRdataIterNext(SDataRowsIter *pIter);

H
Hongze Cheng 已提交
98
// ----
H
more  
hzcheng 已提交
99 100 101 102
/**
 * Get the maximum
 */
int32_t tdGetMaxDataRowSize(SSchema *pSchema);
H
Hongze Cheng 已提交
103

H
more  
hzcheng 已提交
104 105 106 107
#ifdef __cplusplus
}
#endif

H
more  
Hongze Cheng 已提交
108
#endif // _TD_DATA_FORMAT_H_