udfc.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
//
// 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 {
    UDF_TASK_SETUP = 0,
    UDF_TASK_CALL = 1,
    UDF_TASK_TEARDOWN = 2

};

typedef struct SSDataBlock{
    char *data;
    int32_t size;
} SSDataBlock;

typedef struct SUdfInfo {
    char *udfName;
    char *path;
} SUdfInfo;

33
typedef void *UdfcFuncHandle;
34

35
int32_t createUdfdProxy();
36

37
int32_t destroyUdfdProxy();
38

39
//int32_t setupUdf(SUdfInfo *udf, int32_t numOfUdfs, UdfcFuncHandle *handles);
40

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 teardownUdf(UdfcFuncHandle handle);
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

typedef struct SUdfSetupRequest {
    char udfName[16]; //
    int8_t scriptType; // 0:c, 1: lua, 2:js
    int8_t udfType; //udaf, udf, udtf
    int16_t pathSize;
    char *path;
} SUdfSetupRequest;

typedef struct SUdfSetupResponse {
    int64_t udfHandle;
} SUdfSetupResponse;


typedef struct SUdfCallRequest {
    int64_t udfHandle;
    int8_t step;

    int32_t inputBytes;
    char *input;

    int32_t stateBytes;
    char *state;
} SUdfCallRequest;


typedef struct SUdfCallResponse {
    int32_t outputBytes;
    char *output;
    int32_t newStateBytes;
    char *newState;
} SUdfCallResponse;


typedef struct SUdfTeardownRequest {
    int64_t udfHandle;
} SUdfTeardownRequest;


typedef struct SUdfTeardownResponse {
wafwerar's avatar
wafwerar 已提交
87 88 89
#ifdef WINDOWS
  size_t avoidCompilationErrors;
#endif
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
} SUdfTeardownResponse;

typedef struct SUdfRequest {
    int32_t msgLen;
    int64_t seqNum;

    int8_t type;
    void *subReq;
} SUdfRequest;

typedef struct SUdfResponse {
    int32_t msgLen;
    int64_t seqNum;

    int8_t type;
    int32_t code;
    void *subRsp;
} 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);
#endif //UDF_UDF_H