-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathconvert_js.go
More file actions
39 lines (32 loc) · 773 Bytes
/
convert_js.go
File metadata and controls
39 lines (32 loc) · 773 Bytes
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
//go:build js
// +build js
// Copyright (c) Roman Atachiants and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
package binary
func ToBytes(v string) (b []byte) {
return []byte(v)
}
func binaryToString(buf *[]byte) string {
return string(*buf)
}
func stringToBinary(v string) (b []byte) {
return []byte(v)
}
func binaryToBools(b *[]byte) (result []bool) {
buffer := *b
result = make([]bool, len(buffer), len(buffer))
for i := 0; i < len(buffer); i++ {
result[i] = buffer[i] == 1
}
return
}
func boolsToBinary(v *[]bool) (result []byte) {
value := *v
result = make([]byte, len(value), len(value))
for i := 0; i < len(value); i++ {
if value[i] {
result[i] = 1
}
}
return
}