fix: added proto docs, changed a little bit

This commit is contained in:
əlemi 2023-08-20 07:32:08 +02:00
parent 0b0c5c1904
commit 4764e47da5
3 changed files with 46 additions and 6 deletions

View file

@ -2,34 +2,59 @@ syntax = "proto3";
package codemp.buffer; package codemp.buffer;
// handle buffer changes, keep in sync users
service Buffer { service Buffer {
// attach to a buffer and receive operations
rpc Attach (BufferPayload) returns (stream RawOp); rpc Attach (BufferPayload) returns (stream RawOp);
// send an operation for a specific buffer
rpc Edit (OperationRequest) returns (BufferEditResponse); rpc Edit (OperationRequest) returns (BufferEditResponse);
// create a new buffer
rpc Create (BufferPayload) returns (BufferCreateResponse); rpc Create (BufferPayload) returns (BufferCreateResponse);
// get contents of buffer
rpc Sync (BufferPayload) returns (BufferResponse); rpc Sync (BufferPayload) returns (BufferResponse);
} }
// empty request
message BufferCreateResponse {} message BufferCreateResponse {}
// empty request
message BufferEditResponse {} message BufferEditResponse {}
// raw wire operation sequence event
message RawOp { message RawOp {
// operation seq serialized to json
string opseq = 1; string opseq = 1;
// user id that has executed the operation
string user = 2; string user = 2;
} }
// client buffer operation request
message OperationRequest { message OperationRequest {
// buffer path to operate onto
string path = 1; string path = 1;
// buffer hash of source state
string hash = 2; string hash = 2;
string opseq = 3;
string user = 4; // raw operation sequence
RawOp op = 3;
} }
// generic buffer operation request
message BufferPayload { message BufferPayload {
// buffer path to operate onto
string path = 1; string path = 1;
// user id that is requesting the operation
string user = 2; string user = 2;
// optional buffer full content for replacing
optional string content = 3; optional string content = 3;
} }
// response from server with buffer content
message BufferResponse { message BufferResponse {
string content = 2; // current buffer content
string content = 1;
} }

View file

@ -2,29 +2,43 @@ syntax = "proto3";
package codemp.cursor; package codemp.cursor;
// handle cursor events and broadcast to all users
service Cursor { service Cursor {
// send cursor movement to server
rpc Moved (CursorEvent) returns (MovedResponse); rpc Moved (CursorEvent) returns (MovedResponse);
// attach to a workspace and receive cursor events
rpc Listen (UserIdentity) returns (stream CursorEvent); rpc Listen (UserIdentity) returns (stream CursorEvent);
} }
// empty request
message MovedResponse {} message MovedResponse {}
// a tuple indicating row and column
message RowCol { message RowCol {
int32 row = 1; int32 row = 1;
int32 col = 2; int32 col = 2;
} }
// cursor position object
message CursorPosition { message CursorPosition {
// path of current buffer this cursor is into
string buffer = 1; string buffer = 1;
// cursor start position
RowCol start = 2; RowCol start = 2;
// cursor end position
RowCol end = 3; RowCol end = 3;
} }
// cursor event, with user id and cursor position
message CursorEvent { message CursorEvent {
// user moving the cursor
string user = 1; string user = 1;
// new cursor position
CursorPosition position = 2; CursorPosition position = 2;
} }
// payload identifying user for cursor attaching
message UserIdentity { message UserIdentity {
// user identifier
string id = 1; string id = 1;
} }

View file

@ -114,9 +114,10 @@ async fn send_opseq(tx: &mut BufferClient<Channel>, uid: String, path: String, o
} }
}; };
let req = OperationRequest { let req = OperationRequest {
hash: "".into(), path, hash: "".into(),
user: uid, op: Some(RawOp {
opseq, path, opseq, user: uid,
}),
}; };
match tx.edit(req).await { match tx.edit(req).await {
Ok(_) => true, Ok(_) => true,