58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
|
package pfile
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"git.crumpington.com/public/jldb/lib/wal"
|
||
|
"git.crumpington.com/public/jldb/mdb/change"
|
||
|
)
|
||
|
|
||
|
// ----------------------------------------------------------------------------
|
||
|
|
||
|
type pFileState struct {
|
||
|
Data map[[2]uint64][]byte
|
||
|
}
|
||
|
|
||
|
// ----------------------------------------------------------------------------
|
||
|
|
||
|
type recBuilder struct {
|
||
|
changes []change.Change
|
||
|
rec wal.Record
|
||
|
}
|
||
|
|
||
|
func NewRecBuilder(seqNum, timestamp int64) *recBuilder {
|
||
|
return &recBuilder{
|
||
|
rec: wal.Record{
|
||
|
SeqNum: seqNum,
|
||
|
TimestampMS: timestamp,
|
||
|
},
|
||
|
changes: []change.Change{},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (b *recBuilder) Store(cID, iID uint64, data string) *recBuilder {
|
||
|
b.changes = append(b.changes, change.Change{
|
||
|
CollectionID: cID,
|
||
|
ItemID: iID,
|
||
|
Store: true,
|
||
|
Data: []byte(data),
|
||
|
})
|
||
|
return b
|
||
|
}
|
||
|
|
||
|
func (b *recBuilder) Delete(cID, iID uint64) *recBuilder {
|
||
|
b.changes = append(b.changes, change.Change{
|
||
|
CollectionID: cID,
|
||
|
ItemID: iID,
|
||
|
Store: false,
|
||
|
})
|
||
|
return b
|
||
|
}
|
||
|
|
||
|
func (b *recBuilder) Record() wal.Record {
|
||
|
buf := &bytes.Buffer{}
|
||
|
change.Write(b.changes, buf)
|
||
|
b.rec.DataSize = int64(buf.Len())
|
||
|
b.rec.Reader = buf
|
||
|
return b.rec
|
||
|
}
|