schema.h 1.9 KB
Newer Older
H
hzcheng 已提交
1
#ifndef _TD_SCHEMA_H_
H
more  
Hongze Cheng 已提交
2 3 4
#define _TD_SCHEMA_H_

#include <stdint.h>
H
more  
Hongze Cheng 已提交
5
#include <string.h>
H
more  
Hongze Cheng 已提交
6 7 8

#include "type.h"

H
hzcheng 已提交
9 10 11 12 13
#ifdef __cplusplus
extern "C" {
#endif

// ---- Column definition and operations
H
more  
Hongze Cheng 已提交
14
typedef struct {
H
hzcheng 已提交
15 16 17 18
  int8_t  type;    // Column type
  int16_t colId;   // column ID
  int16_t bytes;   // column bytes
  int32_t offset;  // point offset in a row data
H
more  
Hongze Cheng 已提交
19 20
} SColumn;

H
hzcheng 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#define colType(col) ((col)->type)
#define colColId(col) ((col)->colId)
#define colBytes(col) ((col)->bytes)
#define colOffset(col) ((col)->offset)

#define colSetType(col, t) (colType(col) = (t))
#define colSetColId(col, id) (colColId(col) = (id))
#define colSetBytes(col, b) (colBytes(col) = (b))
#define colSetOffset(col, o) (colOffset(col) = (o))

SColumn *tdNewCol(int8_t type, int16_t colId, int16_t bytes);
void tdFreeCol(SColumn *pCol);
void tdColCpy(SColumn *dst, SColumn *src);

// ---- Schema definition and operations
H
more  
Hongze Cheng 已提交
36 37
typedef struct {
  int32_t  numOfCols;
H
hzcheng 已提交
38
  int32_t  padding;   // TODO: replace the padding for useful variable
H
hzcheng 已提交
39
  SColumn  columns[];
H
more  
Hongze Cheng 已提交
40 41
} SSchema;

H
hzcheng 已提交
42 43 44 45 46 47 48 49 50 51 52
#define schemaNCols(s) ((s)->numOfCols)
#define schemaColAt(s, i) ((s)->columns + i)

SSchema *tdNewSchema(int32_t nCols);
SSchema *tdDupSchema(SSchema *pSchema);
void tdFreeSchema(SSchema *pSchema);
void tdUpdateSchema(SSchema *pSchema);
int32_t tdMaxRowDataBytes(SSchema *pSchema);

// ---- Inline schema definition and operations

H
more  
Hongze Cheng 已提交
53 54 55 56 57 58 59
/* Inline schema definition
 * +---------+---------+---------+-----+---------+-----------+-----+-----------+
 * | int32_t |         |         |     |         |           |     |           |
 * +---------+---------+---------+-----+---------+-----------+-----+-----------+
 * |   len   | SSchema | SColumn | ... | SColumn | col1_name | ... | colN_name |
 * +---------+---------+---------+-----+---------+-----------+-----+-----------+
 */
H
more  
Hongze Cheng 已提交
60 61
typedef char *SISchema;

H
hzcheng 已提交
62
// TODO: add operations on SISchema
H
more  
Hongze Cheng 已提交
63

H
hzcheng 已提交
64 65 66
#ifdef __cplusplus
}
#endif
H
more  
Hongze Cheng 已提交
67

H
more  
Hongze Cheng 已提交
68
#endif  // _TD_SCHEMA_H_