-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_template.go
More file actions
146 lines (106 loc) · 4.46 KB
/
context_template.go
File metadata and controls
146 lines (106 loc) · 4.46 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package facesdk
/*
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#define SAVE_TEMPLATE_DEFAULT_SIZE 300
#define MAX_METHOD_NAME_SIZE 16
typedef void (*binary_stream_write_func_type)(
void* stream,
const void* data,
uint64_t bytes_count);
typedef void (*binary_stream_read_func_type)(
void* stream,
void* data,
uint64_t bytes_count);
typedef struct {
char* data;
size_t size;
size_t offset;
} WriteData;
typedef struct {
const char* data;
size_t offset;
} ReadData;
void* __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_loadTemplate(void* binaryStream, binary_stream_read_func_type readFunction, void** exception);
void __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_getMethodName(void* templ, void* binaryStream, binary_stream_write_func_type writeFunction, void** exception);
void __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_save(void* templ, void* binaryStream, binary_stream_write_func_type writeFunction, void** exception);
int32_t __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_size(void* templ, void** exception);
void* __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_convert(void* context, void** exception);
void __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_destructor(void* implementation);
extern void readFunction(void* data, void* buffer, uint64_t bytesCount);
extern void writeFunction(void* data, const void* buffer, uint64_t bytesCount);
void* loadTemplate(void* data, void** exception)
{
ReadData readData = { (const char*)data, 0 };
return __4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_loadTemplate(&readData, readFunction, exception);
}
const uint8_t* saveTemplate(void* contextTemplate, size_t* size, void** exception)
{
WriteData writeData = { (char*)malloc(SAVE_TEMPLATE_DEFAULT_SIZE), SAVE_TEMPLATE_DEFAULT_SIZE, 0 };
__4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_save(contextTemplate, &writeData, writeFunction, exception);
*size = writeData.offset;
return (const uint8_t*)writeData.data;
}
const char* getContextTemplateMethodName(void* contextTemplate, size_t* size, void** exception)
{
WriteData writeData = { (char*)malloc(MAX_METHOD_NAME_SIZE), MAX_METHOD_NAME_SIZE, 0 };
__4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_getMethodName(contextTemplate, &writeData, writeFunction, exception);
*size = writeData.offset;
return writeData.data;
}
*/
import "C"
import (
"errors"
"unsafe"
)
type ContextTemplate struct {
implementation unsafe.Pointer
}
// Create ContextTemplate from []bytes
func LoadContextTemplate(data []byte) (ContextTemplate, error) {
exception := createException()
result := C.loadTemplate(unsafe.Pointer(&data[0]), &exception)
return ContextTemplate{implementation: result}, checkApiException(exception)
}
// Convert blob from Context to ContextTemplate
func ConvertToContextTemplate(context Context) (ContextTemplate, error) {
exception := createException()
result := C.__4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_convert(context.implementation, &exception)
return ContextTemplate{implementation: result}, checkApiException(exception)
}
// Serialize ContextTemplate to []byte
func (template ContextTemplate) Save() ([]byte, error) {
exception := createException()
var size = C.size_t(0)
temp := unsafe.Pointer(C.saveTemplate(template.implementation, &size, &exception))
result := C.GoBytes(temp, C.int(size))
C.free(temp)
return result, checkApiException(exception)
}
// Get size of ContextTemplate in bytes
func (template ContextTemplate) Size() (int32, error) {
exception := createException()
result := int32(C.__4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_size(template.implementation, &exception))
return result, checkApiException(exception)
}
// Get method name of ContextTemplate
func (template ContextTemplate) GetMethodName() (string, error) {
exception := createException()
var size = C.size_t(0)
temp := C.getContextTemplateMethodName(template.implementation, &size, &exception)
result := C.GoStringN(temp, C.int(size))
C.free(unsafe.Pointer(temp))
return result, checkApiException(exception)
}
// Destroy ContextTemplate
func (template *ContextTemplate) Close() error {
if template.implementation == nil {
return errors.New("ContextTemplate already destroyed")
}
C.__4848a76477c449608aa5deb15c5495e4_facerec_v3_ContextTemplate_destructor(template.implementation)
template.implementation = nil
return nil
}