udfc.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
// Created by shenglian on 28/02/22.
//

#ifndef UDF_UDF_H
#define UDF_UDF_H

#include <stdlib.h>
#define DEBUG
#ifdef DEBUG
#define debugPrint(...) fprintf(__VA_ARGS__)
#else
#define debugPrint(...) /**/
#endif

enum {
H
Hongze Cheng 已提交
17 18 19
  UDF_TASK_SETUP = 0,
  UDF_TASK_CALL = 1,
  UDF_TASK_TEARDOWN = 2
20 21 22

};

H
Hongze Cheng 已提交
23 24 25
typedef struct SSDataBlock {
  char   *data;
  int32_t size;
26 27 28
} SSDataBlock;

typedef struct SUdfInfo {
H
Hongze Cheng 已提交
29 30
  char *udfName;
  char *path;
31 32
} SUdfInfo;

33
typedef void *UdfcFuncHandle;
34

35
int32_t createUdfdProxy();
36

37
int32_t destroyUdfdProxy();
38

H
Hongze Cheng 已提交
39
// int32_t setupUdf(SUdfInfo *udf, int32_t numOfUdfs, UdfcFuncHandle *handles);
40

H
Hongze Cheng 已提交
41
int32_t setupUdf(SUdfInfo *udf, UdfcFuncHandle *handle);
42

43
int32_t callUdf(UdfcFuncHandle handle, int8_t step, char *state, int32_t stateSize, SSDataBlock input, char **newstate,
44 45
                int32_t *newStateSize, SSDataBlock *output);

46
int32_t doTeardownUdf(UdfcFuncHandle handle);
47 48

typedef struct SUdfSetupRequest {
H
Hongze Cheng 已提交
49 50 51 52 53
  char    udfName[16];  //
  int8_t  scriptType;   // 0:c, 1: lua, 2:js
  int8_t  udfType;      // udaf, udf, udtf
  int16_t pathSize;
  char   *path;
54 55 56
} SUdfSetupRequest;

typedef struct SUdfSetupResponse {
H
Hongze Cheng 已提交
57
  int64_t udfHandle;
58 59 60
} SUdfSetupResponse;

typedef struct SUdfCallRequest {
H
Hongze Cheng 已提交
61 62
  int64_t udfHandle;
  int8_t  step;
63

H
Hongze Cheng 已提交
64 65
  int32_t inputBytes;
  char   *input;
66

H
Hongze Cheng 已提交
67 68
  int32_t stateBytes;
  char   *state;
69 70 71
} SUdfCallRequest;

typedef struct SUdfCallResponse {
H
Hongze Cheng 已提交
72 73 74 75
  int32_t outputBytes;
  char   *output;
  int32_t newStateBytes;
  char   *newState;
76 77 78
} SUdfCallResponse;

typedef struct SUdfTeardownRequest {
H
Hongze Cheng 已提交
79
  int64_t udfHandle;
80 81 82
} SUdfTeardownRequest;

typedef struct SUdfTeardownResponse {
wafwerar's avatar
wafwerar 已提交
83 84 85
#ifdef WINDOWS
  size_t avoidCompilationErrors;
#endif
86 87 88
} SUdfTeardownResponse;

typedef struct SUdfRequest {
H
Hongze Cheng 已提交
89 90
  int32_t msgLen;
  int64_t seqNum;
91

H
Hongze Cheng 已提交
92 93
  int8_t type;
  void  *subReq;
94 95 96
} SUdfRequest;

typedef struct SUdfResponse {
H
Hongze Cheng 已提交
97 98
  int32_t msgLen;
  int64_t seqNum;
99

H
Hongze Cheng 已提交
100 101 102
  int8_t  type;
  int32_t code;
  void   *subRsp;
103 104 105 106 107 108
} SUdfResponse;

int32_t decodeRequest(char *buf, int32_t bufLen, SUdfRequest **pRequest);
int32_t encodeResponse(char **buf, int32_t *bufLen, SUdfResponse *response);
int32_t encodeRequest(char **buf, int32_t *bufLen, SUdfRequest *request);
int32_t decodeResponse(char *buf, int32_t bufLen, SUdfResponse **pResponse);
H
Hongze Cheng 已提交
109
#endif  // UDF_UDF_H