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