codemp-proto/src/lib.rs

116 lines
2.4 KiB
Rust
Raw Normal View History

//! # CodeMP Protocol - cooperative development
//! `codemp-proto` is the gRPC protocol specification powering [`codemp`](https://codemp.dev).
//!
//! This is built on top of [tonic] and provides both clientside and serverside service
//! implementations.
/// common types across services
#[allow(non_snake_case)]
2024-03-09 19:27:29 +01:00
pub mod common {
tonic::include_proto!("common");
2024-03-09 19:27:29 +01:00
impl From<uuid::Uuid> for Identity {
fn from(id: uuid::Uuid) -> Self {
2024-08-21 20:16:14 +02:00
let (hi, lo) = id.as_u64_pair();
Identity { hi, lo }
}
}
impl From<&uuid::Uuid> for Identity {
fn from(id: &uuid::Uuid) -> Self {
2024-08-21 20:16:14 +02:00
let (hi, lo) = id.as_u64_pair();
Identity { hi, lo }
}
}
impl From<Identity> for uuid::Uuid {
fn from(value: Identity) -> Self {
2024-08-21 20:16:14 +02:00
uuid::Uuid::from_u64_pair(value.hi, value.lo)
}
}
impl From<&Identity> for uuid::Uuid {
fn from(value: &Identity) -> Self {
2024-08-21 20:16:14 +02:00
uuid::Uuid::from_u64_pair(value.hi, value.lo)
}
}
impl Identity {
pub fn uuid(&self) -> uuid::Uuid {
uuid::Uuid::from(self)
}
}
2024-03-09 19:27:29 +01:00
}
/// filetree related types
2024-03-09 19:27:29 +01:00
pub mod files {
tonic::include_proto!("files");
2024-03-09 19:27:29 +01:00
impl From<String> for BufferNode {
fn from(value: String) -> Self {
BufferNode { path: value }
}
2024-03-09 19:27:29 +01:00
}
2024-03-09 19:27:29 +01:00
impl From<&str> for BufferNode {
fn from(value: &str) -> Self {
BufferNode {
path: value.to_string(),
}
}
2024-03-09 19:27:29 +01:00
}
2024-03-09 19:27:29 +01:00
impl From<BufferNode> for String {
fn from(value: BufferNode) -> Self {
value.path
}
}
2024-03-09 19:27:29 +01:00
}
/// buffer synchronisation protocol types and procedures
2024-03-09 19:27:29 +01:00
pub mod buffer {
tonic::include_proto!("buffer");
}
/// cursor position protocol types and procedures
2024-03-09 19:27:29 +01:00
pub mod cursor {
tonic::include_proto!("cursor");
impl From<RowCol> for (i32, i32) {
fn from(pos: RowCol) -> (i32, i32) {
(pos.row, pos.col)
}
}
impl From<(i32, i32)> for RowCol {
fn from((row, col): (i32, i32)) -> Self {
RowCol { row, col }
}
}
impl PartialOrd for RowCol {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
match self.row.partial_cmp(&other.row) {
Some(core::cmp::Ordering::Equal) => {}
ord => return ord,
}
self.col.partial_cmp(&other.col)
}
}
2024-03-09 19:27:29 +01:00
}
/// workspace state protocol types and procedures
2024-03-09 19:27:29 +01:00
pub mod workspace {
tonic::include_proto!("workspace");
}
/// session management protocol types and procedures
pub mod session {
tonic::include_proto!("session");
}
/// authentication and authorization protocol types and procedures
2024-03-09 19:27:29 +01:00
pub mod auth {
tonic::include_proto!("auth");
2024-03-09 19:07:23 +01:00
}