-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput.go
More file actions
190 lines (173 loc) · 3.71 KB
/
input.go
File metadata and controls
190 lines (173 loc) · 3.71 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package goqrencode
/*
#include <qrencode.h>
#cgo LDFLAGS: -lqrencode
*/
import "C"
import (
"fmt"
"io"
"io/ioutil"
"runtime"
"unsafe"
)
/*
* Exception process
*/
func ThrowAndCatchException() error {
// todo
// patch libqrencode
// extern "C"
// int throw_and_catch_exception {
// try {
// ....
// } catch (...) {
// return ...
// }
// }
return fmt.Errorf("libqrencode error")
}
/*
* Validate the input data.
* See qrencode.h QRinput_check
*/
func InputCheck(mode C.QRencodeMode, r interface{}) error {
b, err := ioutil.ReadAll(r.(io.Reader))
if err != nil {
return err
}
ret := C.QRinput_check(mode, C.int(len(b)), (*C.uchar)(unsafe.Pointer(&b)))
if int(ret) == 0 {
return nil
} else {
return ThrowAndCatchException()
}
}
/*
* Return a string that identifies the library version.
*/
func ApiVersion() (major, minor, micro int) {
C.QRcode_APIVersion((*C.int)(unsafe.Pointer(&major)), (*C.int)(unsafe.Pointer(&minor)), (*C.int)(unsafe.Pointer(µ)))
return
}
/*
* Return a string that identifies the library version.
*/
func ApiVersionString() string {
return C.GoString(C.QRcode_APIVersionString())
}
/*
* goqrencode Input
*/
type Input struct {
input *C.QRinput
}
/*
* create goqrencode Input
*/
func InputNew() (ret *Input, err error) {
ret = new(Input)
err = ret.New()
return
}
/*
* create Input
*/
func (c *Input) New() error {
c.input = C.QRinput_new()
if c.input == nil {
return ThrowAndCatchException()
} else {
// set gc func
runtime.SetFinalizer(c, (*Input).Destroy)
return nil
}
}
/*
* Append data to an input object
* The data is copied and appended to the input object.
* See qrencode.h QRinput_append
*
*/
func (c *Input) Append(mode C.QRencodeMode, r interface{}) error {
b, err := ioutil.ReadAll(r.(io.Reader))
if err != nil {
return err
}
ret := C.QRinput_append(c.input, mode, C.int(len(b)), (*C.uchar)(unsafe.Pointer(&b)))
if int(ret) == 0 {
return nil
} else {
return ThrowAndCatchException()
}
}
/*
* Append ECI header.
* See qrcnecode.h QRinput_appendECIheader
*/
func (c *Input) AppendECIHeader(ecinum uint) error {
ret := C.QRinput_appendECIheader(c.input, C.uint(ecinum))
if int(ret) == 0 {
return nil
} else {
return ThrowAndCatchException()
}
}
/*
* Get current version.
* See qrcnecode.h QRinput_getVersion
*/
func (c *Input) GetVersion() int {
return int(C.QRinput_getVersion(c.input))
}
/*
* Set version of the QR code that is to be encoded.
* See qrcnecode.h QRinput_setVersion
*/
func (c *Input) SetVersion(version int) error {
ret := C.QRinput_setVersion(c.input, C.int(version))
if int(ret) == 0 {
return nil
} else {
return ThrowAndCatchException()
}
}
/*
* Get current error correction level.
* See qrcnecode.h QRinput_getErrorCorrectionLevel
*/
func (c *Input) GetErrorCorrectionLevel() C.QRecLevel {
return C.QRinput_getErrorCorrectionLevel(c.input)
}
/*
* Set error correction level of the QR code that is to be encoded.
* See qrcnecode.h QRinput_setErrorCorrectionLevel
*/
func (c *Input) SetErrorCorrectionLevel(level C.QRecLevel) error {
ret := C.QRinput_setErrorCorrectionLevel(c.input, level)
if int(ret) == 0 {
return nil
} else {
return ThrowAndCatchException()
}
}
/*
* Set version and error correction level of the QR code at once.
* See qrcnecode.h QRinput_setVersionAndErrorCorrectionLevel
*/
func (c *Input) SetVersionAndErrorCorrectionLevel(version int, level C.QRecLevel) error {
ret := C.QRinput_setVersionAndErrorCorrectionLevel(c.input, C.int(version), level)
if int(ret) == 0 {
return nil
} else {
return ThrowAndCatchException()
}
}
/*
* free input object
* See qrcnecode.h QRinput_free
*/
func (c *Input) Destroy() {
C.QRinput_free(c.input)
}
//todo InputStruct