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/treechangeproto/treechange.go
2023-01-05 15:34:09 +03:00

51 lines
1.5 KiB
Go

package treechangeproto
func WrapHeadUpdate(update *TreeHeadUpdate, rootChange *RawTreeChangeWithId) *TreeSyncMessage {
return &TreeSyncMessage{
Content: &TreeSyncContentValue{
Value: &TreeSyncContentValue_HeadUpdate{HeadUpdate: update},
},
RootChange: rootChange,
}
}
func WrapFullRequest(request *TreeFullSyncRequest, rootChange *RawTreeChangeWithId) *TreeSyncMessage {
return &TreeSyncMessage{
Content: &TreeSyncContentValue{
Value: &TreeSyncContentValue_FullSyncRequest{FullSyncRequest: request},
},
RootChange: rootChange,
}
}
func WrapFullResponse(response *TreeFullSyncResponse, rootChange *RawTreeChangeWithId) *TreeSyncMessage {
return &TreeSyncMessage{
Content: &TreeSyncContentValue{
Value: &TreeSyncContentValue_FullSyncResponse{FullSyncResponse: response},
},
RootChange: rootChange,
}
}
func WrapError(err error, rootChange *RawTreeChangeWithId) *TreeSyncMessage {
return &TreeSyncMessage{
Content: &TreeSyncContentValue{
Value: &TreeSyncContentValue_ErrorResponse{ErrorResponse: &TreeErrorResponse{Error: err.Error()}},
},
RootChange: rootChange,
}
}
func GetHeads(msg *TreeSyncMessage) (heads []string) {
content := msg.GetContent()
switch {
case content.GetHeadUpdate() != nil:
return content.GetHeadUpdate().Heads
case content.GetFullSyncRequest() != nil:
return content.GetFullSyncRequest().Heads
case content.GetFullSyncResponse() != nil:
return content.GetFullSyncResponse().Heads
default:
return nil
}
}