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
|
package hotline
import (
"encoding/binary"
"github.com/jhalter/mobius/concat"
)
// FileNameWithInfo field content is presented in this structure:
// Type 4 Folder (‘fldr’) or other
// Creator 4
// File size 4
// 4 Reserved?
// Name script 2
// Name size 2
// Name data size
type FileNameWithInfo struct {
Type []byte // file type code
Creator []byte // File creator code
FileSize []byte // File Size in bytes
RSVD []byte
NameScript []byte // TODO: What is this?
NameSize []byte // Length of name field
Name []byte // File name
}
func (f FileNameWithInfo) Payload() []byte {
name := f.Name
nameSize := make([]byte, 2)
binary.BigEndian.PutUint16(nameSize, uint16(len(name)))
return concat.Slices(
f.Type,
f.Creator,
f.FileSize,
[]byte{0, 0, 0, 0},
f.NameScript,
nameSize,
f.Name,
)
}
func (f *FileNameWithInfo) Read(p []byte) (n int, err error) {
// TODO: check p for expected len
f.Type = p[0:4]
f.Creator = p[4:8]
f.FileSize = p[8:12]
f.RSVD = p[12:16]
f.NameScript = p[16:18]
f.NameSize = p[18:20]
f.Name = p[20:]
return len(p), err
}
|