Repository navigation
Expand file tree
/
Copy pathalgorithm_convert.go
More file actions
116 lines (101 loc) 路 3.1 KB
/
Copy pathalgorithm_convert.go
File metadata and controls
116 lines (101 loc) 路 3.1 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
// Copyright 2025 The Gromb Authors. All rights reserved.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package gromb
import (
"encoding/binary"
"math"
)
const (
hextable = "0123456789ABCDEF"
reverseHexTable = "" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\x0A\x0B\x0C\x0D\x0E\x0F\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\x0A\x0B\x0C\x0D\x0E\x0F\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
)
func asciiToHex(src []uint8) []uint8 {
dst := make([]uint8, len(src)/2)
{
i, j := 0, 0
for j+1 < len(src) {
if src[j] == ' ' || src[j] == '\r' || src[j] == '\n' {
j++
continue
}
a := reverseHexTable[src[j]]
b := reverseHexTable[src[j+1]]
if a > 0x0f {
return nil
}
if b > 0x0f {
return nil
}
dst[i] = (a << 4) | b
i++
j += 2
}
}
return dst
}
func asciiFromHex(src []uint8) []uint8 {
dst := make([]uint8, len(src)*2)
{
j := 0
for _, v := range src {
dst[j] = hextable[v>>4]
dst[j+1] = hextable[v&0x0f]
j += 2
}
}
return dst
}
func byteToUint16(in []uint8, order binary.ByteOrder) uint16 {
return order.Uint16(in[:])
}
func byteFromUint16(in uint16, order binary.ByteOrder) []uint8 {
var out []uint8 = make([]uint8, 2)
order.PutUint16(out, in)
return out
}
func bytesFromUint16s(input []uint16, order binary.ByteOrder) []uint8 {
output := make([]uint8, 2*len(input))
for i := 0; i < len(input); i++ {
order.PutUint16(output[i*2:i*2+2], input[i])
}
return output
}
func bytesToUint16s(input []uint8, order binary.ByteOrder) []uint16 {
output := make([]uint16, len(input)/2)
for i := 0; i < len(input)/2; i++ {
output[i] = order.Uint16(input[i*2 : i*2+2])
}
return output
}
func bytesToFloat32s(input []uint8, order binary.ByteOrder) []float32 {
output := make([]float32, len(input)/4)
for i := 0; i < len(input)/4; i++ {
output[i] = math.Float32frombits(order.Uint32(input[i*4 : i*4+4]))
}
return output
}
func bytesFromFloat32s(input []float32, order binary.ByteOrder) []uint8 {
output := make([]uint8, len(input)*4)
for i := 0; i < len(input); i++ {
order.PutUint32(output[i*4:i*4+4], math.Float32bits(input[i]))
}
return output
}