-
Notifications
You must be signed in to change notification settings - Fork 3
/
zbar_types.go
63 lines (50 loc) · 1.14 KB
/
zbar_types.go
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
package zbar
import (
"github.com/tetratelabs/wazero/api"
)
type symbol struct {
mod api.Module
len, data uint32
ptr uint32
}
func newSymbol(ptr uint32, zbar api.Module) symbol {
s := symbol{
ptr: ptr,
mod: zbar,
}
res := must(s.mod.ExportedFunction("Symbol_get_data_length").
Call(ctx, uint64(s.ptr)))
s.len = uint32(res[0])
res = must(s.mod.ExportedFunction("Symbol_get_data").
Call(ctx, uint64(s.ptr)))
s.data = uint32(res[0])
return s
}
func (s *symbol) read(b []byte, offset uint32) (uint32, bool) {
if offset+uint32(len(b)) < s.len {
b2, _ := s.mod.Memory().Read(s.data+offset, uint32(len(b)))
copy(b, b2)
return uint32(len(b)), true
}
b2, _ := s.mod.Memory().Read(s.data+offset, s.len-offset)
copy(b, b2)
return s.len - offset, false
}
func (s *symbol) readAll() []byte {
b, ok := s.mod.Memory().Read(s.data, s.len)
if !ok {
return nil
}
return b
}
func (s symbol) next() (symbol, bool) {
res := must(s.mod.ExportedFunction("Symbol_next").
Call(ctx, uint64(s.ptr)))
if res[0] == 0 {
return symbol{}, false
}
return newSymbol(uint32(res[0]), s.mod), true
}
type img struct {
ptr uint32
}