-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
115 lines (85 loc) · 2.55 KB
/
utils.go
File metadata and controls
115 lines (85 loc) · 2.55 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package facesdk
/*
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
typedef struct {
char* data;
size_t size;
size_t offset;
} WriteData;
typedef struct {
const char* data;
size_t offset;
} ReadData;
const char* TDVException_getMessage(void* eh);
void TDVException_deleteException(void* eh);
const char* __4848a76477c449608aa5deb15c5495e4_facerec_v3_apiException_what(void* exception);
void __4848a76477c449608aa5deb15c5495e4_facerec_v3_apiObject_destructor(void* object);
void writeFunction(void* data, const void* buffer, uint64_t bytesCount)
{
WriteData* ptr = (WriteData*)data;
if (ptr->offset + bytesCount > ptr->size)
{
char* temp = ptr->data;
ptr->data = (char*)malloc(ptr->size * 2);
memcpy(ptr->data, temp, ptr->offset);
free(temp);
}
memcpy(ptr->data + ptr->offset, buffer, bytesCount);
ptr->offset += bytesCount;
}
void readFunction(void* data, void* buffer, uint64_t bytesCount)
{
ReadData* ptr = (ReadData*)data;
memcpy(buffer, ptr->data + ptr->offset, bytesCount);
ptr->offset += bytesCount;
}
*/
import "C"
import (
"errors"
"unsafe"
)
func createException() unsafe.Pointer {
var exceptionType unsafe.Pointer
return C.malloc(C.size_t(unsafe.Sizeof(exceptionType)))
}
func checkProcessingBlockException(exception unsafe.Pointer) error {
if exception != nil {
errorMessage := C.GoString(C.TDVException_getMessage(exception))
C.TDVException_deleteException(exception)
return errors.New(errorMessage)
}
return nil
}
func checkApiException(exception unsafe.Pointer) error {
if exception != nil {
errorMessage := C.GoString(C.__4848a76477c449608aa5deb15c5495e4_facerec_v3_apiException_what(exception))
C.__4848a76477c449608aa5deb15c5495e4_facerec_v3_apiObject_destructor(exception)
return errors.New(errorMessage)
}
return nil
}
func getStringByIndex(cArray **C.char, index int) string {
ptr := *(**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cArray)) + uintptr(index)*unsafe.Sizeof(*cArray)))
return C.GoString(ptr)
}
func createCStringArray(goStrings []string) (**C.char, func()) {
cArray := C.malloc(C.size_t(len(goStrings)) * C.size_t(unsafe.Sizeof(uintptr(0))))
stringArray := (**C.char)(cArray)
cStrings := make([]*C.char, len(goStrings))
for i, s := range goStrings {
cStr := C.CString(s)
cStrings[i] = cStr
ptr := (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(stringArray)) + uintptr(i)*unsafe.Sizeof(uintptr(0))))
*ptr = cStr
}
cleanup := func() {
for _, cStr := range cStrings {
C.free(unsafe.Pointer(cStr))
}
C.free(unsafe.Pointer(cArray))
}
return stringArray, cleanup
}