jldb/mdb/change/encoding.go

36 lines
651 B
Go
Raw Permalink Normal View History

2023-10-13 09:43:27 +00:00
package change
import "io"
func Write(changes []Change, w io.Writer) error {
count := uint64(len(changes))
if err := writeBin(w, count); err != nil {
return err
}
for _, c := range changes {
if err := c.writeTo(w); err != nil {
return err
}
}
return nil
}
func Read(changes []Change, r io.Reader) ([]Change, error) {
var count uint64
if err := readBin(r, &count); err != nil {
return changes, err
}
if uint64(len(changes)) < count {
changes = make([]Change, count)
}
changes = changes[:count]
for i := range changes {
if err := changes[i].readFrom(r); err != nil {
return changes, err
}
}
return changes, nil
}