Initial commit
This commit is contained in:
25
lib/wal/wal-header.go
Normal file
25
lib/wal/wal-header.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package wal
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
type walHeader struct {
|
||||
FirstSegmentID int64
|
||||
LastSegmentID int64
|
||||
}
|
||||
|
||||
func (h walHeader) WriteTo(b []byte) {
|
||||
vals := []int64{h.FirstSegmentID, h.LastSegmentID}
|
||||
|
||||
for _, val := range vals {
|
||||
binary.LittleEndian.PutUint64(b[0:8], uint64(val))
|
||||
b = b[8:]
|
||||
}
|
||||
}
|
||||
|
||||
func (h *walHeader) ReadFrom(b []byte) {
|
||||
ptrs := []*int64{&h.FirstSegmentID, &h.LastSegmentID}
|
||||
for _, ptr := range ptrs {
|
||||
*ptr = int64(binary.LittleEndian.Uint64(b[0:8]))
|
||||
b = b[8:]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user