26 lines
493 B
Go
26 lines
493 B
Go
|
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:]
|
||
|
}
|
||
|
}
|