-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
45 lines (40 loc) · 1.07 KB
/
entry.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
package stud
import (
"encoding/binary"
"fmt"
"io"
)
type entry struct {
dib byte
pad [3]byte
hash uint32
k uint64
offset uint64
end uint64
}
func (e entry) _marshal(w File) {
panicerr2(w.Write(emptyEntry[:]))
panicerr2(w.Seek(-entrySize, 1))
panicerr(binary.Write(w, binary.BigEndian, e.dib))
panicerr(binary.Write(w, binary.BigEndian, e.pad))
panicerr(binary.Write(w, binary.BigEndian, e.hash))
panicerr(binary.Write(w, binary.BigEndian, e.k))
panicerr(binary.Write(w, binary.BigEndian, e.offset))
panicerr(binary.Write(w, binary.BigEndian, e.end))
}
func _unmarshalEntry(r io.Reader) entry {
e := entry{}
panicerr(binary.Read(r, binary.BigEndian, &e.dib))
panicerr(binary.Read(r, binary.BigEndian, &e.pad))
panicerr(binary.Read(r, binary.BigEndian, &e.hash))
panicerr(binary.Read(r, binary.BigEndian, &e.k))
panicerr(binary.Read(r, binary.BigEndian, &e.offset))
panicerr(binary.Read(r, binary.BigEndian, &e.end))
return e
}
func (e entry) String() string {
if e.k == 0 {
return "null"
}
return fmt.Sprintf("%x->%x(%d)", e.k, e.offset, e.dib)
}