-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
29 lines (23 loc) · 1.04 KB
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package wal
import "io"
// Entry is a single record of the Write Ahead Log.
// It is up to the application that uses the WAL to provide at least one concrete
// Entry implementation to the WAL via the EntryRegistry.
type Entry interface {
Type() EntryType
// EncodePayload encodes the payload into the provided buffer. In case the
// buffer is too small to fit the entire payload, this function can grow the
// old and return a new slice. Otherwise, the old slice must be returned.
EncodePayload([]byte) []byte
// ReadPayload reads the payload from the reader but does not yet decode it.
// Reading and decoding are separate steps for performance reasons. Sometimes
// we might want to quickly seek through the WAL without having to decode
// every entry.
ReadPayload(r io.Reader) ([]byte, error)
// DecodePayload decodes an entry from a payload that has previously been read
// by ReadPayload(…).
DecodePayload([]byte) error
}
// EntryType is used to distinguish different types of messages that we write
// to the WAL.
type EntryType uint8