codemp_proto/
lib.rs

1//! # CodeMP Protocol - cooperative development
2//! `codemp-proto` is the gRPC protocol specification powering [`codemp`](https://code.mp).
3//!
4//! This is built on top of [tonic] and provides both clientside and serverside service
5//! implementations.
6#![doc(html_logo_url = "https://code.mp/logo-round.png")]
7
8/// common types across services
9#[allow(non_snake_case)]
10pub mod common {
11	tonic::include_proto!("common");
12
13	impl From<uuid::Uuid> for Identifier {
14		fn from(id: uuid::Uuid) -> Self {
15			let (hi, lo) = id.as_u64_pair();
16			Identifier { hi, lo }
17		}
18	}
19
20	impl From<&uuid::Uuid> for Identifier {
21		fn from(id: &uuid::Uuid) -> Self {
22			let (hi, lo) = id.as_u64_pair();
23			Identifier { hi, lo }
24		}
25	}
26
27	impl From<Identifier> for uuid::Uuid {
28		fn from(value: Identifier) -> Self {
29			uuid::Uuid::from_u64_pair(value.hi, value.lo)
30		}
31	}
32
33	impl From<&Identifier> for uuid::Uuid {
34		fn from(value: &Identifier) -> Self {
35			uuid::Uuid::from_u64_pair(value.hi, value.lo)
36		}
37	}
38
39	impl Identifier {
40		pub fn uuid(&self) -> uuid::Uuid {
41			uuid::Uuid::from(self)
42		}
43	}
44}
45
46/// filetree related types
47pub mod files {
48	tonic::include_proto!("files");
49}
50
51/// buffer synchronisation protocol types and procedures
52pub mod buffer {
53	tonic::include_proto!("buffer");
54}
55
56/// cursor position protocol types and procedures
57pub mod cursor {
58	tonic::include_proto!("cursor");
59
60	impl From<RowCol> for (i32, i32) {
61		fn from(pos: RowCol) -> (i32, i32) {
62			(pos.row, pos.col)
63		}
64	}
65
66	impl From<(i32, i32)> for RowCol {
67		fn from((row, col): (i32, i32)) -> Self {
68			RowCol { row, col }
69		}
70	}
71
72	impl PartialOrd for RowCol {
73		fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
74			match self.row.partial_cmp(&other.row) {
75				Some(core::cmp::Ordering::Equal) => {}
76				ord => return ord,
77			}
78			self.col.partial_cmp(&other.col)
79		}
80	}
81}
82
83/// workspace state protocol types and procedures
84pub mod workspace {
85	tonic::include_proto!("workspace");
86}
87
88/// session management protocol types and procedures
89pub mod session {
90	tonic::include_proto!("session");
91}
92
93/// authentication and authorization protocol types and procedures
94pub mod auth {
95	tonic::include_proto!("auth");
96}