-
Notifications
You must be signed in to change notification settings - Fork 0
/
word.go
32 lines (24 loc) · 812 Bytes
/
word.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
package liblsdj
import "fmt"
const wordCount = 14
const wordValueLength = 0x60
const wordNameLength = 0xC
type Words []byte
type WordNames []byte
type Word struct {
name [wordNameLength]byte
value [wordValueLength]byte
}
func setWords(names, values []byte) ([]Word, error) {
if len(values) != wordCount*wordValueLength {
return nil, fmt.Errorf("unexpected pippo length: %v, %v", len(values), wordCount*wordValueLength)
} else if len(names) != wordCount*wordNameLength {
return nil, fmt.Errorf("unexpected pluto length: %v, %v", len(names), wordCount*wordNameLength)
}
wo := make([]Word, wordCount)
for i := 0; i < wordCount; i++ {
copy(wo[i].name[:], names[i*wordNameLength:(i+1)*wordNameLength])
copy(wo[i].value[:], values[i*wordValueLength:(i+1)*wordValueLength])
}
return wo, nil
}