1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00
any-sync/commonspace/object/tree/synctree/request.go
2024-07-31 22:58:49 +02:00

39 lines
1.1 KiB
Go

package synctree
import (
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
"github.com/anyproto/any-sync/commonspace/sync/objectsync/objectmessages"
)
type InnerRequest struct {
heads []string
snapshotPath []string
root *treechangeproto.RawTreeChangeWithId
}
func (r *InnerRequest) MsgSize() uint64 {
size := uint64(len(r.heads)+len(r.snapshotPath)) * 59
if r.root != nil {
size += uint64(len(r.root.Id) + len(r.root.RawChange))
}
return size
}
func NewRequest(peerId, spaceId, objectId string, heads []string, snapshotPath []string, root *treechangeproto.RawTreeChangeWithId) *objectmessages.Request {
copyHeads := make([]string, len(heads))
copy(copyHeads, heads)
return objectmessages.NewRequest(peerId, spaceId, objectId, &InnerRequest{
heads: copyHeads,
snapshotPath: snapshotPath,
root: root,
})
}
func (r *InnerRequest) Marshall() ([]byte, error) {
msg := &treechangeproto.TreeFullSyncRequest{
Heads: r.heads,
SnapshotPath: r.snapshotPath,
}
req := treechangeproto.WrapFullRequest(msg, r.root)
return req.Marshal()
}