-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetc.go
55 lines (46 loc) · 865 Bytes
/
etc.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
46
47
48
49
50
51
52
53
54
55
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package kv
import (
"bytes"
"fmt"
"io"
)
type header struct {
magic []byte
ver byte
reserved []byte
}
func (h *header) rd(b []byte) error {
if len(b) != 16 {
panic("internal error")
}
if h.magic = b[:4]; bytes.Compare(h.magic, []byte(magic)) != 0 {
return fmt.Errorf("Unknown file format")
}
b = b[4:]
h.ver = b[0]
h.reserved = b[1:]
return nil
}
// Get a 7B int64 from b
func b2h(b []byte) (h int64) {
for _, v := range b[:7] {
h = h<<8 | int64(v)
}
return
}
// Put a 7B int64 into b
func h2b(b []byte, h int64) []byte {
for i := range b[:7] {
b[i], h = byte(h>>48), h<<8
}
return b
}
func noEof(e error) (err error) {
if e != io.EOF {
err = e
}
return
}