Skip to content

Commit

Permalink
Merge pull request #2 from gfeyer/main
Browse files Browse the repository at this point in the history
Update to version 2.6
  • Loading branch information
gfeyer authored Aug 26, 2021
2 parents 3f78588 + c0c74d6 commit 009bb12
Show file tree
Hide file tree
Showing 32 changed files with 6,147 additions and 5,432 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
/test/Release
/test/x64
*.j
*.txt
*.txt
/build
.vscode
1 change: 1 addition & 0 deletions 3rdparty/gjq/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go build -o libjq.dll -buildmode=c-shared
1 change: 1 addition & 0 deletions 3rdparty/gjq/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go build -o libjq -buildmode=c-archive
76 changes: 76 additions & 0 deletions 3rdparty/gjq/libjq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package _/install/platform-tools/kafkadesktopclient/3rdparty/gjq */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h> /* for ptrdiff_t below */

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments. */




/* End of preamble from import "C" comments. */


/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;

/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue. */

#ifdef __cplusplus
extern "C" {
#endif

extern long int cgoCurrentMillis();
extern char* cgoFilter(char* userQuery, char* jsonRequest);

#ifdef __cplusplus
}
#endif
86 changes: 86 additions & 0 deletions 3rdparty/gjq/libjq.h.bkp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package _/install/platform-tools/kafkadesktopclient/src/gjq */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h> /* for ptrdiff_t below */

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments. */




/* End of preamble from import "C" comments. */


/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
#ifndef _WIN32
typedef __SIZE_TYPE__ GoUintptr;
#endif
typedef float GoFloat32;
typedef double GoFloat64;
#ifndef _WIN32
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue. */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
// windows build
extern __declspec(dllexport) long int cgoCurrentMillis();
extern __declspec(dllexport) char* cgoFilter(char* userQuery, char* jsonRequest);
#else
// Linux & Macos build
extern long int cgoCurrentMillis();
extern char* cgoFilter(char* userQuery, char* jsonRequest);
#endif

#ifdef __cplusplus
}
#endif
107 changes: 107 additions & 0 deletions 3rdparty/gjq/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package main

import "C"
import (
"encoding/json"
"fmt"
"log"
"time"

"github.com/itchyny/gojq"
)

//export cgoCurrentMillis
func cgoCurrentMillis() C.long {
return C.long(time.Now().Unix())
}

//export cgoFilter
func cgoFilter(userQuery *C.char, jsonRequest *C.char) *C.char {
q := " fromjson | " + C.GoString(userQuery)
input := C.GoString(jsonRequest)

query, err := gojq.Parse(q)

if err != nil {
return C.CString(err.Error())
}

iter := query.Run(input)

// var jsonResult string
var result []byte

for {
v, ok := iter.Next()
if !ok {
break
}
if err, ok := v.(error); ok {
return C.CString(err.Error())
}

j, err := json.Marshal(v)

if err == nil {
// jsonResult += string(j)
if len(result) == 0 {
result = append(result, j...)
} else {
result = append(result, '\n')
result = append(result, j...)
}
}
}

// cstr := C.CString(jsonResult)
cstr := C.CString(string(result))
return cstr
}

func main() {
query, err := gojq.Parse(" fromjson | .glossary.GlossDiv")

if err != nil {
log.Fatalln(err)
}
// input := map[string]interface{}{"foo": []interface{}{1, 2, 3}}
input := `{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}`
iter := query.Run(input) // or query.RunWithContext

v, _ := iter.Next()
b, err := json.Marshal(v)

fmt.Println(string(b))

for {
v, ok := iter.Next()
if !ok {
break
}
if err, ok := v.(error); ok {
log.Fatalln(err)
}
fmt.Printf("%#v\n", v)
}
}
16 changes: 16 additions & 0 deletions 3rdparty/gjq/win/build_lib.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# With cgo, cannot use .lib directly in visual studio (only works with MinGW compiler).
# So we need to generate the .dll file with go build, then generate the .lib file from the dll by using the function definitions
#
# details 1: https://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll
# details 2: https://web.archive.org/web/20130330132630/http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio
#
# To create the .def file from .dll, open developer command VS2019->Tools->Command Line->Developer command prompt
# dumpbin /exports libjq.dll
# get the function names and add them to the .def file, example:
# EXPORTS
# function1
# function2
#
# After .def file is created, run command below to create .lib from .def

lib /def:libjq.def /out:libjq.lib /machine:x64
4 changes: 4 additions & 0 deletions 3rdparty/gjq/win/libjq.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXPORTS
_cgo_dummy_export
cgoCurrentMillis
cgoFilter
Binary file added 3rdparty/gjq/win/libjq.exp
Binary file not shown.
86 changes: 86 additions & 0 deletions 3rdparty/include/libjq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package _/install/platform-tools/kafkadesktopclient/src/gjq */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h> /* for ptrdiff_t below */

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments. */




/* End of preamble from import "C" comments. */


/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
#ifndef _WIN32
typedef __SIZE_TYPE__ GoUintptr;
#endif
typedef float GoFloat32;
typedef double GoFloat64;
#ifndef _WIN32
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue. */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
// windows build
extern __declspec(dllexport) long int cgoCurrentMillis();
extern __declspec(dllexport) char* cgoFilter(char* userQuery, char* jsonRequest);
#else
// Linux & Macos build
extern long int cgoCurrentMillis();
extern char* cgoFilter(char* userQuery, char* jsonRequest);
#endif

#ifdef __cplusplus
}
#endif
Binary file added 3rdparty/lib/libjq
Binary file not shown.
Binary file added 3rdparty/lib/libjq.dll
Binary file not shown.
Binary file added 3rdparty/lib/libjq.lib
Binary file not shown.
Loading

0 comments on commit 009bb12

Please sign in to comment.