This repository has been archived on 2022-07-30. You can view files and clone it, but cannot push or open issues/pull-requests.
mdb/kvstore/shipping.go

46 lines
901 B
Go

package kvstore
import "encoding/binary"
const recHeaderSize = 22
func encodeRecordHeader(rec record, buf []byte) {
// SeqNum (8)
// ID (8)
// DataLen (4)
// Store (1)
// CollectionLen (1)
binary.LittleEndian.PutUint64(buf[:8], rec.SeqNum)
buf = buf[8:]
binary.LittleEndian.PutUint64(buf[:8], rec.ID)
buf = buf[8:]
if rec.Store {
binary.LittleEndian.PutUint32(buf[:4], uint32(len(rec.Data)))
buf[4] = 1
} else {
binary.LittleEndian.PutUint32(buf[:4], 0)
buf[4] = 0
}
buf = buf[5:]
buf[0] = byte(len(rec.Collection))
}
func decodeRecHeader(header []byte) (rec record, colLen, dataLen int) {
buf := header
rec.SeqNum = binary.LittleEndian.Uint64(buf[:8])
buf = buf[8:]
rec.ID = binary.LittleEndian.Uint64(buf[:8])
buf = buf[8:]
dataLen = int(binary.LittleEndian.Uint32(buf[:4]))
buf = buf[4:]
rec.Store = buf[0] != 0
buf = buf[1:]
colLen = int(buf[0])
return
}