mirror of
https://github.com/talent-plan/tinykv.git
synced 2024-12-27 13:20:24 +08:00
46 lines
654 B
Go
46 lines
654 B
Go
package storage
|
|
|
|
// Modify is a single modification to TinyKV's underlying storage.
|
|
type Modify struct {
|
|
Data interface{}
|
|
}
|
|
|
|
type Put struct {
|
|
Key []byte
|
|
Value []byte
|
|
Cf string
|
|
}
|
|
|
|
type Delete struct {
|
|
Key []byte
|
|
Cf string
|
|
}
|
|
|
|
func (m *Modify) Key() []byte {
|
|
switch m.Data.(type) {
|
|
case Put:
|
|
return m.Data.(Put).Key
|
|
case Delete:
|
|
return m.Data.(Delete).Key
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *Modify) Value() []byte {
|
|
if putData, ok := m.Data.(Put); ok {
|
|
return putData.Value
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Modify) Cf() string {
|
|
switch m.Data.(type) {
|
|
case Put:
|
|
return m.Data.(Put).Cf
|
|
case Delete:
|
|
return m.Data.(Delete).Cf
|
|
}
|
|
return ""
|
|
}
|