From 4764e47da5654996d2565980a33130a7b6fd7fa5 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 20 Aug 2023 07:32:08 +0200 Subject: [PATCH] fix: added proto docs, changed a little bit --- proto/buffer.proto | 31 ++++++++++++++++++++++++++++--- proto/cursor.proto | 14 ++++++++++++++ src/buffer/worker.rs | 7 ++++--- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/proto/buffer.proto b/proto/buffer.proto index b668a44..23f919f 100644 --- a/proto/buffer.proto +++ b/proto/buffer.proto @@ -2,34 +2,59 @@ syntax = "proto3"; package codemp.buffer; +// handle buffer changes, keep in sync users service Buffer { + // attach to a buffer and receive operations rpc Attach (BufferPayload) returns (stream RawOp); + // send an operation for a specific buffer rpc Edit (OperationRequest) returns (BufferEditResponse); + // create a new buffer rpc Create (BufferPayload) returns (BufferCreateResponse); + // get contents of buffer rpc Sync (BufferPayload) returns (BufferResponse); } +// empty request message BufferCreateResponse {} + +// empty request message BufferEditResponse {} +// raw wire operation sequence event message RawOp { + // operation seq serialized to json string opseq = 1; + + // user id that has executed the operation string user = 2; } +// client buffer operation request message OperationRequest { + // buffer path to operate onto string path = 1; + + // buffer hash of source state string hash = 2; - string opseq = 3; - string user = 4; + + // raw operation sequence + RawOp op = 3; } +// generic buffer operation request message BufferPayload { + // buffer path to operate onto string path = 1; + + // user id that is requesting the operation string user = 2; + + // optional buffer full content for replacing optional string content = 3; } +// response from server with buffer content message BufferResponse { - string content = 2; + // current buffer content + string content = 1; } diff --git a/proto/cursor.proto b/proto/cursor.proto index 5af4fa2..d48d7c5 100644 --- a/proto/cursor.proto +++ b/proto/cursor.proto @@ -2,29 +2,43 @@ syntax = "proto3"; package codemp.cursor; +// handle cursor events and broadcast to all users service Cursor { + // send cursor movement to server rpc Moved (CursorEvent) returns (MovedResponse); + // attach to a workspace and receive cursor events rpc Listen (UserIdentity) returns (stream CursorEvent); } +// empty request message MovedResponse {} +// a tuple indicating row and column message RowCol { int32 row = 1; int32 col = 2; } +// cursor position object message CursorPosition { + // path of current buffer this cursor is into string buffer = 1; + // cursor start position RowCol start = 2; + // cursor end position RowCol end = 3; } +// cursor event, with user id and cursor position message CursorEvent { + // user moving the cursor string user = 1; + // new cursor position CursorPosition position = 2; } +// payload identifying user for cursor attaching message UserIdentity { + // user identifier string id = 1; } diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index c4336a0..509b364 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -114,9 +114,10 @@ async fn send_opseq(tx: &mut BufferClient, uid: String, path: String, o } }; let req = OperationRequest { - hash: "".into(), - user: uid, - opseq, path, + path, hash: "".into(), + op: Some(RawOp { + opseq, user: uid, + }), }; match tx.edit(req).await { Ok(_) => true,