Documentation ¶
Overview ¶
Package packs implements PushPullPack which is used to sync the document between the client and the server.
Index ¶
- Variables
- func BuildDocumentForServerSeq(ctx context.Context, be *backend.Backend, docInfo *database.DocInfo, ...) (*document.InternalDocument, error)
- func FindChanges(ctx context.Context, be *backend.Backend, docInfo *database.DocInfo, ...) ([]*change.Change, error)
- func PushPullKey(projectID types.ID, docKey key.Key) sync.Key
- func SnapshotKey(projectID types.ID, docKey key.Key) sync.Key
- type PushPullOptions
- type ServerPack
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidServerSeq is returned when the given server seq greater than // the initial server seq. ErrInvalidServerSeq = errors.New("invalid server seq") )
Functions ¶
func BuildDocumentForServerSeq ¶
func BuildDocumentForServerSeq( ctx context.Context, be *backend.Backend, docInfo *database.DocInfo, serverSeq int64, ) (*document.InternalDocument, error)
BuildDocumentForServerSeq returns a new document for the given serverSeq.
func FindChanges ¶ added in v0.2.11
func FindChanges( ctx context.Context, be *backend.Backend, docInfo *database.DocInfo, from int64, to int64, ) ([]*change.Change, error)
FindChanges fetches changes of the given document.
func PushPullKey ¶
PushPullKey creates a new sync.Key of PushPull for the given document.
Types ¶
type PushPullOptions ¶ added in v0.4.24
type PushPullOptions struct { // Mode represents the sync mode. Mode types.SyncMode // Status represents the status of the document to be updated. Status document.StatusType }
PushPullOptions represents the options for PushPull.
type ServerPack ¶
type ServerPack struct { // DocumentKey is key of the document. DocumentKey key.Key // Checkpoint is used to determine the client received changes. Checkpoint change.Checkpoint // ChangeInfos represents a unit of modification in the document. ChangeInfos []*database.ChangeInfo // Snapshot is a byte array that encode the document. Snapshot []byte // MinSyncedTicket is the minimum logical time taken by clients who attach the document. // It used to collect garbage on the replica on the client. MinSyncedTicket *time.Ticket // IsRemoved is a flag that indicates whether the document is removed. IsRemoved bool }
ServerPack is similar to change.Pack, but has ChangeInfos instead of Changes to reduce type conversion in Server.
func NewServerPack ¶
func NewServerPack( key key.Key, cp change.Checkpoint, changeInfos []*database.ChangeInfo, snapshot []byte, ) *ServerPack
NewServerPack creates a new instance of ServerPack.
func PushPull ¶
func PushPull( ctx context.Context, be *backend.Backend, project *types.Project, clientInfo *database.ClientInfo, docInfo *database.DocInfo, reqPack *change.Pack, opts PushPullOptions, ) (*ServerPack, error)
PushPull stores the given changes and returns accumulated changes of the given document.
CAUTION(hackerwins, krapie): docInfo's state is constantly mutating as they are constantly used as parameters in subsequent subroutines.
func (*ServerPack) ApplyDocInfo ¶ added in v0.3.3
func (p *ServerPack) ApplyDocInfo(info *database.DocInfo)
ApplyDocInfo applies the given DocInfo to the ServerPack.
func (*ServerPack) ChangesLen ¶
func (p *ServerPack) ChangesLen() int
ChangesLen returns the size of the changes.
func (*ServerPack) OperationsLen ¶
func (p *ServerPack) OperationsLen() int
OperationsLen returns the size of the operations.
func (*ServerPack) SnapshotLen ¶
func (p *ServerPack) SnapshotLen() int
SnapshotLen returns the size of the snapshot.
func (*ServerPack) ToPBChangePack ¶
func (p *ServerPack) ToPBChangePack() (*api.ChangePack, error)
ToPBChangePack converts the given model format to Protobuf format.