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:] } }