1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/commonspace/object/tree/objecttree/derivedtree.go
2024-12-16 15:37:17 +01:00

24 lines
597 B
Go

package objecttree
import (
"github.com/anyproto/protobuf/proto"
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
)
func IsEmptyDerivedTree(tree ObjectTree) bool {
return tree.IsDerived() && IsEmptyTree(tree)
}
func IsEmptyTree(tree ObjectTree) bool {
return tree.Len() == 1 && tree.Root().Id == tree.Id()
}
func IsDerivedRoot(root *treechangeproto.RawTreeChangeWithId) (derived bool, err error) {
rawChange := &treechangeproto.RawTreeChange{}
err = proto.Unmarshal(root.RawChange, rawChange)
if err != nil {
return
}
return rawChange.Signature == nil, err
}