Commit 9f8c776e authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/btree: Draft support for Length

BTrees.Length.Length is used in many places in ERP5. At least we should
be able to load and save it now.
parent 25e04547
......@@ -38,3 +38,48 @@ package btree
//go:generate ./gen-btree IO int32 ziobtree.go
//go:generate ./gen-btree LO int64 zlobtree.go
import (
"fmt"
"reflect"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
)
// Length is equivalent of BTrees.Length.Length in BTree/py.
type Length struct {
zodb.Persistent
value int
}
type lengthState Length // hide state methods from public API
// DropState implements zodb.Stateful.
func (l *lengthState) DropState() {
l.value = 0
}
// PyGetState implements zodb.PyStateful.
func (l *lengthState) PyGetState() interface{} {
return l.value
}
// PySetState implements zodb.PyStateful.
func (l *lengthState) PySetState(pystate interface{}) (err error) {
v, ok := pickletools.Xint64(pystate)
if !ok {
return fmt.Errorf("state must be int; got %T", pystate)
}
l.value = int(v)
return nil
}
// ---- register classes to ZODB ----
func init() {
t := reflect.TypeOf
zodb.RegisterClass("BTrees.Length.Length", t(Length{}), t(lengthState{}))
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment