From 164e9887b8a848821a015621975efc9e585eb311 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Thu, 1 Feb 2024 03:19:27 +0100 Subject: [PATCH] fix: serialize uuid as string when sending --- proto/user.proto | 2 +- src/cursor/controller.rs | 2 +- src/workspace.rs | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/proto/user.proto b/proto/user.proto index 2fa52ac..322a935 100644 --- a/proto/user.proto +++ b/proto/user.proto @@ -6,5 +6,5 @@ package user; // payload identifying user message UserIdentity { // user identifier - required bytes id = 1; //since uuid is 8 bytes we prefer to just send the raw bytes instead of string + required string id = 1; } diff --git a/src/cursor/controller.rs b/src/cursor/controller.rs index 2dd5cd2..af1f783 100644 --- a/src/cursor/controller.rs +++ b/src/cursor/controller.rs @@ -57,7 +57,7 @@ impl Controller for CursorController { std::mem::swap(&mut cursor.start, &mut cursor.end); } Ok(self.op.send(CursorEvent { - user: UserIdentity { id: self.user_id.as_bytes().to_vec() }, + user: UserIdentity { id: self.user_id.to_string() }, position: cursor, })?) } diff --git a/src/workspace.rs b/src/workspace.rs index 79da51c..1e00f5e 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -1,4 +1,4 @@ -use std::{collections::{BTreeMap, BTreeSet}, sync::Arc}; +use std::{collections::{BTreeMap, BTreeSet}, str::FromStr, sync::Arc}; use tokio::sync::mpsc; use uuid::Uuid; use crate::{ @@ -25,8 +25,7 @@ impl From for UserInfo { impl From for Uuid { fn from(uid: UserIdentity) -> Uuid { - let b: [u8; 16] = uid.id.try_into().expect("expected an uuid"); - Uuid::from_bytes(b) + Uuid::from_str(&uid.id).expect("expected an uuid") } } @@ -89,9 +88,9 @@ impl Workspace { /// [crate::api::Controller::recv] to exchange [crate::api::TextChange] pub async fn attach(&mut self, path: &str) -> crate::Result> { let mut worskspace_client = self.services.workspace.clone(); - self.token.send(worskspace_client.attach( - tonic::Request::new(AttachRequest { path: path.to_string() }) - ).await?.into_inner())?; + let mut request = tonic::Request::new(AttachRequest { path: path.to_string() }); + request.metadata_mut().insert("path", tonic::metadata::MetadataValue::try_from(path).expect("could not represent path as byte sequence")); + self.token.send(worskspace_client.attach(request).await?.into_inner())?; let (tx, rx) = mpsc::channel(10); let stream = self.services.buffer.clone()