dataformat.h 4.1 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 19 20 21
#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
// ----------------- Data row structure

H
hzcheng 已提交
27
/* A data row, the format is like below:
H
more  
Hongze Cheng 已提交
28 29 30
 * +---------+---------------------------------+
 * | int32_t |                                 |
 * +---------+---------------------------------+
H
hzcheng 已提交
31
 * |   len   |                row              |
H
more  
Hongze Cheng 已提交
32
 * +---------+---------------------------------+
H
hzcheng 已提交
33 34
 * len: the length including sizeof(row) + sizeof(len)
 * row: actual row data encoding
H
more  
Hongze Cheng 已提交
35
 */
H
hzcheng 已提交
36 37 38 39 40 41 42 43 44 45 46
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)

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

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

/* Data column definition
 * +---------+---------+-----------------------+
 * | int32_t | int32_t |                       |
 * +---------+---------+-----------------------+
 * |   len   | npoints |          data         |
 * +---------+---------+-----------------------+
 */
H
hzcheng 已提交
64
typedef char *SDataCol;
H
more  
Hongze Cheng 已提交
65 66 67 68 69 70 71 72

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

H
more  
hzcheng 已提交
75
typedef struct {
H
hzcheng 已提交
76 77 78
  int32_t  rowCounter;
  int32_t  totalRows;
  SDataRow row;
H
more  
hzcheng 已提交
79 80
} SDataRowsIter;

H
more  
Hongze Cheng 已提交
81 82 83
// ----------------- Data column structure

// ---- operation on SDataRow;
H
hzcheng 已提交
84
#define TD_DATA_ROW_HEADER_SIZE sizeof(int32_t)
H
more  
Hongze Cheng 已提交
85 86 87
#define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow))
#define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t))

H
more  
hzcheng 已提交
88
SDataRow tdSDataRowDup(SDataRow rdata);
H
hzcheng 已提交
89 90
void     tdSDataRowCpy(SDataRow src, void *dst);
void     tdFreeSDataRow(SDataRow rdata);
H
more  
hzcheng 已提交
91

H
more  
Hongze Cheng 已提交
92 93
// ---- operation on SDataRows
#define TD_DATAROWS_LEN(pDataRows) (*(int32_t *)(pDataRows))
H
more  
hzcheng 已提交
94 95
#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 已提交
96 97 98 99 100 101 102 103 104

// ---- 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 已提交
105
// ---- operation on SDataRowIter
H
hzcheng 已提交
106
void    tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
H
more  
hzcheng 已提交
107 108 109
int32_t tdRdataIterEnd(SDataRowsIter *pIter);
void    tdRdataIterNext(SDataRowsIter *pIter);

H
more  
hzcheng 已提交
110 111 112 113
#ifdef __cplusplus
}
#endif

H
hzcheng 已提交
114
#endif  // _TD_DATA_FORMAT_H_